(Stock(past x days) - Stock(current)) / Stock(current)
Date
2011-01-03 0.004695
2011-01-04 -0.002670
2011-01-05 0.006426
2011-01-06 0.005454
2011-01-07 -0.006085
...
2019-10-28 -0.002914
2019-10-29 -0.010520
2019-10-30 -0.002215
2019-10-31 0.030043
2019-11-01 NaN
Name: XOM_1d, Length: 2224, dtype: float64
Date
2011-01-03 0.002012
2011-01-04 0.003738
2011-01-05 0.011914
2011-01-06 -0.000665
2011-01-07 0.001323
...
2019-10-28 -0.013403
2019-10-29 -0.012712
2019-10-30 0.027761
2019-10-31 NaN
2019-11-01 NaN
Name: XOM_2d, Length: 2224, dtype: float64
Date
2011-01-03 0.008451
2011-01-04 0.009212
2011-01-05 0.005757
2011-01-06 0.006784
2011-01-07 0.013097
...
2019-10-28 -0.015589
2019-10-29 0.016949
2019-10-30 NaN
2019-10-31 NaN
2019-11-01 NaN
Name: XOM_3d, Length: 2224, dtype: float64
Date
2011-01-03 0.013950
2011-01-04 0.003071
2011-01-05 0.013253
2011-01-06 0.018622
2011-01-07 0.014817
...
2019-10-28 0.013986
2019-10-29 NaN
2019-10-30 NaN
2019-10-31 NaN
2019-11-01 NaN
Name: XOM_4d, Length: 2224, dtype: float64
Date
2011-01-03 0.007780
2011-01-04 0.010547
2011-01-05 0.025167
2011-01-06 0.020351
2011-01-07 0.029766
...
2019-10-28 NaN
2019-10-29 NaN
2019-10-30 NaN
2019-10-31 NaN
2019-11-01 NaN
Name: XOM_5d, Length: 2224, dtype: float64
Date
2011-01-03 0.015292
2011-01-04 0.022430
2011-01-05 0.026908
2011-01-06 0.035382
2011-01-07 0.041275
...
2019-10-28 NaN
2019-10-29 NaN
2019-10-30 NaN
2019-10-31 NaN
2019-11-01 NaN
Name: XOM_6d, Length: 2224, dtype: float64
Date
2011-01-03 0.027230
2011-01-04 0.024166
2011-01-05 0.042035
2011-01-06 0.046954
2011-01-07 0.035058
...
2019-10-28 NaN
2019-10-29 NaN
2019-10-30 NaN
2019-10-31 NaN
2019-11-01 NaN
Name: XOM_7d, Length: 2224, dtype: float64
---------------------
def process_data_for_labels(ticker):
hm_days = 7
df = pd.read_csv('sp500_joined_closes.csv', index_col=0)
tickers = df.columns.values.tolist()
df.fillna(0, inplace=True)
for i in range(1, hm_days+1):
df['{}_{}d'.format(ticker, i)] = (df[ticker].shift(-i) - df[ticker]) / df[ticker]
print(df['{}_{}d'.format(ticker, i)])
df.fillna(0, inplace=True)
return tickers, df
process_data_for_labels('XOM')
--------------------------
reference:
https://www.youtube.com/watch?v=Z-5wNWgRJpk&list=PLQVvvaa0QuDcOdF96TBtRtuQksErCEBYZ&index=9
No comments:
Post a Comment