In the Fundamental Factor Long Short Strategy tutorial here is the part of rebalance function
# Assign each stock equally. Always hold 10% cash to avoid margin call
for i in self.long:
self.SetHoldings(i,0.9/self.num_fine)
for i in self.short:
self.SetHoldings(i,-0.9/self.num_fine)
shouldn't it be:
# Assign each stock equally. Always hold 10% cash to avoid margin call
for i in self.long:
self.SetHoldings(i,0.45/self.num_fine)
for i in self.short:
self.SetHoldings(i,-0.45/self.num_fine)
if .9 does work, will .45 work too?
Ehsan B
what if i want .7 of my portfolio to long and .3 of portfolio to short?
Adam W
self.long = [x.Symbol for x in sorted_symbol[:int(self.num_fine/2)]]
so that the Longs / Shorts add up to self.num_fine.
Â
Anyways, for your follow up question:
def FineSelectionFunction(self, fine): self.long = [x.Symbol for x in sorted_symbol[:int(self.num_fine/2)]] self.short = [x.Symbol for x in sorted_symbol[-int(self.num_fine/2):]] return self.long+self.short def rebalance(self): # Number of Longs/Shorts symbols in filtered tradable universe numLongs = len(self.long) numShorts = len(self.short) # Portfolio allocation between Long/Short longAllocation = 0.7 shortAllocation = 0.3 marginBuffer = 0.1 # Long allocations for symbol in self.long: self.SetHoldings(symbol, (longAllocation - marginBuffer/2) / self.numLongs ) # Short allocations for symbol in self.short: self.SetHoldings(symbol, - (shortAllocation - marginBuffer/2) / numShorts )
Â
Ehsan B
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!