-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARIMA_pure.py
78 lines (65 loc) · 2.99 KB
/
ARIMA_pure.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
# import necessary Packages below:
import numpy as np
import numpy
from pmdarima.arima import auto_arima
def myTradingSystem(DATE, OPEN, HIGH, LOW, CLOSE, VOL, exposure, equity, settings):
nMarkets=CLOSE.shape[1]
log_diff = np.diff(np.log(CLOSE),axis=0)
weights = np.zeros(nMarkets)
periodLonger=200
print('{} {}'.format(DATE[0],DATE[-1]))
build = settings['counter']%20==0
for i in range(nMarkets):
curr_market = log_diff[-periodLonger:,i]
try:
if build:
model = auto_arima(curr_market, error_action='ignore', suppress_warnings=True, seasonal=True, m=4, stepwise=True)#sarima
#model = auto_arima(cur_market, error_action='ignore', suppress_warnings=True)#arima
settings['models'][i] = model
print('==={}:{}'.format(settings['markets'][i], model.params()))
else:
model = settings['models'][i]
print('==={}'.format(settings['markets'][i]))
if model:
model.fit(curr_market)
pred = model.predict(n_periods=1)[0]
print(pred)
if pred:
weights[i] = pred
except Exception as e:
#print('cash')
#pass
print(e)
settings['counter']+=1
return weights, settings
def mySettings():
''' Define your trading system settings here '''
settings= {}
# Futures Contracts
settings['markets'] = ['CASH','F_AD','F_BO','F_BP','F_C','F_CC','F_CD','F_CL',
'F_CT','F_DX','F_EC','F_ES','F_FC','F_FV','F_GC','F_F',
'F_HG','F_HO','F_JY','F_KC','F_LB','F_LC','F_LN','F_MD',
'F_MP','F_NG','F_NQ','F_NR','F_O','F_OJ','F_PA','F_PL',
'F_RB','F_RU','F_S','F_SB','F_SF','F_SI','F_SM','F_TU',
'F_TY','F_US','F_W','F_XX','F_YM','F_AX','F_CA','F_DT',
'F_UB','F_UZ','F_GS','F_LX','F_DL','F_ZQ','F_VX','F_SS',
'F_AE','F_BG','F_BC','F_LU','F_DM','F_AH','F_CF','F_DZ',
'F_FB','F_FL','F_FM','F_FP','F_FY','F_GX','F_HP','F_LR',
'F_LQ','F_ND','F_NY','F_PQ','F_RR','F_RF','F_RP','F_RY',
'F_SH','F_SX','F_TR','F_EB','F_VF','F_VT','F_VW','F_GD','F_F']
# Back testing
settings['beginInSample'] = '20180119'
settings['endInSample'] = '20200331'
# Validation
# settings['beginInSample'] = '20171030'
# settings['endInSample'] = '20191231'
settings['lookback']= 504
settings['budget']= 10**6
settings['slippage']= 0.05
settings['models'] = [None]*len(settings['markets'])
settings['counter']=0
return settings
# Evaluate trading system defined in current file.
if __name__ == '__main__':
import quantiacsToolbox
results = quantiacsToolbox.runts(__file__)