margot.data.features.finance

class margot.data.features.finance.SimpleReturns(column: str, *args, **kwargs)

Simple returns are the percent change from yesterdays close to today’s close.

Internal implementation:

return series.pct_change().fillna(0)
Parameters

column (str) – The name of a price time series.

class margot.data.features.finance.LogReturns(column: str, *args, **kwargs)

Log returns can be summed over time.

Internal implementation:

return np.log(1 + series.pct_change().fillna(0))
Parameters

column (str) – The name of the price time series.

class margot.data.features.finance.RealisedVolatility(column: str, *args, **kwargs)

Realised volatility measures the variability of returns over a lookback window.

Internal implementation:

return series.rolling(window).std() * np.sqrt(252)
Parameters
  • column (str) – The name of a returns time series.

  • window (int) – Lookback window in trading days.

Raises

AttributeError – A lookback window is required.

class margot.data.features.finance.SimpleMovingAverage(column: str, *args, **kwargs)

Simple moving average of lookback window.

Internal implementation:

return series.rolling(window).mean()
Parameters
  • column (str) – The name of a returns time series.

  • window (int) – Lookback window in trading days.

get_label()

Return the label for this feature.

Override this to customise.

Returns

the label to be used in the pandas column.

Return type

str

class margot.data.features.finance.UpperBollingerBand(column: str, *args, **kwargs)

Upper bollinger band with window and standard deviation.

Internal implementation:

return series.rolling(window).mean() +
        series.rolling(self.window).mean().std() *
            self.width
Parameters
  • column (str) – The name of a returns time series.

  • window (int) – lookback in trading days. Defaults to 20

  • width (float) – width in standard deviations. Defaults to 2.0

class margot.data.features.finance.LowerBollingerBand(column: str, *args, **kwargs)

Lower bollinger band of window and standard deviation.

Internal implementation:

return series.rolling(window).mean() -
        series.rolling(self.window).mean().std() *
            self.width
Parameters
  • column (str) – The name of a returns time series.

  • window (int) – lookback in trading days. Defaults to 20

  • width (float) – width in standard deviations. Defaults to 2.0