Hi everyone,
I tried to implement the Kalman Filter for Bitcoin, unfortunately it is not working.
I hope you can give me some advide, to fix the problem.
There is always an error when trying to run a backtest.
from datetime import datetime
import itertools
import pandas as pd
from pykalman import KalmanFilter
import pywt
import matplotlib.pyplot as plt
import seaborn as sns
class EnergeticFluorescentOrangeElephant(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 1)
self.SetEndDate(2019, 12, 31)
btc = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol
self.kf = KalmanFilter(transition_matrices = [1],
observation_matrices = [1],
initial_state_mean = 0,
initial_state_covariance = 1,
observation_covariance=1,
transition_covariance=.01)
#btc_price = self.kf.filter(btc)
def OnData(self, data):
#self.Plot("Grafik", "BTC-Kalman", btc_price)
self.Plot("Grafik", "BTC", btc)
I hope you can help me.
Best reagards
Marcel
Fred Painchaud
Hi Marcel,
I don't know the Kalman filter but I guess the class indicator you are using is working fine. However, I can certainly spot a small omission in your code in the following line:
btc = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol
Hint: it is at the very start of the line…
…
…you are missing a “self.” in front of the variable for it to be an instance variable. So you need this:
self.btc = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol
Then you will be able to reference it later in another method, such as OnData.
Cheers,
Fred
Spacetime
Marcel Friz there is an example shown in the post below for kalman filter that may help… take a look at it…
Vladimir
Marcel Friz,
Here is Kalman Filter for BTCUSD with your setup.
Marcel Friz
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!