Hello,
I am trying to use federal funds rate data in my algo. I have been folloeing FRED docs hereĀ
Here is sample code (can't attach backtest because of error):
# region imports
from AlgorithmImports import *
# endregion
class SquareYellowGreenCaterpillar(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 4, 13) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.ir = self.AddData(Fred, Fred.CommercialPaper.CPFF, Resolution.Daily).Symbol
# Historical data
history = self.History(self.ir, 60, Resolution.Daily)
self.Debug(f"We got {len(history)} items from our history request")
def OnData(self, data: Slice):
if slice.ContainsKey(self.fred_peak_to_trough):
ir = slice.Get(Fred, self.ir).Value
This simple script returns an error:
[ERROR] FATAL UNHANDLED EXCEPTION:Engine.Run(): During the algorithm initialization, the following exception has occurred: type object 'CommercialPaper' has no attribute 'CPFF', at Initialize, self.ir = self.AddData(Fred in main.py: line 9, type object 'CommercialPaper' has no attribute 'CPFF',ApiConnection.TryRequest(backtest/status/update): Error: The operation has timed out.
Nico Xenox
Hey Mislav Sagovac,
When adding data from Fred you have to use the accessor code not the symbol. Also change slice to data. Otherwise your OnData def should be OnData(self, slice)
I attached the working example.
Hope it helps ;)
Mislav Sagovac
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!