mlfinlab.multi_product.etf_trick
This module contains a class for ETF trick generation and futures roll function, described in Marcos Lopez de Prado’s book ‘Advances in Financial Machine Learning’ ETF trick class can generate ETF trick series either from .csv files or from in-memory pandas DataFrames.
Module Contents
Classes
Contains logic of vectorised ETF trick implementation. |
Functions
|
Function for generating rolling futures series from data frame of multiple futures. |
- class ETFTrick
-
Contains logic of vectorised ETF trick implementation.
- get_etf_series(open_df: pandas.DataFrame, close_df: pandas.DataFrame, alloc_df: pandas.DataFrame, costs_df: pandas.DataFrame = None, rates_df: pandas.DataFrame = None) pandas.Series
-
Get ETF trick series.
- Parameters:
-
-
open_df – (pd.DataFrame) Open prices data frame corresponds to o(t) from the book.
-
close_df – (pd.DataFrame) Close prices data frame or path to csv file, corresponds to p(t).
-
alloc_df – (pd.DataFrame) Asset allocations data frame or path to csv file (in # of contracts), corresponds to w(t).
-
costs_df – (pd.DataFrame) Rebalance, carry and dividend costs of holding/rebalancing the position, corresponds to d(t).
-
rates_df – (pd.DataFrame) Dollar value of one point move of contract includes exchange rate, futures contracts multiplies). Corresponds to phi(t). For example, 1$ in VIX index, equals 1000$ in VIX futures contract value. If None then trivial (all values equal 1.0) is generated.
-
- Returns:
-
(pd.Series) Pandas Series with ETF trick values starting from 1.0.
- get_futures_roll_series(data_df: pandas.DataFrame, open_col: str, close_col: str, sec_col: str, current_sec_col: str, roll_backward: bool = False, method: str = 'absolute') pandas.Series
-
Function for generating rolling futures series from data frame of multiple futures.
- Parameters:
-
-
data_df – (pd.DataFrame) Pandas DataFrame containing price info, security name and current active futures column.
-
open_col – (str) Open prices column name.
-
close_col – (str) Close prices column name.
-
sec_col – (str) Security name column name.
-
current_sec_col – (str) Current active security column name. When value in this column changes it means rolling.
-
roll_backward – (bool) True for subtracting final gap value from all values.
-
method – (str) What returns user wants to preserve, ‘absolute’ or ‘relative’.
-
- Returns:
-
(pd.Series) Futures roll adjustment factor series.