<jupyter_start><jupyter_text>Oil prices Follow up: we want to see if inflation adjusted prices will have any significantly different result from our "Oil Price" notebook.   Conclusion: no significantly change in terms of quarterly change or seasonality<jupyter_code>df = pd.read_csv(r'.\data\wti-daily.csv')
df.head(2)
df['Date'] = pd.to_datetime(df['Date'])
df.index=df.Date
df=df.drop('Date', axis=1)
plt.rcParams["figure.figsize"] = (20,4)
df.plot()
plt.title("WTI oil price", fontdict={'fontsize': 20, 'fontweight': 'bold'})
plt.ylabel("price $")
price_max= pd.to_datetime("2008-07-03")
ax = df.plot()
plt.title("WTI oil price", fontdict={'fontsize': 20, 'fontweight': 'bold'})
ax.xaxis.set_major_formatter(mdates.DateFormatter('%y'))
ax.xaxis.set_major_locator(mdates.YearLocator())
ax.axvline(price_max, color ='red', alpha=0.5, dashes=(5, 2, 1, 2), linewidth=3.0)
plt.ylabel("price $")
ax.tick_params(direction='in', length=3, width=1, colors='grey')<jupyter_output><empty_output><jupyter_text>Monthly mean<jupyter_code>monthly_mean=df.resample('MS').mean()
monthly_mean.columns=['price']
ax = monthly_mean.plot()
plt.title("average monthly price", fontdict={'fontsize': 20, 'fontweight': 'bold'})
plt.ylabel("price $")
ax.tick_params(direction='in', length=3, width=1, colors='grey')
#import cpi data downloaded from Department of Labor
cpi = pd.read_excel('./data/CPI_all_urban_SeriesReport-20190426102108_bcf8a6.xlsx', index_col=0, skiprows=11)
cpi = cpi.iloc[:,0:11]

cpi.reset_index(drop=False, inplace=True)
cpi =pd.melt(cpi,'Year',var_name="Month",
value_name="cpi")
cpi['Day']=1
cpi['Month']=pd.to_datetime(cpi.Month, format='%b').dt.month
cpi.index=pd.to_datetime(cpi.loc[:,['Year','Month','Day']])
cpi.sort_index(inplace=True)
cpi.drop(['Year','Month','Day'], axis=1, inplace=True)
ax = cpi.cpi.plot()
plt.title("hertorical cpi", fontdict={'fontsize': 20, 'fontweight': 'bold'})
plt.ylabel("index")
ax.tick_params(direction='in', length=3, width=1, colors='grey')
cpi = cpi.loc['1983-07-01':'2019-03-01']
cpi['adjust']= cpi.loc['2019-03-01'].cpi/cpi.cpi
cpi.head()
wti_cpi = pd.merge(left= monthly_mean, right= cpi, how='inner', left_index=True, right_index=True)
wti_cpi['price_adj'] = wti_cpi.price*wti_cpi.adjust
wti_cpi = wti_cpi.loc[:,['price','price_adj']]
wti_cpi.plot()
ax = plt.title("monthly average oil price inflation adjusted and unadjusted", fontdict={'fontsize': 20, 'fontweight': 'bold'})
plt.ylabel("$ price")

#quarterly
wti_cpi = wti_cpi.resample('q').mean()
ax = wti_cpi.plot()
plt.title("monthly average oil price inflation adjusted and unadjusted", fontdict={'fontsize': 20, 'fontweight': 'bold'})
plt.ylabel("index")
ax.tick_params(direction='in', length=3, width=1, colors='grey')
ax = wti_cpi.loc['2004':,:].pct_change().plot()
plt.title("Quarterly change of inflation adjusted oil price and unadjusted price", fontdict={'fontsize': 20, 'fontweight': 'bold'})
plt.ylabel("index")
ax.tick_params(direction='in', length=3, width=1, colors='grey')
ax = wti_cpi.loc['2004':,:].pct_change().rolling(4, center = True).mean().plot()
plt.title("Moving average of quarterly change of inflation adjusted oil price and unadjusted price", fontdict={'fontsize': 20, 'fontweight': 'bold'})
plt.ylabel("index")
ax.tick_params(direction='in', length=3, width=1, colors='grey')
wti_cpi['qtr'] =wti_cpi.index.quarter
wti_cpi['year'] = wti_cpi.index.year
wti_cpi['QoQ'] =wti_cpi.price_adj.pct_change()
wti_cpi= wti_cpi.loc['2004':,['price_adj','QoQ' ,'year','qtr']]
palette = sns.cubehelix_palette(18, start=2, rot=0, dark=0, light = 0.95, reverse = False)
sns.pairplot(wti_cpi,palette=palette, hue='year' )<jupyter_output><empty_output><jupyter_text>Seasonality<jupyter_code>plt.rcParams["figure.figsize"] = (10,5)
sns.boxplot( x='price_adj', y='qtr', data=wti_cpi, showmeans=True,saturation=1.00, orient='h',boxprops=dict(alpha=.5),  palette ='Blues')
plt.title("boxplot of inflation adjusted prices by quarter", fontdict={'fontsize': 20, 'fontweight': 'bold'})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1947211155378486, 'fraction_numerical': 0.03162350597609562, 'mean_word_length': 8.407494145199063, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '624411', 'license': 'MIT', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1558, 'n_words': 278, 'path': 'Oil price-Inflation adjusted.ipynb', 'repo_name': 'magicmathmandarin/financial-trading-data', 'size': '4016'}