Options strategy: how to buy a call prior to expiration?
Author: CarmaAdvisory
Creation Date: 5/31/2017 6:50 AM
profile picture

CarmaAdvisory

#1
Hi everybody, I would need help for coding an option strategy. I would want to create a strategy that, when a specific condition is satisfied, buy a call with at least 7 day to expiration with a strike price that is x% below the underlying previous close.

I tried using CreateSyntheticOption with poor results...

Thanks
profile picture

Eugene

#2
Please raise questions related to WealthSignals under that category. This is a WealthScript question.

Have you thoroughly reviewed search results for "option" that might be like these threads (containing a lot of quality code examples):

WL 6.9: Synthetic Options Contract Reference
Backtesting historic predictions of optionable stocks
How to code "nearest term ATM call option"?

Then, how do your results look like or what presents difficulty?
profile picture

CarmaAdvisory

#3
Thank you Eugene, actually very high quality code example even if not easy for my poor coding skills...

Trying to create a call option with at least 7 days to exp and with a strike price 3% below previos close:
CODE:
Please log in to see this code.


I get the error message CS1502: The best overloaded method match for WealthLab.WealthScript.CreateSyntheticOption(int,int,int,bool) has some invalid arguments

I realized that the third argument (0.97*Close[bar]) is the problem. In addition could you please explain me the meaning of the first argument (DateTime startDate)?

Thank you
profile picture

Eugene

#4
QUOTE:
I realized that the third argument (0.97*Close[bar]) is the problem.

No, it's more than this argument. As you could see in the QuickRef, CreateSyntheticOption can be called like this:
CODE:
Please log in to see this code.

You're trying to mix both worlds which won't work out. There is no way to have both atLeastXDaysTilExpiration and strikePrice because it's not programmed to be used like that.

For backtesting, the correct way would be to use some extra methods like DateTimeToBar and NextOptionExpiryDate and some functions available only in Community Components:
CODE:
Please log in to see this code.


So for backtesting this should suffice:
CODE:
Please log in to see this code.


Problem is, you cannot use this for live trading because NextOptionExpiryDate returns -1 for dates beyond the right edge. If you're willing to drop the "strike price 3% below previous close" requirement, your task becomes very simple -- just use the overloaded call:

CODE:
Please log in to see this code.
profile picture

CarmaAdvisory

#5
Great! Thank you very much Eurgene! I have a lot of test to do now ;)
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).