Notebook
In [40]:
SPY = get_pricing(
    'SPY',
    fields=('close_price', 'high', 'low'), #modify to price, open_price, high, low or volume to change the field
    start_date='2015-01-01', #customize your pricing date range
    end_date = '2016-11-01',
    frequency='daily', #change to daily for daily pricing
)

# matplotlib is installed for easy plotting
SPY.plot()
Out[40]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4eb80e2550>
In [41]:
SPY.head()
Out[41]:
close_price high low
2015-01-02 00:00:00+00:00 205.41 206.88 204.180
2015-01-05 00:00:00+00:00 201.80 204.37 201.350
2015-01-06 00:00:00+00:00 199.82 202.72 198.855
2015-01-07 00:00:00+00:00 202.34 202.72 200.880
2015-01-08 00:00:00+00:00 205.92 206.16 203.990
In [ ]:
 
In [ ]:
 
In [42]:
((SPY.shift(-1)['close_price']-SPY['close_price'])/SPY['close_price']).hist(bins = 20)
Out[42]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea97d1110>
In [43]:
((SPY.shift(-1)['low']-SPY['close_price'])/SPY['close_price']).hist(bins = 20)
Out[43]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea9723dd0>
In [44]:
((SPY.shift(-1)['high']-SPY['close_price'])/SPY['close_price']).hist(bins = 20)
Out[44]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea95b4910>
In [48]:
import pandas
In [50]:
SPY_W =SPY['close_price'].resample('W-FRI', label='right', closed='right').last()
In [55]:
SPY_H =SPY['high'].resample('W-FRI', label='right', closed='right').max()
In [73]:
SPY_L =SPY['low'].resample('W-FRI', label='right', closed='right').min()
In [75]:
SPY_L.plot()
Out[75]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea8d3f450>
In [64]:
((SPY_W.shift(-1)-SPY_W)/SPY_W).hist(bins = 20)
Out[64]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea95b4750>
In [76]:
((SPY_H.shift(-1)-SPY_W)/SPY_W).hist(bins = 20)
Out[76]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea8c76890>
In [77]:
((SPY_L.shift(-1)-SPY_W)/SPY_W).hist(bins = 20)
Out[77]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea8c66b50>
In [78]:
SPY_L.describe()
Out[78]:
count     97.000000
mean     203.638202
std        8.319773
min      181.020000
25%      199.950000
50%      204.985000
75%      208.890000
max      217.230000
Name: low, dtype: float64
In [81]:
SPY_H.describe()
Out[81]:
count     97.000000
mean     208.935586
std        6.657850
min      188.340000
25%      206.420000
50%      210.210000
75%      212.590000
max      219.600000
Name: high, dtype: float64
In [82]:
SPY_W.describe()
Out[82]:
count     97.000000
mean     206.567371
std        7.383299
min      186.640000
25%      203.140000
50%      207.850000
75%      211.000000
max      218.570000
Name: close_price, dtype: float64
In [97]:
SPY_W.where(((SPY_W.shift(1) - SPY_W.shift(13))/SPY_W.shift(13)) < -.02).pct_change().hist(bins=30)
Out[97]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea8065750>
In [98]:
SPY_W.where(((SPY_W.shift(1) - SPY_W.shift(2))/SPY_W.shift(2))  < -.01).pct_change().hist(bins=30)
Out[98]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea864cc10>
In [99]:
SPY_W.where(((SPY_W.shift(1) - SPY_W.shift(2))/SPY_W.shift(2))  > .01).pct_change().hist(bins=30)
Out[99]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4ea3d6de50>
In [ ]: