Forums › ProRealTime English forum › ProBuilder support › The Ultimate Historical and Implied Volatility Rank and Percentile Indicator › Reply To: The Ultimate Historical and Implied Volatility Rank and Percentile Indicator
Thanks Vonasi, I do appreciate your need to get to the core of the coding task. It’s also that it helps me by having all the info in one post so I don’t have to spend time going back and forth searching for all the links and details I’ve sourced if I need to improve/compare some aspect of the indicator/concept. It may also help others who come across the post and don’t understand the relevance/function of the indicator.
Nicolas, oh, ok no worries. I searched again just now and actually found the best options trading software platform aka: TD Ameritrade’s,
Think or Swim and all their HV and IV codes:http://www.thetatrend.com/4-volatility-indicators-for-options-trading-with-thinkorswim-thinkscript-code/
The main idea then would be to have a chart like ivolatility’s image #1 (which I posted above) and think or Swims (pls see image posted below) with both HV and IV lines with actual market % changes in volatility (not scaled as 100%). This would have to be a separate indicator as I’m not sure it can be overlaid within the main Ninza high/low volatility indicator. Does the current PRC versions of HV respect the Fidelity equation in image #4 above?
Think or Swim Historical/Implied Volatility code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#HVIV - Historical/Implied Volatility #Provides 20 day and 60 day (1 and 3 month) HV Lines #Feel free to share the code with a link back to thetatrend.com declare lower; declare hide_on_intraday; #20 day input input longLength = 252; input shortLength = 20; #60 day HV input input longLengthb = 252; input shortLengthb = 60; def clLog = Log(close / close[1]); #Plot Implied Volatility plot ImpVol = IMP_VOLATILITY(); #Plot 20 day HV plot HV = stdev(clLog, shortLength) * Sqrt(shortLength * longLength / (shortLength - 1)); HV.SetDefaultColor(GetColor(0)); #Plot 60 day HV plot HVb = stdev(clLog, shortLengthb) * Sqrt(shortLengthb * longLengthb / (shortLengthb - 1)); HVb.SetDefaultColor(GetColor(0)); |
Yes please, my third Ninza image above here shows the high and low volatility from a central axis which would be great and it’s also scaled within -100% to +100% boundaries. It would just be a modification of the great job Vonasi has done with this IV Rank/Percentile code below but I’m hoping it can include:
- Identify market tops.
- Identify market bottoms.
- Highlight plots and bars where tops or bottoms are identified, (currently we just have the green low volatility mkt bottoms).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
//Implied Volatility Rank and Percentile Indicator //By Vonasi //Date 20191018 //settings p = 200 vixfixperiod = 22 //Vix Fix - Implied Volatility Proxy wvf = ((highest[vixfixperiod](close)-low)/(highest[vixfixperiod](close)))*100 //Boundaries upper = highest[p](wvf) lower = lowest[p](wvf) wvflev = ((wvf-lower)/(upper-lower))*100 //Percentile rnkCount = 0 count = 0 FOR i = 1 to p-1 count = count + 1 IF wvflev[i] < wvflev THEN rnkCount = rnkCount + 1 endif NEXT PercentileRank = (rnkCount/count)*100 //colours r = 128 g = 0 if wvflev >=50 then r= 0 g = 128 endif r1 = 255 g1 = 140 b1 = 0 if PercentileRank >=50 then r1 = 0 g1 = 255 b1 = 255 endif RETURN 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" |
Phew, I got that out in a three paragraphs! 😀
Wait.. I forgot to mention, because market prices don’t follow a normal distribution and our PRC indicators and the Ninza indicator rely on Bollinger Band/Std Deviations, has anyone ever tried to use a Fisher Transform on this kind of volatility data first and output that in a rank or percentile indicator, is that practical, wouldn’t it be more accurate?
Ps/ I’ve posted an image of the PRC HV/IV indicators that are currently available on the forum below. (I set percentiles for the green bars to 99% and a “Bollinger Band Standard Deviation Up” set to 6.0 for extreme accuracy — it should be 1 std dev to replicate the Black Scholes model).
Thanks again Vonasi, certainly these volatility changes are a lot clearer now!