I created a strategy to sell SPXW DTE 0 call or put at delta 0.01 at price > 0.999 spx day high or price < 1.001 spx day low.
Sharpe ratio is super high but return is bad < 2.5% annual return.
Any suggestion on how to improve return to more than 15% but sharpe ratio still above 3? Maybe i should sell spread instead?
Yuri Lopukhov
Returns are low because you only trade 1 contract. This code assigns 5% of balance, which is still too much I guess, DD is 65%, but Sharpe is way above 3 ;)
I would strongly recommend testing on larger time period though.
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.
Yuri Lopukhov
Actually, I shouldn't have changed
to
to cancel the deprecation message. Because this is called for both SPX and each SPXW contract. Not sure how the deprecated version is called though, need to check this.
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.
Thomas
Thank you so much Yuri.
I think we should use schedule on . OnEndofDay trigger actions at 15:50 everyday (it took a newbie like me half a day to figure out :( .
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.
Thomas
Thank you also for the suggestion Yuri , DD is 65% on Jan 23 is not fun .. open at 183k and low at 63k :)) ,,, I wonder what would happen during covid . Will run the backtest tomorrow
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.
Yuri Lopukhov
Yes, it is better to just use self.Schedule.On() if you know exact time. You should also add symbol in self.DateRules.EveryDay() as a parameter to skip non-trading days for that symbol. But this is optional, in your case OnData simply won't run when the market is off anyway.
You can play with position size, of course, to get the risk/reward ratio that suits you.
Other possible option would be to add risk management models (https://www.quantconnect.com/docs/v2/writing-algorithms/algorithm-framework/risk-management/supported-models):
or just use stop/limit orders to reduce slippage (https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types).
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.
Non Compete INVESTOR
note https://github.com/QuantConnect/Lean/blob/master/Algorithm.Framework/Risk/MaximumDrawdownPercentPerSecurity.py
uses negative unrealized profit, so i dont think it takes profit, just protects from losses. I created this issue but maybe i missed something.
https://github.com/QuantConnect/Lean/issues/6841
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.
Yuri Lopukhov
Yes, I just misplaced comments to MaximumDrawdownPercentPerSecurity (stop loss) and MaximumUnrealizedProfitPercentPerSecurity (take profit).
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.
Thomas
Not a very good idea to run an option selling strategy with stop loss.
Option price is much more volatile than stock and when index is down , the downtrend on option price is much more significant than when index is up.
I won't recommend at all. See code and result below
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.
Thomas
Also would u know if Quantconnect support option price for the last 3trading days? The algo didn't show anything whne I backtested on 15 , 16, 17 Feb
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.
Thomas
in addition even without the stop loss/take profit the algo suggests selling >60 contracts of SPX :))
In reality that would require a >$1million account with > $10million buying power . This is not executable.
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.
Thomas
In addition , Yuri & Non-compete , may i know if you know of a simple function to take a day high / day low?
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.
Yuri Lopukhov
There is no simple function for that AFAIK, you can do it the way it was done in this algo, or use Identity indicator with High or Low fields.
So you mean QuantConnect is not calculating required buying power correctly here?
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.
Yuri Lopukhov
it usually takes couple of days before real-time data becomes available for backtesting.
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.
Yuri Lopukhov
sorry, Identity won't work here, you can use self.MAX, self.MIN indicators like this:
and in the beginning of each day call self.max.Reset() / self.min.Reset().
Or use and update Maximum()/Minimum() indicators manually in OnData().
Either way is hardly easier.
There is actually a feature request of this functionality on github here:
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.
Thomas
Thank you very much Yuri.. I decided to use min/max & modify the code to selling spread to control the risk. However the risk is still quite significant . Stoploss doesn't work in the case of options due to super high volatility of the option price.
Still - I risk loosing like 15k on an account of 50k. The probability is low <3% but still… not for those with the fainted heart. Below shows the testing from 3 Jan , if i tested on Dec 22 data, it will result in significant loss.
And regarding your question Yuri, Yes I think quantconnect did not calculate the buying power correctly. Because a IBRK would require a buying power of 80k for selling an spx put/call naked . Meaning that for an account size of 100k i can sell max 1 contract but in the algorithm it allow me to sell 60 contracts !
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.
Thomas
To illustrate my point please see the below backtest, on 12 Dec 2022, market was relatively calm still 14:30. Form 14:30 to 16:00 market jumped more than 30 points resulting in 10% loss to the portfolio. The algo will then take approximately 3months to recover
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.
Yuri Lopukhov
hmm, I guess it can work like this too, but this does not look optimal. I think you can just replace this code with
to reset previous day values.
Thank you for clarifying options margin requirements for me, I am not experienced with options. I hope QC eventually will handle these nuances properly, because currently it shows very little exposure and drawdown, even with positions for hundreds of contracts.
If probability of crash is very low, perhaps it makes sense to extract your profit from trading account regularly and just accept the fact that someday you can lose your trading balance? If this happens, you will keep the profit and can restart. Because if you keep your trading balance low to prevent crashing it, profits are also going to be low. Just maybe something to consider.
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.
David E
One thing with this algo is you're selling like 1000 options at a time. The margin required for that would make this algo not workable. You could only sell like 1% of what you're actually selling.
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.
David E
Yeah I just pulled it up to manually put in a trad eto calculate the margin required. To sell 1 contract requires $58k in margin. So you'll make 0.30 on 58k of used margin and there is no way you can sell the amount on contracts the algo is trying to sell. In fact, on the clone of that last post, the starting amount of $50k, you cant sell even 1 contract with that.
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.
David E
maybe try this on SPY instead? You can sell a contract on SPY for 1/10th the required margin.
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.
Thomas
Very nice code Yuri. Thank you so much for sharing .
A few points
60 contracts mean initial margin of ~50k USD on IBKR. You account size should be at min 60k USD.
Delta 0.01 means that there is 1% chance of assignment when u open your position (if you got assigned at SPY put strike 400, $2.4millon cash will be deducted from your account for 6,000 shares of SPY).
I would argue that 7% annual return is not worth the risk
2. Delta =0.01 is very illiquid. We may not get the trade fill and if it's filled it's not easy to get out. So need paper trade to understand if liquidity is an issue. In my experience it's super hard to fill 60 contracts for delta 0.01 or even 0.02 or 0.03
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.
Thomas
In my opinion , we need to decide when to run the algo. Some days when J.P speaks or CPI data are being released for examples are super volatile. Traders can take market in either up or down direction. We should avoid those days or weeks with those days. I did some analysis for the last 1 year- Days with big drawdown for the strategy are when fed releases the meeting minutes, CPI , jobless claims , JP speaks or days after CPI were release.
Traders need to make some judgement to run or not to run the strategy. For example this week we have FOMC minutes tomorrow, Initial jobless claims on thu. I think we need to avoid running the algo this week
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!