Click here to Login





                                                   Questions and Code to Share: Weekly Expected Move (IV)

  1

0
Josh McCormick
2020-11-14 16:46:02


Since mid-September, I've been using Caleb's Implied Volatility Data downloader which grabs the Historical and Implied Volatility (HV/IV) for various stocks and indicies (with new values published every Friday). I found use for a symbol's IV percentage when I converted it into an expected trading range for the subsequent week, and so now I've started plotting that information. Here's what it looks like for Wayfair (W):

SCREENSHOT:
===========
https://i.imgur.com/7bV7KIP.png

You'll want to focus on the thin green and red horizontal lines that are (usually) above and below the stock price. They're based off a week's worth of implied volatility and the closing price for that Friday. The value is held at that level until new Implied Volatility data has arrived (so you might want to automatically download the data to make sure you've got a steady feed).

When it comes time to plotting the values, I'm having two problems:

1. The vertical lines every Friday are meaningless and unwanted and I'd really like to get rid of them. Is there a way to do so? The only thing I could figure to do would be to have one set of functions drawing the odd weeks and one set of functions drawing the even weeks, and both functions changing their output color to transparent when it wasn't their week. But wow, that's a weird hoop to jump through! Might there be an easier or better way?

2. The horizontal alignment of these lines are off. They start mid-bar of the first week and continue through to the middle of the first bar of the following week. These plotted lines should be shifted a half of a bar to the left for them to make the most sense. (This is a problem I run into elsewhere from time-to time.) Any thoughts on how I can shift these lines to properly overlap only the days they cover?

Here's one of many websites which introduce the concept of Implied Volatility. It's an important part of options trading, but it also has uses in ordinary stock investing:
https://www.ally.com/do-it-right/investing/what-is-implied-volatility/

I'll leave it to others to explore how or why this information is of any use, but what I will share is the formula I used to derive and plot the data. As mentioned, it uses Caleb's Implied Volatility Downloader, and you're going to have to have some data collected before this'll plot anything interesting. If you give this code a try and come up with some enhancements or bug-fixes of your own, I'd greatly enjoy hearing from you! (Publicly or privately.)

"WEEKLY EXPECTED MOVE" FORMULA:
===============================
symbol_name=Name(); // This allows me to substitute in $NDX $SPX etc where needed.
iv=GetData("iv","iv",last,symbol_name);

ivbarsago=barssince (iv!=ref(iv,1)); // How many bars ago was our IV data? (expected weekly)
ivclose=ref(close,ivbarsago); // The current symbol's closing price on that day
ivrange=ivclose*ref(iv,ivbarsago)*0.01*Sqrt(7/365); // Weekly IV percentage, converted into chart handles (+/-)
// Might 6/365 have been more accurate? Or 5/251?
ivabove=ivclose+ivrange; // Highest expected weekly stock price based upon IV
ivbelow=ivclose-ivrange; // Lowest expected weekly stock price based upon IV

Plot (round(ivrange,2), "IV ".Round(ivbelow,2)." to ".Round(ivabove,2)."=", colorBlack, Chartnone,StyleOwnScale|StyleHideYAxisValue);
Plot (ivbelow, "IV-", colorRed, ChartStep, StyleHideYAxisValue|StyleHideValues);
Plot (ivabove, "IV+", colorGreen, ChartStep, StyleHideYAxisValue|StyleHideValues);





Implied Volatility Data (by Caleb, uploaded several months ago)
No notes

Rate an item Rate an item Rate an item Rate an item Rate an item Number of downloads Notes Report an item

Josh McCormick
2020-11-17 17:31:52

  0

Update!

It took some tap-dancing, but I've managed to rid the chart of those unwanted vertical lines. Also, I don't have mathematical proof, but experimentation leads me to believe that the range of the Expected Move is more accurate when Implied Volatility is scaled to a period of 5.5 days instead of 7 calendar days. If you disagree, change Sqrt(5.5/365) to your desired value such as Sqrt(7/365).

Finally, I've seen that the high and low values of the expected range also tend to act as support and resistance on the intraday chart too! I'll whip up some code for that later. I'm also curious to see if any action happens at well-known Fibonacci ratios of the expected move. Anyhow, enjoy!

I probably need to comb through this code another time or two in order to clear out some of the workarounds.

NEW! The blue Expected Move line turns a brighter AQUA on those dates where the Expected Move has been breached (above or below) by the actual price. Over the long term, every 32 out of 100 weeks should escape the predicted values.

UPDATED CODE FOR HISTORICAL CHART:
================================

// ----------------------------------------------------------------------------------------------------------------------
// IV (IMPLIED VOLATILITY) AND EM (EXPECTED MOVE)
//
// DEFAULTS TO: *68% probability* *one year from now* that the stock move will be less than or equal
// to the given number. Both the probability and the duration can be adjusted mathematically, but our
// code (below) only adjusts the duration. You probably want to leave it at a 68% probability so that
// you're using the same measuring stick as the rest of the market.
// INDICATES: How much the stock price is expected to move based on what is known & what is
// expected by the market. Unlike most indicators, this is forward-looking and takes into account
// things like dividends, earning announcements, etc.
// STOCK STRATEGIES: Setting stop levels. Comparing forward-looking risk/volatility between two securities.
// OPTION STRATEGIES: Iron Condors outside EM, Vertical Spreads outside EM, Butterflies on the EM edge
// NOTE: Estimates the MAGNITUDE of change. Not DIRECTION of change.
// ----------------------------------------------------------------------------------------------------------------------

symbol_name=Name(); // This allows me to substitute in $NDX $SPX etc where needed.

iv=GetData("iv","iv",last,symbol_name);

ivbarsago=barssince (iv!=ref(iv,1)); // How many bars ago was our (expected weekly) IV data?
ivbarsago=iff(ivbarsago==0,5,ivbarsago);
ivclose=ref(close,ivbarsago); // The closing price on that day
ivrange=ivclose*NanToZero(ref(iv,ivbarsago),1)*0.01*Sqrt(5.5/365); // Weekly IV percentage as handles (+/-)

// There is a 68% probability that the price will move less than or equal to the predicted range.
// You can adjust the probability (confidence interval) by multiplying the ivrange as follows:
//
// 1.00x = 68.27% 1.645x = 90.0% 1.96x = 95.00% 2.0x = 95.45%
// 2.33x = 98.00% 2.58x = 99.0% 3.00x = 99.73% 4.0x = 99.99% 5.0x = 99.999%

// If this data is old, set it to the closing price so that we can hide it.
ivabove=ivclose+ivrange; // Highest expected weekly stock price based upon IV
ivbelow=ivclose-ivrange; // Lowest expected weekly stock price based upon IV
ivbarsago=iff(ivbarsago==5,0,ivbarsago); // A quick hack for the following code.

Plot (Round(ivabove,2),"EM-:".Round(ivbelow,2)." EM+",colorBlack,Chartnone,StyleOwnScale|StyleHideYAxisValue|StyleHideValuesNan);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim title bar data (cannot hide)
Plot (round(ivrange,2),"EM",colorBlack,Chartnone,StyleOwnScale|StyleHideYAxisValue|StyleHideValuesNan);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim old title bar data (cannot hide)
Plot (Ref(iv,1),"IV %",colorBlack,Chartnone,StyleOwnScale|StyleHideYAxisValue);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim old title bar data (cannot hide)

Plot (iff(ivbarsago==0,ref(ivabove,1),ivabove),"EM+",ColorBlack,ChartStep,StyleHideYAxisValue|StyleHideValues|StyleBringToFront);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars
Plot (iff(ivbarsago==0,ref(ivbelow,1),ivbelow),"EM-",ColorBlack,ChartStep,StyleHideYAxisValue|StyleHideValues|StyleBringToFront);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars

Plot (iff(ivbarsago==0,ref(ivabove,1),ivabove),"EM+",ColorBlue,ChartStep,StyleHideYAxisValue|StyleHideValues|StyleDotted|StyleWidth4|StyleBringToFront);
UpdateColor (high>ivabove,ColorAqua);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars
Plot (iff(ivbarsago==0,ref(ivbelow,1),ivbelow),"EM-",ColorBlue,ChartStep,StyleHideYAxisValue|StyleHideValues|StyleDotted|StyleWidth4|StyleBringToFront);
UpdateColor (low<ivbelow,ColorAqua);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Chart Patterns: Double Top and Double Bottom
Forex Trading Indicator - Better than expected Economic Calendar ...
Historical Earnings Surprise, EPS and Consensus Data
US Crude Oil Supply, Consumption, and Inventories
TSP Sentiment Survey - Percentage of Bullish and Bearish Traders

How-to Lessons
How to scale and move the chart Y-axis
How to copy and paste drawing tools
How to plot support and resistance lines automatically
How to create trading rules based on Put and Call volume data
How to create and trade a Neural Network model

Related Forum Threads
Newby's questions -symbol lists, code etc. ...
drawing objects in log mode in daily and weekly charts
AMM scripting - error and some questions
Backup and move entire QS to new computer
First time here. Questions about Excel and Quantshare

Blog Posts
Trend Following and Moving Averages
Custom Shortcuts - Move a Chart to Display the Last Quotes/Data
Forecast volatility using trading rules and neural networks
3 ways to rank stocks in a trading system - Simulator and Potfoli...
Different periodicities and chart bar types in QuantShare Trading...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.