Hi,
Some background of what I am trying to test. I am trying to backtest strategy which do both long & short BTCUSD together with SPY. However I was unable to do so as shorting BTCUSD requires using the BitFinex brokerageModel. (which does not allows trading of US equities)
Thus I forego the above approach and created customData for BTCUSD. This allows me to go short both BTCUSD & SPY usiong the traditional self.SetHoldings method.
However I am working with the algorithm framework, and somehow the Alpha model does not detect the custom added symbol.
I tested with the inbuilt bitfinex data and the framework detects thus it should be some issue with the Custom Data code I wrote or the issue with the Alpha model with using Custom Data.
Pranava
To test with bitfinex data. Set:
self.useCustomCryptoData = False
To test with custom data and non framework mode:
self.useCustomCryptoData = True self.benchmarkMode = True
Attached the backtest with custom data using SetHoldings. It is able to trade BTCUSD and SPY together.
Any help is appreciated!
Pranava
The OnSecuritiesChanged method in Alpha model does not detect the customData.
I hack thru by adding the customData using algorithm.Portfolio.Keys (which contains the customData).
Is there a better way to do this?
def OnSecuritiesChanged(self, algorithm, changes): for symbol in algorithm.Portfolio.Keys: symbolData = self.symbolDataBySymbol.get(symbol) if symbolData is None: symbolData = SymbolData(symbol) self.symbolDataBySymbol[symbol] = symbolData else: ...... # this does not detect! for added in changes.AddedSecurities: .......
Shile Wen
Hi Pravana,
Your question was answered in this thread. For future reference, please do not create duplicate threads on the same issue.
Best,
Shile Wen
Pranava
Hi Shile,
Its a different issue of not handling custom data in the framework. Which is y i started a thread. :)
Gave the background but this issue have nothing to do with trading crypto
Shile Wen
Hi Pravana,
Another method would be to pass the custom data by the Alpha Model constructor or pass the instance of the QCAlgorithm (self in the TestCustomSymbolWithFramework class) and add the custom data in the Alpha model's init method.
Best,
Shile Wen
Pranava
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!