Target weights and portfolio values does not match at all when using SetHoldings. What can be the reason for that? (Please, note that I am using FX market and check those hourly so the change in asset prices can't be the reason for such a large deviation)
values = []
for asset in trade_assets:
values.append(self.Portfolio[asset].Quantity * self.Portfolio[asset].Price)
pvalues = np.array(values)
pvalues /= np.sum(np.abs(pvalues))
self.Debug(pvalues)
self.Debug(target_weights)
for i, asset in enumerate(trade_assets):
self.SetHoldings(asset, target_weights[i])
Kamer Ali Yüksel
I just noted that the base currencies of these assets were different. Hence, there may be an error with my calculation of portfolio weights since that the "Price" values of those assets are not probably using the same currency. I will check if the problem persists after fixing this error in the portfolio weights calculation.
trade_assets = ['EURAUD', 'EURNZD', 'GBPAUD', 'GBPNZD', 'USDSEK', 'AUDUSD', 'NZDUSD']
Jared Broad
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.
Kamer Ali Yüksel
Thanks Jared, there wasn't an issue actually, it was just my miscalculation. I wasn't using uniform base currency while calculating the weights of the positions within the portfolio. Is there an existing function for getting the portfolio weights (ratios) for each asset (or position) in the portfolio?
Jack Simonson
Hi Kamer,
There is no built-in function or method to retrieve the current portfolio weights, but the best way to calculate these would be dividing the value of the holding of each individual security by the value of all holdings in the portfolio.
## In initialize self.ratios = {} self.symbols = ['SPY', 'IBM', 'AAPL'] for symbol in self.symbols: self.AddEquity(symbol, Resolution.Daily) def CalculateWeight(self, symbol): if self.Portfolio.TotalHoldingsValue > 0: self.ratios[symbol] = self.Securities[symbol].Holdings.AbsoluteHoldingsValue/self.Portfolio.TotalHoldingsValue else: self.ratios[symbol] = 0
Kamer Ali Yüksel
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!