/
strat_reversal_description.py
153 lines (107 loc) · 3.23 KB
/
strat_reversal_description.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 29 09:44:27 2017
@author: teogo
"""
import numpy as np
import dask.dataframe as dd
import os
import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
import numpy as np
params = {'legend.fontsize': 'xx-large',
'figure.figsize': (18, 15),
'axes.labelsize': 'xx-large',
'axes.titlesize':'xx-large',
'xtick.labelsize':'xx-large',
'ytick.labelsize':'xx-large'}
pylab.rcParams.update(params)
w_dir = 'D:/BIG DATA'
directory_load = 'Merged Files'
directory_save = 'Strategy Reversal'
os.chdir(w_dir)
ccys = ['EURUSD', 'EURCHF', 'EURGBP', 'EURJPY', 'EURAUD']
df = dd.read_hdf(directory_load+'/'+ccys[1]+'-'+str(2014)+'.h5',ccys[1]+str(2014)+'05')
plt.figure()
plt.plot(df.compute())
#%%
with open(directory_save+'/Report.txt', 'r') as fout:
file = fout.read()
#%%
lines = file.split()
read_ccy = False
read_PL = False
performance_usd = []
performance_chf = []
performance_gbp = []
performance_jpy = []
performance_aud = []
for elem in lines:
if not read_ccy:
if elem=='Ccy:':
read_ccy = True
else:
ccy = elem
read_ccy = False
if not read_PL:
if elem=='P&L:':
read_PL = True
else:
PL = float(elem)
read_PL = False
if ccy == ccys[0]:
performance_usd.append(PL)
if ccy == ccys[1]:
performance_chf.append(PL)
if ccy == ccys[2]:
performance_gbp.append(PL)
if ccy == ccys[3]:
performance_jpy.append(PL)
if ccy == ccys[4]:
performance_aud.append(PL)
#%%
plt.figure()
plt.plot(range(2004,2017),np.cumsum(np.array([performance_usd,performance_chf,performance_gbp,performance_aud]).T,axis=0))
plt.legend(['EURUSD', 'EURCHF', 'EURGBP', 'EURAUD'])
#%%
directory_save = 'Strategy Reversal Testing'
with open(directory_save+'/Report.txt', 'r') as fout:
file = fout.read()
lines = file.split()
read_ccy = False
read_PL = False
performance_usd = []
performance_chf = []
performance_gbp = []
performance_jpy = []
performance_aud = []
for elem in lines:
if not read_ccy:
if elem=='Ccy:':
read_ccy = True
else:
ccy = elem
read_ccy = False
if not read_PL:
if elem=='P&L:':
read_PL = True
else:
PL = float(elem)
read_PL = False
if ccy == ccys[0]:
performance_usd.append(PL)
if ccy == ccys[1]:
performance_chf.append(PL)
if ccy == ccys[2]:
performance_gbp.append(PL)
if ccy == ccys[3]:
performance_jpy.append(PL)
if ccy == ccys[4]:
performance_aud.append(PL)
#%%
plt.figure()
plt.plot(range(1,12),np.cumsum(np.array([performance_usd,performance_chf,performance_gbp,performance_aud]).T,axis=0))
plt.legend(['EURUSD', 'EURCHF', 'EURGBP', 'EURAUD'])
plt.figure()
plt.plot(range(1,12),np.array([performance_usd,performance_chf,performance_gbp,performance_aud]).T)
plt.legend(['EURUSD', 'EURCHF', 'EURGBP', 'EURAUD'])