Good afternoon to everyone! I am kind of new to the Kalman Filter, but I have came across this really interesting article (https://pdfs.semanticscholar.org/d348/37b8e535974c341d8c8a5c38666581e83309.pdf) about the possibility of using this filter in financial time-series analysis and in particular in the context of dynamic style analysis. I would like to implement this algorithm but I am not sure on how to specify the transition and observation matrices. Practically speaking I have a mutual fund of reference with 60 observations of monthly returns and 8 indexes with which I want to benchmark the fund. I am focusing on the weak style analysis since it should be the easiest to code with the Pykalman library. This is the code up to now, I only need to specify the transition and observation matrices:
import matplotlib.pyplot as plt
from pykalman import KalmanFilter
import numpy as np
import pandas as pd
df1 = pd.read_excel('/Users/marco/Desktop/SA_trial.xlsx')
df1.drop(['Mth'], axis='columns', inplace=True)
fund = df1.iloc[:, 0:1]
index = df1.iloc[:, 2:10]
fund = np.array(fund)
index = np.array(index)
n_timesteps = index.shape[0]
measurements = np.asarray(fund)
kf = KalmanFilter(transition_matrices=np.identity(8),
observation_matrices=index[0, :],
#transition_offsets=[0, 0, 0, 0, 0, 0, 0, 0],
initial_state_mean=index[0])
(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
kf.em(measurements).smooth(measurements)[0]
print('------\n')
print(filtered_state_means)
print(len(filtered_state_means.shape))
weights = filtered_state_means
benchmark = []
for i in range(len(weights)):
benchmark_return = index[i] @ weights[i]
benchmark.append(benchmark_return)
print('------\n')
print(benchmark)
plt.plot(measurements, '-r', label='measurment')
plt.plot(benchmark, '-g', label='kalman-filter output')
plt.legend(loc='upper left')
plt.show()
Thanks in advance for your time!