Hi,
I feel somewhat sorry for asking as I'm a true novice at this and yet I'm attempting something difficult here.
I am trying to build an algo that does the following:
- Determine the current price of 2 equities (SPXL en SPXS)
- Use these prices to determine the needed amount of options of both to buy for the portfolio (in a 2:1 ratio)
- Buy Put options on both and sell calls on both
This should end up with a portfolio with a 67% synthetic short in SPXS and 33% in SPXL.
It should rebalance the options whenever the total weigth in the synthetic short positions surpasses 10% from the weight (so <23 or >43% in position 1).
I keep getting errors with my code. I'm trying to use the code from the tutorial on getting equity prices (in order to determine # of contracts), but this uses the onData (self data) instead of the onData (self slice) used by the sample option algorithms.
Could you please help me?
Much appreciated!
Igor
However, I keep hitting roadblocks.
Halldor Andersen
def OnData(self, data): # Rebalance portfolio daily for symbol in self.tickers: if symbol=="SPXS": self.SetHoldings(symbol,-2/3) else: self.SetHoldings(symbol,-1/3)
I've attached a backtest where I demonstrate the above.
Apollos Hill
You didn't ask but this is a community and I would like to weigh in on the fundamentals of your trading strategy. You will have extremely high negative delta if you by 2 puts and sell 2 calls. You could have like 100-200 delta. Would you not rather by 3 puts. 1 with 60 day expiration and 2 with 30 day expiration? I am using a similar strategy now. I don't go by the contract though because its almost impossible to allocate the exact number you picked of 67% of buying power to an option contract. Because the contracts are a fixed price. Unlike forex where i can do strange percentages like 3.61 of my account buying EURJPY. So since febuary i have been like 75 Delta on the SPXS and 25 Delta on the SPXL. Hedging like this isn't working out too well. so i actually sold my spxl put today and used the money to by more spxs.
Igor Quint
Halldor Andersen
@Halldor , thank you for you answer!
However, there is some issue with balancing between the equities themselves. Leveraged ETFs tend to have very high fees for shorting them. This will in practice deteriorate most profit. Therefore I'm trying to find a way doing this with synthetic short stock (selling atm call and buying atm put). Although you pay cost of carry, this may be lower than the shorting fee and you fix the amount paid. I suspect running this strategy with the options the furthest away may obtain good results.
I can definitely use the Setholdings() function for rebalancing, thanks for that. Do you also know how I can combine the slice and data arguments in the onData function? to determine the number of option contracts I need to get the price info first which requires the onData(self, data) function..
Igor Quint
@ Apollos Hill
Thanks for your suggestion! The rebalancing due to the contract size shouldn't be too much of an issue for now as I want to confirm the expected results through backtesting first (with like a 100k portfolio so I can get reasonably close to 33:67). Using 33:67 short on both SPXL and SPXS, you gain a net exposure of 1x to the underlying S&P. Through the effects of leverage decay/beta slippage, I expect the strategy to perform better than the S&P itself, however, through traditional shorting, the edge is mostly eaten away by the borrowing fee for those shares. I hope to circumvent some of that through options. Buying puts only will leave the portfolio exposed to significant vega as well, I hope to surpass that by selling calls as well, essentially hedging my put long vol exposure.
By you example, did you mean you own puts on SPXS summing to -75 delta? (And -25 for SPXL puts?) That would definitely be similar to what I'm trying to do (except for not selling calls).
Apollos Hill
Hi yes right now I have 3 July 2019 puts for spxs. To me there is no point in selling calls against spxl. Can you explain the beta and leverage deviation that would make selling calls attractive? Delta is delta and they are inverse so selling a call on spxl = buying a put on spxs. Except when long a put the profit is unlimited but selling calls Caps profits and provides unlimited risk.
Igor Quint
Apollos Hill
The point I want to make is to sell calls on both SPXS and SPXL and be long puts on both as well. Reason is that both ETFs are toxic in the long run and lose money, but you do not want any vega exposure on a short position. By selling calls you hedge the vol exposure.
Leverage deviation is best explained as this: If SPXL and SPXS provide 3x and -3x returns respectively on the SP500, and the underlying moves like this day1 :+25%, -20% day2, $1 invested in the S&P would still be $1 after those moves. With SPXL you would have 3x the return so +75% on day1 and -60% day 2, resulting in a portfolio of 0.7, a loss of 0.3 due to compounding leverage. Also, for the SPXS you would be left with only 0.4 on the last day.
Of course this is an extreme example, but you get the point. Especially in high volatile environments, the Leveraged etfs drop in value quickly.
Matt Loftin
Thank you both for this discussion. I have been mentally barking up this tree as I learn, and you both clarified a lot for me. Any Progress since? Any thought to adding a third etf that was more stable to pull some off the value if both SPXL and SXPS are toxic over the long run? Again, I am very new ot all of this and just tryign to learn. Thank you both.
Igor Quint
Hi Matt,
Adding a third ETF isn't strictly the goal of what I was trying to achieve. You are right in that SPXL and SPXS are toxic in the long run. The goal of the double synthetic short is to scrape this value of both ETFs while maintaining a net exposure of 1 to the S&P500. Basically this strategy is able to outperform the SPY etf. One of the main roadblocks consists of the shorting fee you have to pay to short these ETFs outright. Using options you can essentially try to replicate this position without having to pay shorting fees. Unfortunately my skills in working with options on the Quantconnect platform are limited. I have proven in my thesis that the ETF strategy is viable when discarding the shorting fee. If one is able to build the option strategy around it...
Apollos Hill
hI Igor Quint What is the shorting fee amount? I don't know what the shorting fee is for any of the brokers. I tried this with options. I think it would only work if you bought a dozen of weekly SPXS SPXL PUTS. you should try it out manually. It should be pretty easy to do. Let us know how it goes.
Igor Quint
Hi Apollos Hill , the shorting fee varies per day. Using Interactive brokers I crecorded the lending fees/shorting fees on a given day lasy year, see the table underneath.
As the fee is pretty significant, using options can give you a discount when trading the strategy as described by Jiang and Peterburgsky in their 2017 paper. I do find it hard to trade this manually though, as the amount of options required to accurately mimick the S&P (shorting 2/3 SPXS and 1/3 SPXL) is relatively high which implicates you need a high account balance. For the theoretical exercise though, I still would like to see a python program to run this in Quantconnect..
Symbol Sec. lending fee
SPXL 3.77%
SPXS 4.79%
SSO 0.59%
SDS 1.40%
SPY 0.33%
Josh M
Igor Quint if you close before market close do you get charged interest still?
Igor Quint
Hi Josh M , That's a very good question. Didn't know this myself, but apparently it depends. If stock is hard to borrow, some fee might be incurred, but otherwise no shorting fee will be charged if closed before current day's closing time.
(source: https://www.elitetrader.com/et/threads/what-is-the-cost-to-day-trade-short-sell-a-stock.281871/)
So if that's the case, the original strategy can be executed with only day trades. That would increase the transaction costs, but on a large enough portfolio that shouldn't be a problem. Only thing is, you miss out on opening gains/losses.
Igor Quint
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!