In [1]:
%matplotlib inline
In [2]:
import pandas as pd
import pandas.io.data as web
import datetime
start=datetime.datetime(2014, 1, 1)
end=datetime.datetime(2015, 1, 1)
# %5EGSPC sp500
f = web.DataReader("%5EGSPC", 'yahoo', start, end)
print(f.head())
In [3]:
csvfile='sp500.csv'
f.to_csv(csvfile)
df = pd.read_csv(csvfile, index_col='Date', parse_dates=True)
print(df.head())
In [4]:
df2 = df['Open']
print(df2.head())
In [5]:
df3 = df[['Close','High']]
print(df3.head())
In [6]:
df4 = df3[(df3['Close'] > 1400)]
print(df4.head())
In [7]:
df['H-L'] = df.High - df.Low
print(df.head())
In [8]:
df['100MA'] = pd.rolling_mean(df['Close'], 100)
print(df[200:210])
In [9]:
df['Difference'] = df['Close'].diff()
print(df.head())
In [10]:
import matplotlib.pyplot as plt
df[['Open','High','Low','Close','100MA']].plot()
plt.show()
In [ ]: