算术交易和机器学习 Algorithmic Trading and Machine Learning MATH97109

0

<!-- wp:code -->
for p1 in range (4): # AR order
for q1 in range $(4)$ : # MA order
for p2 in range $(3)$ : # seasonal AR order
for q2 in range $(3): \quad \#$ seasonal MA order
$y$-pred $=$ []
for i, $T$ in enumerate(range (train_size, len (data))):
train_set $=$ data.iloc[T - train_size:T]
model = tsa.sARIMAX (endog=train_set, # model
specification
order $=\left(p 1,0, q^{1}\right)$,
seasonal_orde $r=\left(p^{2}, 0, q^{2}\right.$,
12)). fit ()
preds. iloc $[1,1]$ = mode 1 . forecast $($ steps $=1)[0]$ # $1-$
mse = mean_squared_error (preds.y_true, preds.y_pred)
test_results $\left[\left(p 1, q_{1}, p^{2}, q_{2}\right)\right]=$ [np.sqrt (mse),
preds. $y_{-}$true. sub (preds. Y_pred) .std(),
np. mean (aic)]

MATH97109COURSE NOTES ：

trainsize $=10 * 252$ # 10 years
data = nasdaq_returns. clip (lower=nasdaq_returns. quantile $(.05)$,
upper=nasdaq_returns. quantile(.95))
$T=\operatorname{len}$ (nasdaq returns)
test_results $=\{\}$
for $p$ in range $(1,5)$ :
for $q$ in range $(1,5)$ :
print $\left\{f^{\prime}\{p\} \mid\{q\}^{\prime}\right)$
result $=$ []
for $s, t$ in enumerate (range(trainsize, $T-1))$ :
train_set $=$ data $+i l o c[s: t]$
test_set $=$ data.iloc[t+1] # 1 -step ahead forecast
model = arch_model (y=train_set, $p=p, q=q)$. fit (disp='off')
forecast = model. forecast (horizon=1)
$m u=$ forecast.mean. iloc $[-1,0]$
$\mathrm{var}=$ forecast. $v$ ariance. il oc $[-1,0]$
result. append ([(test_set-mul ${ }^{\star \star} 2$, var] $)$
$d f=$ pd. DataErame (result, columns= ['y_true', 'y_pred'])
test_results $[(p, q)]=$ np.sqrt (mean_squared_error (df. $q$ _true,
df. y_pred) )