kats.models.nowcasting.feature_extraction moduleΒΆ

This is a file with functions which turn time series into ML features.

Typical use case is to create various features for the nowcasting model. The features are rolling, i.e. they are the times series as well.

Typical usage example:

>>> df = ROC(df, 5)
kats.models.nowcasting.feature_extraction.BBANDS(df, n: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds two Bolllinger Band columns

A Bollinger Band is a technical analysis tool defined by a set of trendlines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of a security’s price, but which can be adjusted to user preferences.

Parameters
  • df – a pandas dataframe

  • n – an integer on how many steps looking back.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added 2 BollingerBand columns.

kats.models.nowcasting.feature_extraction.EMA(df, n: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds the Exponetial Moving Average column

The exponential moving average (EMA) is a technical chart indicator that tracks the price of an investment (like a stock or commodity) over time. The EMA is a type of weighted moving average (WMA) that gives more

weighting or importance to recent price data

Parameters
  • df – a pandas dataframe

  • n – an integer on how many steps looking back.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added EMA column.

kats.models.nowcasting.feature_extraction.LAG(df: pandas.core.frame.DataFrame, n: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds another column indicating lagged value at the past n steps.

Parameters
  • df – a pandas dataframe.

  • n – an integer on how many steps looking back.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added column.

kats.models.nowcasting.feature_extraction.MA(df: pandas.core.frame.DataFrame, n: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds another column indicating moving average in the past n steps.

Parameters
  • df – a pandas dataframe.

  • n – an integer on how many steps looking back.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added column.

kats.models.nowcasting.feature_extraction.MACD(df: pandas.core.frame.DataFrame, n_fast: int = 12, n_slow: int = 21, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds three columns indicating MACD: https://www.investopedia.com/terms/m/macd.asp.

Parameters
  • df – a pandas dataframe

  • n_fast – an integer on how many steps looking back fast.

  • n_slow – an integer on how many steps looking back slow.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added 3 columns.

kats.models.nowcasting.feature_extraction.MOM(df: pandas.core.frame.DataFrame, n: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds another column indicating momentum: difference of current value and n steps back.

Parameters
  • df – a pandas dataframe.

  • n – an integer on how many steps looking back.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added column.

kats.models.nowcasting.feature_extraction.ROC(df: pandas.core.frame.DataFrame, n: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds another column indicating return comparing to step n back.

Parameters
  • df – a pandas dataframe.

  • n – an integer on how many steps looking back.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added column.

kats.models.nowcasting.feature_extraction.RSI(df, n: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Relative Strength Index (RSI) Compares the magnitude of recent gains and losses over a specified time period to measure speed and change of price movements of a security. It is primarily used to attempt to identify overbought or oversold conditions in the trading of an asset.

Parameters
  • df – a pandas dataframe

  • n – an integer on how many steps looking back.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added RSI column.

kats.models.nowcasting.feature_extraction.TRIX(df, n: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds the TRIX indicator column

The triple exponential average (TRIX) indicator is an oscillator used to identify oversold and overbought markets, and it can also be used as a momentum indicator.

Parameters
  • df – a pandas dataframe

  • n – an integer on how many steps looking back.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added TRIX column.

kats.models.nowcasting.feature_extraction.TSI(df, r: int, s: int, column: str = 'y')pandas.core.frame.DataFrame[source]ΒΆ

Adds the TSI column

The true strength index (TSI) is a technical momentum oscillator used to identify trends and reversals

Parameters
  • df – a pandas dataframe

  • r – an integer on how many steps looking back, for window 1.

  • s – an integer on how many steps looking back, for window 2.

  • column – Optional. If column is provided, will calculate based on provided column otherwise the column named y will be the target.

Returns

A dataframe with all the columns from input df, and the added TSI column.