Back

Basic divide operator not working?

Hi,

Im trying to add a function that will do a bit of risk management for me. Currently I have the below snippet. However I'm seeing that sometimes the function will return an absurdly small amount, like 17 where it should be returning something like a few million. 

I further find upon debugging that even if self.MaxLossAbsolute = 20k and 2*self.ATR_Now is 0.0040, when you add them together you get 20,000.004, which is what youd expect, but when you divide them in "self.MaxLossAbsolute / 2 * self.ATR_Now", somehow the returned figure gets screwed up.

Anyone have any ideas whats going on?

def CalculateTradeSize(self):
self.MaxLossAbsolute = self.Portfolio.Cash * 0.02
self.MaxLossAbsolute + 2*self.ATR_Now

return self.MaxLossAbsolute / 2 * self.ATR_Now

 

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.


Hey Ben,

Your algorithm is interpreting

self.MaxLossAbsolute / 2 * self.ATR_Now

as (self.MaxLossAbsolute/2) * self.Atr_Now.

Make sure to use parenthesis for precision,

self.MaxLossAbsolute / (2 * self.ATR_Now)

Best
Rahul 

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.


i feel incredibly silly for failing basic math. thanks rahul

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