While creating PortoflioTargets using PortfolioTarget.Percent, I get this error. However, I do not gett it in backtest--only in paper or live trading:
The order quantity for SSO cannot be calculated: the price of the security is zero.
I belive this then leads to uncaught exceptions further down the line:
Runtime Error: Object reference not set to an instance of an object Stack Trace: System.NullReferenceException: Object reference not set to an instance of an object
at QuantConnect.Algorithm.QCAlgorithm.ProcessInsights (QuantConnect.Algorithm.Framework.Alphas.Insight[] insights) [0x0003d] in <2de485accd7544f5980cafdf65806aed>:0
at QuantConnect.Algorithm.QCAlgorithm.OnFrameworkData (QuantConnect.Data.Slice slice) [0x001a4] in <2de485accd7544f5980cafdf65806aed>:0
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper.OnFrameworkData (QuantConnect.Data.Slice slice) [0x00000] in <65d87ad6b5074b758360f25b819835f2>:0
at QuantConnect.Lean.Engine.AlgorithmManager.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Interfaces.IAlgorithm algorithm, QuantConnect.Lean.Engine.DataFeeds.ISynchronizer synchronizer, QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler transactions, QuantConnect.Lean.Engine.Results.IResultHandler results, QuantConnect.Lean.Engine.RealTime.IRealTimeHandler realtime, QuantConnect.Lean.Engine.Server.ILeanManager leanManager, QuantConnect.Lean.Engine.Alpha.IAlphaHandler alphas, System.Threading.CancellationToken token) [0x0160a] in <f378596eae5c4b1ba30b5fd3bee83316>:0
I am creating my porfolio targets in a custom portfolio construction model in the CreateTargets method. Is there something I should be doing differently? This code works exactly as I want it to in backtest.
Michael Manus
you need probably something like this "if" - codeline
(it seems you are accessing data that is not there with data[self.symbol] <- only example)
[check the examples on github there are a lot of these codelines used in the example code provided by QC]:
def OnData(self, data):
if not data.ContainsKey(self.symbol): return
..
.
.
.
.
.
Michael Manus
write back if its that problem.
maybe the QC Team can edit the docu to add your error to the "common error" - chapter
KILLC
my code isn't getting any price data, the framework code that is using price to calculate the number of shares to purchase based on my specifed pct allcation is causing this issue. i'm wondering why these symbols (which do trade and should have a price) are coming up with no price data in QuantConnect
Michael Manus
hmm so when it is not your code you should write directly to support@quantconnect.com
Michael Manus
but wait: you are writing that you calculate number of shares based on the price. oh ok its the framework code. write the support it seems you maybe found a bug.
the slice object what i heard provides data on every resolution you subscribed.
if you access data that is not ready you could get this error.
also if there was no data in this time period or when data is missing.
there is a section in the community only for missing data "DATA ISSUES"
Michael Manus
could you please write back what the problem was.
(it popped up while aswering in this forum :) )
i have on a similar backtest problem and can't figure out where the problem is:
System.Exception: NullReferenceException : Object reference not set to an instance of an object
at QuantConnect.Indicators.IndicatorBase`1[T].Update (QuantConnect.Data.IBaseData input) [0x0000e] in <6c3d2eeddb0b4318a1d02ee463443097>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in :0
at OnData in main.py:line 73
---> Python.Runtime.PythonException: NullReferenceException : Object reference not set to an instance of an object
at QuantConnect.Indicators.IndicatorBase`1[T].Update (QuantConnect.Data.IBaseData input) [0x0000e] in <6c3d2eeddb0b4318a1d02ee463443097>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in :0
at Python.Runtime.PyObject.Invoke (Python.Runtime.PyTuple args, Python.Runtime.PyDict kw) [0x00033] in :0
at Python.Runtime.PyObject.TryInvoke (System.Dynamic.InvokeBinder binder, System.Object[] args, System.Object& result) [0x0001d] in :0
at (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object,QuantConnect.Data.Slice)
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper.OnData (QuantConnect.Data.Slice slice) [0x00082] in <65d87ad6b5074b758360f25b819835f2>:0
at QuantConnect.Lean.Engine.AlgorithmManager.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Interfaces.IAlgorithm algorithm, QuantConnect.Lean.Engine.DataFeeds.ISynchronizer synchronizer, QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler transactions, QuantConnect.Lean.Engine.Results.IResultHandler results, QuantConnect.Lean.Engine.RealTime.IRealTimeHandler realtime, QuantConnect.Lean.Engine.Server.ILeanManager leanManager, QuantConnect.Lean.Engine.Alpha.IAlphaHandler alphas, System.Threading.CancellationToken token) [0x015f6] in
KILLC
I will follow up here if I am able to resolve the issue.
Michael Manus
i found my problem.
there was an empty candle with no data at midnight.
if data[self.symbol] is None:
helped to find the problem.
Jared Broad
The midnight data was a split or dividend event.
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.
Michael Manus
oh dividend.....ok that makes sense....
thanks jared for looking up
KILLC
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!