Module serve
Classes
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
class StatCalculator (state: StateSignals)-
Class analog to the BacktestResults class. However, this class is used to calculate the stats in real time. It calculates the statistics based on a one-year moving window when possible. For some indicators, it is not possible because it would cause a difference in calculation of that metric between the inference and the backtest. Those metrics are marked as All-time in the comments.
Static methods
def prepare_data(state: StateSignals) ‑> (typing.List[str],) -
Extracts the relevent up-to-date data from the state object and returns it as an array.
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