Good Evening y'all,
I was working on this mean reversion strategy and just on some quick tests I noticed that despite USDCAD and USDJPY being set to the same number in setHoldings, the numbers weren't representative of the actualy units the leverage gets you. Allocating 10% of the portfolio to each should have USDCAD with roughly twice as many units as USDJPY, at least through my broker (Oanda). Is there a way to call max units available for purchase from the broker to use for quantity?
Alexandre Catarino
SetHoldings calculates (using CalculateOrderQuantity method) the allocation based on total portfolio value.
At t = 0, total portfolio value is initial cash, in your case $1000. The calculation procedure is the following:
// Get unit price in terms of the account currency USDJPY price = 117.013 JPYUSD conversion rate = 0.00855 (~ 1 / 117.013) unitJPY = USDJPY * JPYUSD ~ 1.0001 qntyJPY = portfolio value * target / unitJPY = 1000 * 5 / 1.0001 ~ 4995 USDCAD price = 1.4538 CADUSD conversion rate = 0.68586 (~ 1 / 1.4538) unitCAD = USDCAD * CADUSD ~ 0.9971 qntyCAD = portfolio value * target / unitCAD = 1000 * 5 / 0.9971 ~ 5015
We can calculate the maximum quantity we are allowed to place using CalculateOrderQuantity with the target being the leverage:
var maxQntyJPY = CalculateOrderQuantity("USDJPY", 50); var maxQntyCAD = CalculateOrderQuantity("USDCAD", 50);
William Patterson
Many thanks
William Patterson
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!