<jupyter_start><jupyter_text>During the lecture, we have not touched time-series data, let's do it here<jupyter_code>import pandas as pd
import numpy as np
# read Apple's daily stock prices to pandas, convert date to pandas's datetime format
apple = pd.read_csv('AAPL.csv')

apple['date'] = pd.to_datetime(apple['date'])
# you can calculate your own version of return
# first shift your price series to one row
apple['prc_t_1'] = apple.prc.shift(1)<jupyter_output><empty_output><jupyter_text>Calculate your version of return here:(uncomment below line)<jupyter_code># apple['myret'] =<jupyter_output><empty_output><jupyter_text>Calculate 10-day rolling average for the returns ...You can refer to the doc...https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.window.rolling.Rolling.mean.html(uncomment below line)<jupyter_code># apple['rolling_past10'] = 
# generate future 10 days average returns
apple['rolling_future10'] = apple['rolling_past10'].shift(-10)
# is rolling past return predict future returns? test using np.corrcoef
rollingtest = apple.dropna()
np.corrcoef(rollingtest['rolling_past10'],rollingtest['rolling_future10'])[0][1]<jupyter_output><empty_output><jupyter_text>Working with datetime  access the day of the week using .dthttps://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dt.dayofweek.html<jupyter_code># apple['dayofweek'] =<jupyter_output><empty_output><jupyter_text>substract 5 days from each date using pd.Timedeltahttps://pandas.pydata.org/pandas-docs/stable/user_guide/timedeltas.html<jupyter_code># apple['date_5days'] = 
# compute the difference between date and date_5days
apple['date_diff'] = 
# convert timedeltas to numeric value
apple['date_diff'] / pd.Timedelta('1 day')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup