AMRA Model and Kalman Filter (01)

Autocorrelation
We often need to characterize time series autocorrelation, , which is defined as
When the sequence is weakly stationary, i.e.
where ,
, and
are constant, we write
Now, let’s work on more technical stuffs. If are independent and identically distributed sequence, then the sample autocorrelation
is asympotically normal with mean zero (trivially) and variance . For weakly stationary sequence
,
is asympotitically normal with mean zero and variance
if we assume for
. Therefore, a t-ratio test statistic can be derived such that
for the test
Q Test
When testing on multiple autocorrelations being zero, Box and Pierce (1970) and Ljung and Box (1978) classic work provided test on the hypothesis
The Q test defined as
which follows a chi-squared distribution with $n$ degree of freedom. With Python `statsmodels` module, we can easily check the test results of some financial data.
S&P 500 Data
[sourcecode language=”python” light=”true” wraplines=”false” collapse=”false”]
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pandas.io.data as web
import statsmodels.tsa.api as smafrom statsmodels.tsa.arima_model import ARMA
%matplotlib inlinestart = ‘2006-01-01’
end = ‘2010-12-31’
df_data = web.DataReader(‘GSPC’, ‘yahoo’, start, end)
df_data.tail()
[/sourcecode]
—

S&P 500 Daily Log Returns Analysis
[sourcecode language=”python” light=”true” wraplines=”false” collapse=”false”]
array_adjclose = df_data[‘Adj Close’].values
array_logret_adjclose = np.log(array_adjclose)[1:] – np.log(array_adjclose)[:-1]
array_logret_adjclose = np.insert(array_logret_adjclose, 0, 0)
df_data[‘Log Return’] = array_logret_adjcloseax = df_data[‘Log Return’].plot()
ax.set_title(‘Daily Log Return’)
[/sourcecode]—
[sourcecode language=”python” light=”true” wraplines=”false” collapse=”false”]
fig, ax = plt.subplots(2, 1)
ax[0].plot(sma.stattools.acf(array_logret_adjclose))
ax[1].plot(sma.stattools.pacf(array_logret_adjclose))fig, ax = plt.subplots(3, 1)
acf, confint, qstat, pvalues = sma.stattools.acf(array_logret_adjclose, alpha=0.05, qstat=True)
ax[0].plot(acf)# Q Stats
ax[1].plot(qstat)# P Values
ax[2].plot(pvalues)
[/sourcecode]

—
What’s Next?
We will examine how to choose and calibrate an ARMA model.