Back

Problem with SetHoldings

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])

 

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.


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']

0

Please post an example demonstrating your issue for best assistance.
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 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?

0

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

 

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