A Better Implied Volatility Rank and Percentile Indicator
10/18/2019 at 11:21 AM #110480
Hi, I think this would be a very useful addition to the library and am wondering if it is possible to code an Implied Volatility Rank and Percentile Indicator that can be based on Williams’ Vix Fix? It would be particularly beneficial for Currency, Indices and Options traders but can be applied to most markets.
The PRC version of the indicator was posted here: https://www.prorealcode.com/topic/indicator-request-for-nic/
Can it also be programmed so that it can find tops as well as bottoms, — i.e. instead of just having a fear barometer when Put Premiums are rising sharply, also have a greed barometer for Call Premium rises and potential market tops)? I was hoping we could have an indicator like this one I found on Trading View (linked below) so it shows not just the IV rank but also the Percentile (so it’s scaled by 100%)? Unfortunately the code is locked on Trading View but I am hoping it isn’t too far of the version I linked to above on PRC.
“This indicator is meant to be a substitute for Implied VIX , which charts the implied of the SPX . The great thing about the VixFix is that it can be applied to any security, not just the SPX .Rank and Percentile for traders who do not have access to readily available options data. This indicator is based on the William’s VixFix which is an indicator that mirrors the
IV Rank is calculated by taking the highest and lowest values over the past however many periods you choose, and seeing what percentage of the way between those values the current IV value is. For example if over the past 5 periods the highest IV value was 30 and the lowest IV value was 10, and the current is 20; then the IV Rank would be 50% because 20 is 50% of the way between 10 & 30.
IV Percentile is calculated by looking at all of the past values, not just the highest and lowest, and seeing how many of those values were below the current. (IVP tells you the percentage of time that the IV in the past has been lower than current IV). For example lets say over the past five periods the IV values were : 30,10,11,15, & 17; while the current IV value is 20. As stated before the IV Rank would be 50%, while the IV Percentile would be 80%, given that 4/5 of the values were below the current IV value of 20.
IV Rank and IV Percentile are often wrongly used interchangeably, but as shown here they are very different. Most people use IV Rank as their main options tool; while IV percentile is a great way to give IV Rank context. Whichever you choose to use, or even both, does not really matter as long as you use either one or both consistently.
IV Rank and IV Percentile are mainly used in this way: when IVR/IVP <50, buy options, when IVR/IVP >50 sell options. The reason that you buy options when IVR/IVP is low is because IV is mean reverting, so you would expect IV to eventually start increasing towards the mean, causing prices to move. The reason you would sell options when IVR/IVP is high is because IV is mean reverting and you would expect IV to decrease towards the mean, causing prices to move sideways.
In this script there are two lines, one denoting IVR and one denoting IVP . IVR is the line which is green when it’s above 50 and red when below 50. IVP is the line which is aqua when above 50 and orange when below 50.“
Also, I was wondering why “pl” is set at 1.01 instead of 0.15 and I also do not get the green histogram bars (mine are all grey despite color code within indicator) on the ProRealCode version mentioned above?
Thanks very much,
Cheers Bard.10/18/2019 at 11:49 AM #11048210/18/2019 at 12:35 PM #110489
Try this. I think I understood the description correctly. If you can confirm that it is as expected then I might submit it to the library.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647//Implied Volatility Rank and Percentile Indicator//By Vonasi//Date 20191018//settingsp = 200vixfixperiod = 22//Vix Fixwvf = ((highest[vixfixperiod](close)-low)/(highest[vixfixperiod](close)))*100//Boundariesupper = highest[p](wvf)lower = lowest[p](wvf)wvflev = ((wvf-lower)/(upper-lower))*100//PercentilernkCount = 0count = 0FOR i = 1 to p-1count = count + 1IF wvflev[i] < wvflev THENrnkCount = rnkCount + 1endifNEXTPercentileRank = (rnkCount/count)*100//coloursr = 128g = 0if wvflev >=50 thenr= 0g = 128endifr1 = 255g1 = 140b1 = 0if PercentileRank >=50 thenr1 = 0g1 = 255b1 = 255endifRETURN 0 as "0%",100 as "100%",50 as "50%",wvflev coloured(r,g,0) as "Williams Vix Fix", PercentileRank coloured(r1,g1,b1) as "Percentile Rank"
10/18/2019 at 12:43 PM #110493
IV Rank and IV Percentile are mainly used in this way: when IVR/IVP <50, buy options, when IVR/IVP >50 sell options
I think you might have this the wrong way round. Unless I have coded it back to front (which I don’t think I have) the opposite seems to be true when I look at a chart.10/18/2019 at 3:33 PM #110512
Wow, thanks very much, that was quick @vonasi!
The indicator signals may be poor but it is referring to whether you’re a buyer or seller (writer) of Puts and Calls. It maybe that using a 50% mean value IVR/IVP ratio and expecting meaningful signals maybe naive given the way option premiums can explode and remain high for extended periods of time. (Pls refer to £/$ weekly Call options that have increased by 100’s of percent and remained high since the 11th October due to a possible Brexit deal).
When IVR / IVP < 50, buy call or put options (because premiums are cheap and should rise to the mean value). When IVR / IVP > 50 sell (write) call or put options (because premiums are expensive and should reduce so you can buy them back cheap and close the position for a profit).
I’ve been reading more on this! Is this best way to make a IVR / IVP Indicator? The PRC Vix Fix green spike barchart is very clear. Are the substitute formulas to approximate for Implied Volatility (which predicts an assets expected future movement) and Historical Volatility good enough though?
The Vix represents future 30 day Implied Volatility for the S&P 500. Larry Williams’ I Really Trade website: https://www.ireallytrade.com/newsletters/VIXFix.pdf
explains how high readings = high volatility (good for option (short) sellers of Calls or Puts as premiums explode in value). Williams’ duplicates this implied volatility Vix index with his simple formula:Vix Fix1WVF = (Highest (Close,22) - Low)/(Highest(Close,22))*100
and the VIX and WFV chart indicators look pretty similar.
Obviously the only real way to work out IV is to back calculate it out of the Black Scholes (BS) option Pricing Model using an options calculator as it has to reference the strike price and underlying price and represents a 1 std deviation move on an annual basis. I see formulas on Trading View using 365 days and 252 days, the former makes more sense as the BS Model references the risk free interest rate — for example — annual Gilt or Treasury Bill Rates.
Examples of Implied Volatility Calculations:
US Crude Price = $66
Strike Price for a Put option = $63
Implied Volatility = 24.95% (annual)
Therefore there is a 68% chance of the price being +/- $16.46 within a year ($66 x 0.2495).
1 Std Dev – 68% probability of the oil closing between $49.54 and $82.46 a year from now
2 Std Dev – 95% probability of the oil closing between $33.08 and $98.92 a year from now
3 Std Dev – 99.7% probability of the oil closing between $16.62 and $115.38 a year from now
Percentages are derived from the BS Model:
Strikes with a probability of 16% being In the Money at expiration make them more likely to be profitable for a buyer of Calls and Puts) / 84% Out the Money at expiration make them more likely to be profitable for a buyer of Calls and Puts) and these percentages capture a 1 standard deviation range for an OTM option.
Strikes with a probability of 2.5% ITM / 97.5% OTM capture a 2 standard deviation range for an OTM option.
(Stock price) x (Annualised Implied Volatility) x (Square Root of [days to expiration / 365]) = 1 standard deviation.
Example of AAPL that is trading at $323.62. The current Implied Volatility is 31.6%.
JAN options expire in 22 days, that would indicate that standard deviation is: $323.62 x 31.6% x SQRT (22/365) = $25.11
That means that there is a 68% chance that AAPL will be between $298.51 and $348.73 in January expiration.
From Trading View: https://www.tradingview.com/script/lqwz92Fm-Historical-Volatility-Rank/Historical Volatility12345678910111213141516171819202122232425study(title="Historical Volatility Rank")Length = input(20, minval=1)annualVol = input(365, minval=1)Price = log(close / close)periods = iff(isintraday or isdaily, 1, 7)sigma = stdev(Price, Length)HVol = (sigma * sqrt(annualVol / periods)) * 100lowVol = lowest(HVol, 365)HVrankUp = HVol - lowVolmaxVol = highest(HVol, 365)HVrankLow = maxVol - lowVolHVR = HVrankUp / HVrankLowplot(HVR, color = blue)
Referring back to the original Vix Fix post: https://www.prorealcode.com/topic/indicator-request-for-nic/#post-110244
Imagine an indicator as good as the PRC green high Vix Fix Volatility spike bar but also with Low spikes included to spot extreme measures of greed (for Shorting) and then also with an IVR/IVP ratio threshold showing perhaps better extremes like 20%, (and the mean threshold of 50%) and 80%. Pls see images.
Do any of these “musings” help you any Vonasi !?
Ps/ Why could I not get the PRC Vix Fix code to show green extreme bars?10/18/2019 at 3:54 PM #11051710/18/2019 at 4:11 PM #110520
😄 It took me ages to write that, I thought this would be “childs’ play” for a skilled coder like yourself! Maybe you could find a dark room and lie down for a while!? 😂
Basically I think the IV and HV formulas could be improved (log) but it would, at least for now, be great to see the PRC Vix Fix green spike indicator bounded by 100% and with extreme Low Volatilities for market tops? Then maybe I can figure out how to make a separate IV Percentile indicator.10/18/2019 at 4:34 PM #110522
I can fix your last issue with some simple code changes. This should give you a green and grey histogram:1234567891011121314151617181920212223242526272829303132pd = 22 // "LookBack Period Standard Deviation High"bbl = 20 //"Bolinger Band Length"mult = 2.0 //"Bollinger Band Standard Devaition Up"lb = 50 //"Look Back Period Percentile High"ph = 0.85 //"Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%"n = 10//pl = 1.01 //"Lowest Percentile - 1.10=90%, 1.05=95%, 1.01=99%"mult = max(mult,1)mult = min(mult,5)wvf = ((highest[pd](close)-low)/(highest[pd](close)))*100sDev = mult * std[bbl](wvf)midLine = average[bbl](wvf)//lowerBand = midLine - sDevupperBand = midLine + sDevrangeHigh = (highest[lb](wvf)) * ph//rangeLow = (lowest[lb](wvf)) * plr = 128g = 128b = 128if (wvf >= upperBand or wvf >= rangeHigh) then //or (wvf <= lowerBand or wvf <= rangeLow) thenr = 0b = 0endifave = average[n](wvf)RETURN wvf coloured(r,g,b) style(histogram,1) as "Williams Vix Fix", ave style(line,1) as " WVF Average"10/18/2019 at 4:46 PM #110523
…and this is a version of the VixFix within 0 to 100 boundaries. Not what you are after I think but maybe useful?123456789101112131415161718192021222324252627282930313233p = 200 //LookBack for boundariespd = 22 // "LookBack Period Standard Deviation High"bbl = 20 //"Bolinger Band Length"mult = 2.0 //"Bollinger Band Standard Devaition Up"lb = 50 //"Look Back Period Percentile High"ph = 0.85 //"Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%"mult = max(mult,1)mult = min(mult,5)wvf = ((highest[pd](close)-low)/(highest[pd](close)))*100sDev = mult * std[bbl](wvf)midLine = average[bbl](wvf)upperBand = midLine + sDevrangeHigh = (highest[lb](wvf)) * phr = 128g = 128b = 128if (wvf >= upperBand or wvf >= rangeHigh) then //or (wvf <= lowerBand or wvf <= rangeLow) thenr = 0b = 0endif//Boundariesupper = highest[p](wvf)lower = lowest[p](wvf)wvflev = ((wvf-lower)/(upper-lower))*100RETURN 100 as "100", 50 as "50", 0 as "0", wvflev coloured(r,g,b) style(histogram,1) as "Williams Vix Fix"10/18/2019 at 6:05 PM #11052710/19/2019 at 8:27 PM #110599
Great, thanks very much for taking another look at this @vonasi and for the wvflev amendment @Robertogzzi. I had no internet today as I had British Telecom in fixing a phone fault so I’ll take a proper look tomorrow or Monday.
One thing I noticed on Trading View is that they use a logarithmic version for calculating the HV as mentioned in my post above. I wonder if that will give better signals? But maybe then it can’t be regarded as a Vix Fix?Historical Volatility12345678study(title="Historical Volatility Rank")Length = input(20, minval=1)annualVol = input(365, minval=1)Price = log(close / close)periods = iff(isintraday or isdaily, 1, 7)sigma = stdev(Price, Length)HVol = (sigma * sqrt(annualVol / periods)) * 100
Also, is it quite complicated to make the indicator show the Low volatility periods (Market peaks)? It may be a good idea to have it display in the format of that Ninja Trader image which is displaying data from a centered mid point x-axis and not displaying from the bottom of the x-axis as per the PRC indicator? (I’ll repost it here to save you looking for it).
Cheers, have a great weekend.10/19/2019 at 9:55 PM #110607
I’m afraid that I have absolutely no skills when it comes to converting other code formats to ProRealCode. I coded the last indicator that I provided purely by using your description of how it should be and adapting the logic into the code…. and only because I thought that it was an interesting coding challenge – some people do crosswords to keep their brain moving and some people try to turn a description into an indicator!
I can’t just look at an image and then code something that looks just like the image without an exact description of the logic behind it.
Perhaps if you can provide the actual code for the indicator in the image then Nicolas will be able to convert it as that is his speciality as a coding machine! 🙂10/20/2019 at 9:55 AM #110621
I think the moderators on this are forum are all coding machines! I mean that in the sense that it never ceases to impress me how you all get your minds round the math and coding language challenges — and not in the sense that you’re here just to deliver code on demand like machines!
1 user thanked author for this post.10/20/2019 at 1:16 PM #110636
Here’s a dropbox link https://www.dropbox.com/sh/bcmihvkefjf98cj/AAADlrHpNFlekHHtIe1vSVjJa?dl=0 to the Ninja Trader 8 Williams Vix Fix code (in #C) shown in the image above and sourced from here: https://ninza.co/product/williams-vix-fix
It derives from Trading View’s Chris Moody who based it on Williams’ Vix Fix pdf article on his Ireallytrade site (linked in my post above).
Williams: Low volatility is more often associated with market peaks, while high volatility is associated with market lows.
My thoughts are that because it is an approximation for the Vix — which represent traders’ expectations of (implied) volatility over the next 30 days — it should be used on a daily chart (not 15 mins) and with p = 365 periods to approximate to the Black Scholes option pricing model of implied volatility of a 1 Std Deviation move on an annual basis. When it’s set to 365 only the more significant high volatility bottoms are signified, so there’s less false entries.
Chris Moody also added an interesting feature — please see https://vimeopro.com/user32804960/tradingview-indicators/video/115923112 at 8 mins 25 secs — which is to add an alert panel signifying the bar after the last green bar to signal when to enter, (so you don’t buy in too early on all those initial green bars as the market is till falling). The real way to avoid that though is to increase the values like the ph percentile number up to 95% or 99%. To make the original PRC Vix Fix indicator more sensitive and accurate, these more extreme readings below give less chance of false entries on Indices (which have an inbuilt Long bias). It works well on Silver and the £/$ if values lb are set to 99 and ph to 0.99. (For those selling (writing) options I can’t stress how important it is to sell only at the very highest current volatilities (when premiums are going through the roof) and to enter only when there is a genuine sign that the market premiums (fear factor) are reversing).Orig PRC Vix Fix with more sensitive settings123456789101112131415161718192021222324252627282930313233p = 365 //LookBack for boundariespd = 365 // "LookBack Period Standard Deviation High"bbl = 20 //"Bollinger Band Length"mult = 4.5 //"Bollinger Band Standard Deviation Up"lb = 95 //"Look Back Period Percentile High"ph = 0.95 //"Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%"mult = max(mult,1)mult = min(mult,5)wvf = ((highest[pd](close)-low)/(highest[pd](close)))*100sDev = mult * std[bbl](wvf)midLine = average[bbl](wvf)upperBand = midLine + sDevrangeHigh = (highest[lb](wvf)) * phr = 128g = 128b = 128if (wvf >= upperBand or wvf >= rangeHigh) then //or (wvf <= lowerBand or wvf <= rangeLow) thenr = 0g = 255b = 0endif//Boundariesupper = highest[p](wvf)lower = lowest[p](wvf)wvflev = ((wvf-lower)/(upper-lower))*100RETURN 100 as "100", 50 as "50", 0 as "0", wvflev coloured(r,g,b) style(histogram,1) as "Williams Vix Fix"
Without having seen the Ninza code though it’s difficult to comment on exactly what they have done with Williams’ Vix Fix code and if it would improve by using a different equation for the WVF like the Trading View logarithmic version for calculating the HV posted a few comments above. Whatever, the fact that it spots high volatility bottoms and low volatility tops is a good idea for all traders including option sellers (writers).
Thanks, Bard.10/20/2019 at 2:59 PM #110640
Why 365? There are not 365 bars in a year due to weekends and holidays.
This might be of interest: