Backtesting historic predictions of optionable stocks
Author: tedpenner
Creation Date: 12/13/2016 9:48 PM
profile picture

tedpenner

#1
It seems many people make predictions about a bucket of stocks that they think will perform well over "the next year".

I'm looking for such a list from a reputable firm for the "previous year"

I'm looking to backtest a married put strategy on any optionable stocks that might be in that list.

Assistance in locating a list like this for the prior year is greatly appreciated.
profile picture

Eugene

#2
Usually if a firm (analyst) upgrades a stock to Strong Buy, this should qualify as prediction. So how about simply using the Analyst Ratings provider (part of MS123 Extra Fundamental/News Providers) on a large DataSet?

P.S. While I'm not suggesting this, motivated users with strong coding skills may even analyze stock predictions as they happen at StockTwits API (and optionally using Alchemy API for semantic analysis).
profile picture

tedpenner

#3
Very interesting!


I'm mostly looking for a way to test an automated married put strategy on a list of optionables for the prior year.
profile picture

Cone

#4
I know what a married put is, but what exactly is the strategy for it? In others,

When do you buy the put(s)?
Which strike(s) do you buy?
Do you always hold the put to expiration?
Rollover?

When writing code for a strategy, the requirements must be specific. Please start a new thread in the "Trading Strategies" forum and name it "Married Put Strategy". Specify the requirements and I'll help you get this done.
profile picture

tedpenner

#5
On a prediction of long-term gains.

Buy the underlying stock.
Buy the ITM put "leap option" max time out.
Adjust to next strike by selling the lower strike, and buying the higher strike further out when possible.
Keep going till all the risk has been removed from the position and beyond.

Once all risk has been removed, and there are profits, and zacks.com or similar firm has downgraded it from "strong buy", then exit the position with a profit and pick a stronger buy.
profile picture

sedelstein

#6
Why buy the stock and a put? Why not just buy a call instead? Fewer commissions, equivalent position (Put-Call parity) and you haven't committed the capital to the stock purchase and can use that to be able to have many more positions
profile picture

Eugene

#7
Good question.
profile picture

Cone

#8
Besides sedelstein's good point, your rules are not specific enough to code. How do we identify the leap option and its max time out? Adjust.. when possible? it's always possible! When is risk "removed"?

Selling on a downgrade from "strong buy" with a profit is a specific rule, but what do you do if no firms have a strong buy AND the position is underwater? (You'll never be able to sell it)
profile picture

tedpenner

#9
I'm not sure how to upload an in-line image here so in lieu of that here goes.

Cone, Thank you!

How do we identify the leap option and its max time out?
This platform shows this concept the best. Notice in this screenshot where the position is right now, and also notice that currently, the 18th of Jan 2019 is as far 'out' as we can go



This is an example of where I would have preferred not to have to accomplish this manually

Adjust.. when possible? it's always possible! I would agree with this.

When is risk "removed"? Each time the price of the underlying moves up to the next strike price.

Selling on a downgrade from "strong buy" with a profit is a specific rule,

What do you do if no firms have a strong buy AND the position is underwater? (You'll never be able to sell it).
Correct, hence the purpose of buying leap options as far out as you can.

Sedelstein, Thank you!

Why buy the stock and a put? Why not just buy a call instead? Because buying a call is equal to 100% risk, where buying the stock and the put limits the overall risk to between about 7-20%. It is a long-term play, for long-term assets. This is not a short-term or swing trade.

Fewer commissions, equivalent position (Put-Call parity) and you haven't committed the capital to the stock purchase and can use that to be able to have many more positions. True
profile picture

sedelstein

#10
Buying a stock and a put is mathematically equivalent to buying a call.. If you want to lose only between 7 and 20%, just put 7 to 20% of your money into the call.
profile picture

Eugene

#11
Steve, I don't pretend that I understand options but what about rollover costs/timing with a "long-term play" in mind?
profile picture

sedelstein

#12
Hi Eugene

Isn't the strategy rolling puts as the stock moves as well?
Tying up the capital in the long stock and puts has it's costs too.
profile picture

Eugene

#13
Agreed. If the long stock's ROI is less than such of a CD or index, what's the point in holding it (unless you anticipate a breakout play or follow insider buying in it, for example, in a diversified portfolio).
profile picture

Cone

#14
Stocks may pay dividends. Yield on S&P 500 companies isn't great, but it's about 2%. On a $10K investment that $200/year probably more than pays rollover costs.

I don't have much to go on here, but I'll come up with something for the sake of argument. I can already see that buying stock and options in the same strategy is going to require the SetShareSize option in order to probably control sizing for two different instruments.
profile picture

sedelstein

#15
Fwiw, options are priced w/ dividends factored in. Otherwise, there would be an arbitrage opportunity.
profile picture

Cone

#16
Good point! :)
profile picture

Cone

#17
Here's something to go on...
It's interesting to click between UseLeaps 0/1 (to turn on and off using the puts).. Generally speaking using the puts reduce profit in my tests using the default parameters.

Set up:
1. Update your WLP fundamental data with "Fidelity Analyst Ratings" selected.
2. Data Range: 5 Years (analyst ratings don't go back further)
3. Position Size: Override in Script
4. Copy and compile the Strategy
5. Set up your parameters.
a. $ Size (Stock): Must be large enough to buy at least 100 shares (a round lot)
b. Use Leaps=1: Set to 0 to for the results without buying options.
c. Round option: Multiple of the option price
d. Avg R (Rating) Buy/Sell: 1=Buy, 5=Sell. Choose an average number between 1 and 5.
e. Last n Ratings: Number of most-recent ratings to obtain the average rating. I don't recommend a number below 5.


Entry Rules:
Buy a round lot (n x 100 shares) when the average analyst rating drops equal or lower than the Avg R Buy parameter. If options are enabled, buy a leap put (1 year from next option expiry).

Exit Rules:
1. Sell stock and option when the average rating rises equal or higher than the Avg R Sell parameter.
2. Roll the option if a) put has lost more than 50% of its value, or, b) within 4 months of expiry date.

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

Eugene

#18
Robert, that's some nice code. One question: are you sure that this can't get out of bounds on the last bar?
CODE:
Please log in to see this code.
profile picture

tedpenner

#19
Very nice!

Using At-The-Money options should be assumed for this strategy.

Q re exit rule: Sell stock and option when the average rating rises equal or higher than the Avg R Sell parameter.
[AND there is profit in the overall position, otherwise don't until option is about to expire. We are giving it time and accepting the risk that it won't move in our direction within the time frame of the leap option which I think is about 2.8 years but we need a way to determine both "at-the-money" and "max time out"].

Q re exit rule: Roll the option if a) put has lost more than 50% of its value
[I don't think I agree with this],
or, b) within 4 months of expiry date
[I'm not sure I agree with this either].
profile picture

Cone

#20
Thanks Eugene, I edited.

QUOTE:
I don't think I agree
Without definitive rules to code to manage positions in both the stock and options, you get my rules. ;)

I did miss your rule about rolling every time you move to the next strike. The problem is knowing what is the next strike is for any given underlying? It could be every $0.50, $1, $2, $2.50, or $5 (or others). This would create a lot more positions, but it's worth a try for next time.
profile picture

tedpenner

#21
Thank you for the assistance Cone.

ATM (at-the-money) can be derived from the delta.
A delta of .5 or -.5 is the strike price at which the option is likely to be the least affected by other the Greeks http://www.optionmonster.com/education/option_greeks.php (theta, vega, gamma, and rho).
A call is at-the-money when it is equal to or closer to a delta of .5 than any other strike price in the option chain for that month.
A put is at-the-money when it is equal to or closer to a delta of -.5 than any other strike price in the chain for that month.

nearestMo option vs furthestMo option:
How do you define nearest monthly option?
How do you define furthest out monthly option (a leap option)?
profile picture

Cone

#22
We are creating synthetic contracts here. We can create any strike that we want. For example, we can make a 115.125 strike for AAPL, even though that doesn't really exist. Anyway, the rounding parameter controls the strike. If you set to "1", then you get a strike for every even dollar. If you set it to "5", then every 5 dollars. Sure, the code is buying ATM puts - this is no mystery because you can see it in the code - GetLeapData() method.

QUOTE:
How do you define nearest monthly option?

The WealthScript NextOptionExpiryDate() method returns the date of the next expiry after the date of the bar passed to it.


QUOTE:
How do you define furthest out monthly option (a leap option)?

The method GetLeapData() has a "monthsOut" parameter. If you pass 12, then you get the expiry 12 months after the nearest expiry. You can modify the code to pass any integer number you want.

Here's "Version 2" with the following changes:
Exit Rules:
1. Sell stock and option when the average rating rises equal or higher than the Avg R Sell parameter (no change).
2. Roll the option if a) stock closes above next strike (determined by Round option parameter), or, b) within 1 month of expiry date.

I'd recommend putting the Round parameter at 5 to avoid trading options too frequently.

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

tedpenner

#23
Ok, thank you again.

So from what I understand, I can specify the number of months out with the monthsOut option parameter as well as the distance between the strikes with the round option parameter.

I'm a little confused on the need to use synthetic option data as opposed to real data. Is there any way to get the choice?

What if we were to trade the strategy with IB or using some other tool?

How can we get closer to real data?
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).