I can't attach the backtest (probbably because it returns an error), so I am posting the code:
class SwimmingFluorescentYellowAlligator(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2015, 1, 1)
self.SetEndDate(2015, 1, 7)
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("ROST", Resolution.Minute)
def OnData(self, data: Slice):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
if not self.Portfolio.Invested:
self.SetHoldings("ROST", -1)
self.Debug(self.Portfolio["ROST"].IsShort)
This returns an error:
Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'bool'>) method. Please checkout the API documentation.
at OnData
self.Debug(self.Portfolio["ROST"].IsShort)
===
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 17 (Open Stacktrace)
Fred Painchaud
Hi Mislav,
Replace
self.Debug(self.Portfolio["ROST"].IsShort)
with
self.Debug(f"{self.Portfolio["ROST"].IsShort}")
Fred
Mislav Sagovac
This just prints code as string. Doesn't solve the error.
Try this;
Fred Painchaud
Sorry, the issue was the embedded double quotes (inside double quotes)… replied just a tad too fast.
So.
self.Debug(f"{self.Portfolio['ROST'].IsShort}")
or
self.Debug(f'{self.Portfolio["ROST"].IsShort}')
But you already knew that, right.
Fred
Mislav Sagovac
Have you tried the code I posted in reply ?
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!