Module engine
Classes
class BackTestResult (strategy_name: str, metadata: Metadata, start: datetime.datetime, end: datetime.datetime, intial_cash: float, added_cash: float, market_index: Optional[numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]], broker: Broker, account: Account, risk_free_rate: float = 1.5)-
This class is used to store the result of a backtest. It contains all the information about the backtest
Args:
strategy_name: The name of the strategy
metadata: The metadata object
start: Start date of the backtest data
end: End date of the backtest data
intial_cash: The initial cash of the account
added_cash: The cash added to the account (or removed) with the CashController
market_index: The market index time series (Price/score evolution across time)
broker: The broker object used to backtest the strategy
account: The account object used to backtest the strategy
risk_free_rate: The risk free rate used to compute the ratios [%]. (Usually the estimated policy rate)Static methods
def load(path: str)-
Load a backtest result from a JSON file
Args:
path: The path to the backtest result fileReturns:
- The backtest result
def load_state(data: dict)-
Load a backtest result from a state dictionary
Args:
data: The state dictionaryReturns:
- The backtest result
def strided_arr(a: numpy.ndarray, window: int)-
Create a strided array to compute the rolling window of an array
Args:
a: The array
window: The window sizeReturns:
- The strided array. Shape(len(a) - window + 1, window)
Methods
def compute_calmar_ratio(self, yearly_max_drawdown: pandas.core.series.Series) ‑> Optional[float]-
Compute the calmar ratio of the strategy
Args:
yearly_max_drawdown: The yearly maximum drawdown of the strategyReturns:
- The calmar ratio of the strategy
def compute_sharp_ratio(self, risk_free_rate) ‑> float-
Compute the sharp ratio of the strategy on a weekly basis
Args:
risk_free_rate: The risk free rate or MAR (Minimum acceptable return)Returns:
- The sharp ratio of the strategy
def compute_sortino_ratio(self, risk_free_rate) ‑> float-
Compute the sortino ratio of the strategy on a weekly basis
Args:
risk_free_rate: The risk free rate or MAR (Minimum acceptable return)Returns:
- The sortino ratio of the strategy
def get_drawdown(self, equity_history: numpy.ndarray, equity_timestamps: numpy.ndarray, window: Union[datetime.timedelta, int] = datetime.timedelta(days=365)) ‑> numpy.ndarray[typing.Any, numpy.dtype[numpy.float32]]-
Get the maximum drawdown of the strategy for each timestep (Causally - so looking back in time)
Args:
equity_history: The equity history of the strategy (Worth of the portoflio evolution over time)
equity_timestamps: The timestamps of the equity history
window: The lookback window to use to compute the drawdownReturns:
- A time series of the maximum drawdown of the strategy for each time steps
def get_ohlc(self, period: Period)-
Return a OHLC dataframe of the equity history corresponding to the period.
Args:
period: The period to use to make the OHLC dataframeReturns:
- The OHLC dataframe
def save(self, path: str)-
Save the backtest result to a JSON file with the .bktst extension if none is provided. About the .bktst extension: This is the fileformat for a backtest result. It is a JSON file that contains all the information about the backtest. It is a human readable file that can be used to share backtest results with other people. Also, it can be loaded by this module so that the backtest result can be analyzed later.
Args:
path: The path to save the backtest result. If no extension is provided, the .bktst extension will be added.Returns:
- None
def toAnalyser(self, data: List[Dict[str, TSData]])-
Convert the backtest result to an analyser object to visualize the backtest results
Returns:
- The analyser object
class Period (*args, **kwds)-
Create a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3Access them by:
- attribute access:
Color.RED
- value lookup:
Color(1)
- name lookup:
Color['RED']
Enumerations can be iterated over, and know how many members they have:
>>> len(Color) 3>>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.
Parent
- enum.Enum
Class variables
var DAILYvar HOURLYvar MONTHLYvar QUARTERLYvar WEEKLYvar YEARLY