Back

Divide by 0 in stochastic

Here is the simple code to try out Stoch indicator and I got divide by 0 exception.

Stack trace is at the end of this code

namespace QuantConnect
{
/*
* QuantConnect University: Bollinger Bands Example:
*/
public class IndicatorSuiteAlgorithm : QCAlgorithm
{
string _symbol = "ACWI";
Stochastic _sto = null;


//Initialize the data and resolution you require for your strategy:
public override void Initialize()
{
//Initialize
SetStartDate(2015, 6, 1);
SetEndDate(DateTime.Now.Date.AddDays(-1));
SetCash(25000);

//Add as many securities as you like. All the data will be passed into the event handler:
AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute);
_sto = STO(_symbol, 14, 1, 1, Resolution.Minute);

}


public void OnData(TradeBars data)
{
if (!_sto.IsReady) return;
Plot("STO", _sto);
}
}
}

=====================

at System.Decimal.op_Division (Decimal d1, Decimal d2) [0x00000] in :0
at QuantConnect.Indicators.Stochastic.ComputeFastStoch (Int32 period, QuantConnect.Data.Market.TradeBar input) [0x00000] in :0
at QuantConnect.Indicators.Stochastic+<>c__DisplayClass12.<.ctor>b__0 (QuantConnect.Data.Market.TradeBar input) [0x00000] in :0
at (wrapper delegate-invoke) System.Func`2:invoke_TResult_T (QuantConnect.Data.Market.TradeBar)
at QuantConnect.Indicators.FunctionalIndicator`1[QuantConnect.Data.Market.TradeBar].ComputeNextValue (QuantConnect.Data.Market.TradeBar input) [0x00000] in :0
at QuantConnect.Indicators.IndicatorBase`1[QuantConnect.Data.Market.TradeBar].Update (QuantConnect.Data.Market.TradeBar input) [0x00000] in :0
at QuantConnect.Indicators.Stochastic.ComputeNextValue (QuantConnect.Data.Market.TradeBar input) [0x00000] in :0
at QuantConnect.Indicators.IndicatorBase`1[QuantConnect.Data.Market.TradeBar].Update (QuantConnect.Data.Market.TradeBar input) [0x00000] in :0
at QuantConnect.Algorithm.QCAlgorithm+<>c__DisplayClass18`1[QuantConnect.Data.Market.TradeBar].b__17 (System.Object sender, QuantConnect.Data.BaseData consolidated) [0x00000] in :0
at QuantConnect.Data.Consolidators.DataConsolidator`1[QuantConnect.Data.Market.TradeBar].OnDataConsolidated (QuantConnect.Data.BaseData consolidated) [0x00000] in :0
at QuantConnect.Data.Consolidators.IdentityDataConsolidator`1[QuantConnect.Data.Market.TradeBar].Update (QuantConnect.Data.Market.TradeBar data) [0x00000] in :0
at QuantConnect.Data.Consolidators.DataConsolidator`1[QuantConnect.Data.Market.TradeBar].Update (QuantConnect.Data.BaseData data) [0x00000] in :0
at QuantConnect.Lean.Engine.AlgorithmManager.Run (QuantConnect.Packets.AlgorithmNodePacket job, IAlgorithm algorithm, IDataFeed feed, ITransactionHandler transactions, IResultHandler results, IRealTimeHandler realtime, CancellationToken token) [0x00000] in Lean.Engine.AlgorithmManager.Run (QuantConnect.Packets.AlgorithmNodePacket job, IAlgorithm algorithm, IDataFeed feed, ITransactionHandler transactions, IResultHandler results, IRealTimeHandler realtime, CancellationToken token) [0x00000] in :0
Update Backtest








In the future please attach the backtest so other users can clone instead of copying code! :)

It looks like you've found a bug! This line should check for divide by zero, very necessary for thinly traded stocks.

I'll submit a fix to the open source project now.
0

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.


Thanks Michael. I see that you have checked in the fix in open source. Is this fix instanlty gets available in QuantConnect or do I have to wait until release schedule to get this on QuantConnect ? If certain rlease schelue is followed where can I find what fixes are being used QuantConnect vs latestest opensouce lean project on GitHub ?

Thanks
0

When you build your algorithm you can see the version number in the console, currently it is version:
Build Request Successful for .... Lean Version: 2.1.3.5

The LEAN version number is here on the github project:
https://github.com/QuantConnect/Lean/blob/master/Common/Properties/SharedAssemblyInfo.cs
0

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.


Hi Jared,
When will QC pull latest version of Lean. Is there a schedule or is it daily/weekly/Monthly pull ? In above example I am interested in Michael fix which is available in Lean 2.1.3.6. QC web build for back testing shows 2.1.3.5
0

Update Backtest





0

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.


Loading...

This discussion is closed