Stat
- class Stat(hbt, utc=True, unit='us', allocated=100000)[source]
Calculates performance statistics and generates a summary of performance metrics.
- Parameters:
- annualised_return(denom=None, include_fee=True, trading_days=365)[source]
Calculates annualised return.
- Parameters:
denom (float | None) – If provided, annualised return will be calculated in percentage terms by dividing by the specified denominator.
include_fee (bool) – If set to
True
, fees will be included in the calculation; otherwise, fees will be excluded.trading_days (int) – The number of trading days per year used for annualisation.
- Returns:
Annaulised return.
- daily_trade_amount()[source]
Retrieves the average value of daily trades.
- Returns:
Average value of daily trades.
- daily_trade_num()[source]
Retrieves the average number of daily trades.
- Returns:
Average number of daily trades.
- daily_trade_volume()[source]
Retrieves the average quantity of daily trades.
- Returns:
Average quantity of daily trades.
- datetime()[source]
Converts and returns a DateTime series from the timestamp.
- Returns:
DateTime series by converting from the timestamp.
- equity(resample=None, include_fee=True, datetime=True)[source]
Calculates equity values.
- Parameters:
resample (str | None) – If provided, equity values will be resampled based on the specified period.
include_fee (bool) – If set to
True
, fees will be included in the calculation; otherwise, fees will be excluded.datetime (bool) – If set to
True
, the timestamp is converted to a DateTime, which takes a long time. If you want fast computation, set it toFalse
.
- Returns:
the calculated equity values.
- property recorder
Returns a
Recorder
instance to record performance statistics.
- riskreturnratio(include_fee=True)[source]
Calculates Risk-Return Ratio, which is Annualized Return / Maximum Draw Down over the entire period.
- Parameters:
include_fee (bool) – If set to
True
, fees will be included in the calculation; otherwise, fees will be excluded.- Returns:
Risk-Return Ratio
- sharpe(resample, include_fee=True, trading_days=365)[source]
Calculates the Sharpe Ratio without considering benchmark rates.
- Parameters:
- Returns:
The calculated Sharpe Ratio.
- summary(capital=None, resample='5min', trading_days=365)[source]
Generates a summary of performance metrics.
- Parameters:
capital (float | None) – The initial capital investment for the strategy. If provided, it is used as the denominator to calculate annualized return and MDD in percentage terms. Otherwise, absolute values are displayed.
resample (str) – The resampling period, such as ‘1s’, ‘5min’.
trading_days (int) – The number of trading days per year used for annualisation.
- class Recorder(timestamp, mid, balance, position, fee, trade_num, trade_qty, trade_amount)[source]
- Parameters:
timestamp (ListType(int64)) –
mid (ListType(float64)) –
balance (ListType(float64)) –
position (ListType(float64)) –
fee (ListType(float64)) –
trade_num (ListType(int64)) –
trade_qty (ListType(float64)) –
trade_amount (ListType(float64)) –