In the last tutorial we explored Kalman filter and how to build kalman filter using pykalman python library. In this section we will be dealing with python com server to integrate Amibroker + Python to compute Kalman Filter and Unscented Kalman Filter Mean Estimation and plot the same in Amibroker.
The Kalman Filter and Unscented Kalman Filter is a unsupervised algorithm for tracking a single object in a continuous state space. Given a sequence of noisy measurements, the Kalman Filter is able to recover the “true state” of the underling object being tracked. The difference between kalman and unscented kalman filter is that while the Kalman Filter restricts dynamics to affine functions, the Unscented Kalman Filter is designed to operate under arbitrary dynamics.
Python Library Used:
Pandas – Python Data Analysis and Data structure Library(to handle time series data).
PyKalman – Library to compute Kalman Filter and Unscented Kalman Filter.
Scipy(Dependency Library of PyKalman) – Library used for scientific computing and technical computing
Since Kalman Filter is a statistical model it is relatively difficult to code in AFL Programming Language and hence we rely on Amibroker with Python COM Server and relative python libraries which ease our work. Price data is sent from Amibroker to Python Com Server and then Python does the kalman filter computations and returns back to Amibroker.
Steps to follow in Amibroker
1)Download Kalman-AFL Set and Unzip it
2)Copy the file pyKalman.py to \\python2.7\\bin\\ folder. And execute the file with the command python pyKalman.py in your command prompt as shown below
3)Copy the PyAFL – Kalman Filter.afl file and paste the file in \\Amibroker\\Formulas\\Basic Charts Folder
4)Open a New Blank Chart and apply PyAFL – Kalman Filter.afl to it.
5)Now right click over the charts -> goto parameters and change between Kalman and UnScented Kalman to compute the relevant statistical tool.
Incase if you are very new to Python here is a tutorial on how to install python and relevant python librariess