Machine Learning for Finance in Python
Nathan George
Data Science Professor
# add non-linear interaction term for a linear model
SMAxRSI = amd_df['14-day SMA'] * amd_df['14-day RSI']
Some models that don't require manually creating interaction features:
Decision-tree-based models
Others
amd_df['Adj_Volume_1d_change'] = amd_df['Adj_Volume'].pct_change()
one_day_change = amd_df['Adj_Volume_1d_change'].values amd_df['Adj_Volume_1d_change_SMA'] = talib.SMA(one_day_change, timeperiod=10)
print(amd_df.index.dayofweek)
Int64Index([2, 3, 4, 0, 1, 2, 3, 4, 0, 1,
...
1, 2, 3, 4, 0, 1, 2, 3, 4, 0],
dtype='int64', name='Date', length=4807)
days_of_week = pd.get_dummies(amd_df.index.dayofweek, prefix='weekday', drop_first=True)
print(days_of_week.head())
weekday_1 weekday_2 weekday_3 weekday_4
Date
2018-04-10 1 0 0 0
2018-04-11 0 1 0 0
2018-04-12 0 0 1 0
2018-04-13 0 0 0 1
2018-04-16 0 0 0 0
Machine Learning for Finance in Python