1start_date = '2015-01-01'
2end_date = '2016-12-31'
3
4fig, ax = plt.subplots(figsize=(16,9))
5
6ax.plot(data.loc[start_date:end_date, :].index, data.loc[start_date:end_date, 'MSFT'], label='Price')
7ax.plot(long_rolling.loc[start_date:end_date, :].index, long_rolling.loc[start_date:end_date, 'MSFT'], label = '100-days SMA')
8ax.plot(short_rolling.loc[start_date:end_date, :].index, short_rolling.loc[start_date:end_date, 'MSFT'], label = '20-days SMA')
9
10ax.legend(loc='best')
11ax.set_ylabel('Price in $')
12ax.xaxis.set_major_formatter(my_year_month_fmt)
13
1# Calculating the short-window simple moving average
2short_rolling = data.rolling(window=20).mean()
3short_rolling.head(20)
4
1import pandas as pd
2import numpy as np
3import matplotlib.pyplot as plt
4import matplotlib.dates as mdates
5%matplotlib inline
6import seaborn as sns
7sns.set(style='darkgrid', context='talk', palette='Dark2')
8
9my_year_month_fmt = mdates.DateFormatter('%m/%y')
10
11data = pd.read_pickle('./data.pkl')
12data.head(10)
13
1# Calculating the long-window simple moving average
2long_rolling = data.rolling(window=100).mean()
3long_rolling.tail()
4