forked from je-suis-tm/quant-trading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOil Money CAD.py
124 lines (84 loc) · 2.44 KB
/
Oil Money CAD.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# coding: utf-8
# In[1]:
import pandas as pd
import os
import matplotlib.pyplot as plt
import statsmodels.api as sm
os.chdir('d:/')
import numpy as np
# In[2]:
df=pd.read_csv('wcs crude cadaud.csv',encoding='utf-8')
# In[3]:
df.set_index('date',inplace=True)
# In[4]:
df.index=pd.to_datetime(df.index,format='%m/%d/%Y')
# In[5]:
df=df.reindex(columns=
['cny',
'gbp',
'usd',
'eur',
'krw',
'mxn',
'lng',
'wcs',
'edmonton',
'wti',
'gold',
'jpy',
'cad'])
# In[6]:
var=locals()
for i in df.columns:
if i!='cad':
x=sm.add_constant(df[i])
y=df['cad']
m=sm.OLS(y,x).fit()
var[str(i)]=m.rsquared
ax=plt.figure(figsize=(10,5)).add_subplot(111)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
width=0.7
colorlist=['#9499a6','#9499a6','#9499a6','#9499a6',
'#9499a6','#9499a6','#9499a6','#582a20',
'#be7052','#f2c083','#9499a6','#9499a6']
temp=list(df.columns)
for i in temp:
if i!='cad':
plt.bar(temp.index(i)+width,
var[str(i)],width=width,label=i,
color=colorlist[temp.index(i)])
plt.title('Regressions on Loonie')
plt.ylabel('R Squared\n')
plt.xlabel('\nRegressors')
plt.xticks(np.arange(len(temp))+width,
['Yuan', 'Sterling', 'Dollar', 'Euro', 'KRW',
'MXN', 'LNG', 'WCS', 'Edmonton',
'WTI', 'Gold', 'Yen'],fontsize=10)
plt.show()
# In[7]:
ax=plt.figure(figsize=(10,5)).add_subplot(111)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
(df['cny']/df['cny'].iloc[0]).plot(c='#283670',label='Yuan')
(df['gbp']/df['gbp'].iloc[0]).plot(c='#fe4d32',label='Sterling')
(df['cad']/df['cad'].iloc[0]).plot(c='#484a25',label='Loonie')
plt.legend(loc=0)
plt.xlabel('Date')
plt.ylabel('Normalized Value by 100')
plt.title('Loonie vs Yuan vs Sterling')
plt.show()
# In[8]:
ax=plt.figure(figsize=(10,5)).add_subplot(111)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
(df['wti']/df['wti'].iloc[0]).plot(c='#2a78b2',label='WTI',alpha=0.5)
(df['wcs']/df['wcs'].iloc[0]).plot(c='#7b68ee',label='WCS',alpha=0.5)
(df['edmonton']/df['edmonton'].iloc[0]).plot(c='#110b3c',
label='Edmonton',alpha=0.5)
(df['cad']/df['cad'].iloc[0]).plot(c='#cb8b8b',label='Loonie')
plt.legend(loc=0)
plt.xlabel('Date')
plt.ylabel('Normalized Value by 100')
plt.title('Loonie vs Crude Oil Blends')
plt.show()