Data transforms, features, and targets

Machine Learning for Finance in Python

Nathan George

Data Science Professor

Making features and targets

features = amd_df[['10d_close_pct', 'Adj_Volume']]

targets = amd_df['10d_future_close_pct']
print(type(features))
pandas.core.series.DataFrame
print(type(targets))
pandas.core.series.Series
Machine Learning for Finance in Python

price and moving average

Machine Learning for Finance in Python

Moving averages

Moving averages:

  • use n past days to get average
  • common values for n: 14, 50, 200
Machine Learning for Finance in Python

price and sma

Machine Learning for Finance in Python

RSI and price plot

Machine Learning for Finance in Python

RSI equation

RS equation

Machine Learning for Finance in Python

Calculating SMA and RSI

import talib

amd_df['ma200'] = talib.SMA(amd_df['Adj_Close'].values, timeperiod=200)
amd_df['rsi200'] = talib.RSI(amd_df['Adj_Close'].values, timeperiod=200)
Machine Learning for Finance in Python

Finally, our features

feature_names = ['10d_close_pct', 'ma200', 'rsi200']
features = amd_df[feature_names]
targets = amd_df['10d_future_close_pct']

feature_target_df = amd_df[feature_names + '10d_future_close_pct']
Machine Learning for Finance in Python

Check correlations

import seaborn as sns

corr = feature_target_df.corr()
sns.heatmap(corr, annot=True)
Machine Learning for Finance in Python

feature and target correlation plot

Machine Learning for Finance in Python

Let's create features and targets!

Machine Learning for Finance in Python

Preparing Video For Download...