LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
Hello! I am new at this (though I have experience with both C# and financial markets) and I'm having trouble getting this backtest to trigger an order. The code compiles fine (it's based on a couple of the example backtests), but I suspect that I've made some incorrect assumptions about how the API works. (Also, I'm a bit worried the code is a mess, because of incorrect assumptions...)
Can somebody please take a look at the code and tell me how to fix it? The algorithm is pretty simple: if GOOG goes down by 2.5% to 12.5% (say) in a day, buy a call contract. If I own calls, and they're worth more than 30% than I paid for them (total, including transaction costs), I liquidate.
For some reason, though, I can't get the order to trigger.
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.
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.
This is a good start but there are a few points to update. I'm working on an algorithm for this and will post shortly
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.
OK Ive made a few modifications to your algorithm. I'll explain a few of them here but if you have more questions feel free to ask.
First I tracked the "dip" differently. Rather than using ROC, I set up a manual tracker based on a daily high. I'm sure this could be consolidated a bit but personally I like the control this gives you. There is a new constant "NUM_DAYS" that lets you control what time window you want to look in for dips.
Second, You didn't actually have the option chain set up to scal. You'll notice a new option.setFilter call added to initialize. This sets up option tracking on the underlying.
Third, the exit criterion on a "win" wasn't currectly based on the option price. I modified it to do this.
You'll also see I added some extra charting and logging, this isn't necessary but can be useful as you dissect this a bit to see whats going on.
Also there currenly isn't any logic that creates a "stop loss" inthe case where you are long a call and want to exit if the call value drops. It will currently hold until expiration.
1
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.
Alexander Solla
59
,
That's very cool, thank you. I ended up building a "buy the dip" strategy for stocks, which I cloned and tried to turn into an option strategy (of the same sort as my original post and your response). I realized I just don't know how to set up the option or get the option out of my Portfolio. Your example is really really helpful!
Just one note on indicators. In the original algorithm, RateOfChange was defined by the helper method ROC in the OnData event handler. It would rewrite the indicator on every OnData call, so it wouldn't return the desired values. Please move it into Initialize method:
private RateOfChange _rocIndicator;
public override void Initialize()
{
/* Algorithm setup methods */
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.
Alexander Solla
59
,
I'm still kind of working on this, trying to merge your algorithm with mine. I was able to get the order to trigger, but somehow, I lost it when moving to daily resolution. Is it possible to do options backtesting with a daily resolution? I'd like to do longer time periods, but it's (understandably) too slow with minute resolution. I'm really just looking for a historical estimate of the probability of winning and losing "the bet".
Currently we don't have hourly/daily options data but we're working on it! :)
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.
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...
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!
You do not have enough QC Credit to send this award, get a QC Credit Pack
here.
Award Sent Successfully
Thank you for giving back to the community.
Processing...
Choose a Credit Pack
Payment Confirmation
QuantConnect Credit (QCC) can be applied to your cloud-invoices or
gifted to others in the community with Community Awards in recognition of their contributions.
Community Awards highlight the awesome work your fellow community members are doing and inspires
high quality algorithm contributions to the community. Select an option below to add
QuantConnect Credit to your account:
$5
500 Credit Points
 
$10
1,000 Credit Points
 
$18
2,000 Credit Points
10% bonus
$45
5,000 Credit Points
10% bonus
03/23XXXX XXXX XXXX 0592
We will charge your default organization credit card on file, click
here to update.