Back

CalculateOrderQuantity divide by 0 when using USDJPY but not EURUSD

I have an algo thats been running for a while live on FXCM using EURUSD as my security. I'd like to switch to USDJPY but when running the backtest I get a new stacktrace error and I can't figure out why.

Any ideas? Same algo, different currency pair

146 | 10:33:07:Runtime Error: Division by zero (Open Stacktrace)

at System.Decimal.op_Division (Decimal d1, Decimal d2) [0x00000] in :0
at QuantConnect.Algorithm.QCAlgorithm.CalculateOrderQuantity (QuantConnect.Symbol symbol, Decimal target) [0x00000] in :0
at QuantConnect.FXCMBollengerBands.OnDataFifteen (System.Object sender, QuantConnect.Data.Market.TradeBar consolidated) [0x00000] in :0
Update Backtest






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.



I wonder if unitPrice is somehow 0 here

 

https://github.com/QuantConnect/Lean/blob/master/Algorithm/QCAlgorithm.Trading.cs#L626

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.


Disabling the warm up it works fine but takes 10 days to warm up. It may be an issue with the SetWarmup logic. We'll have to look into this deeper and will get back to you here.

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.


unitPrice is zero here, because Security.QuoteCurrency.ConversionRate is zero here.

The conversion rate is updated when the CashBook is updated which only occurs after the warming up period.

The IsWarmingUp condition check is missing from the algorithm:

private void OnDataFifteen(object sender, TradeBar consolidated)
{
if (IsWarmingUp) return;
// ...
}

So why did it work for EURUSD?
Because the AccountCurrency is USD, therefore the conversion rate is 1.

When the algorithm traded EURUSD without the IsWarmingUp condition check, it didn't throw "Division by zero" exception, but it was buying it on 10 days before the StartDate. Since it was running in live mode, that detail passed unnoticed.

2

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.


Great catch thank yiou

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.


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