Back

Can't trigger order

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.

Update Backtest








Oops, here's the backtest.

0


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.


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!

0

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 */

var equity = AddEquity("GOOG");
_rocIndicator = ROC(equity.Symbol, 1, Resolution.Daily );
}

 

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.


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".

 

0


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.


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