The Ultimate Historical and Implied Volatility Rank and Percentile Indicator

Forums ProRealTime English forum ProBuilder support The Ultimate Historical and Implied Volatility Rank and Percentile Indicator

  • This topic has 21 replies, 3 voices, and was last updated 5 years ago by avatarBard.
Viewing 15 posts - 1 through 15 (of 22 total)
  • #110875

    Following on from this topic: https://www.prorealcode.com/topic/a-better-implied-volatility-rank-and-percentile-indicator

    I would be grateful if we can get this indicator coded. I think this would be an essential addition to the PRC library and am wondering if it is possible to code an Historical Volatility (HV) and Implied Volatility (IV) Rank and Percentile Indicator. It would be particularly beneficial for Currency, Indices and Options traders but can be applied to most markets. IV can only ever be approximated as it is derived from the Black Scholes option pricing model. 

    Black, Scholes and Merton won the Nobel Prize for coming up with their options pricing model because it predicted the future probability and pricing of asset prices. Option pricing, historical and implied volatility are crucial in that understanding of future asset pricing. For thorough explanation on probabilities please see my explanations here: 

    https://www.prorealcode.com/topic/options-probabilities-using-the-black-scholes-assume-a-normal-distribution/

    https://www.prorealcode.com/topic/a-better-implied-volatility-rank-and-percentile-indicator/#post-110512

    Two things come to mind: 

    1) A comparison in the same indicator needs to be made between the HV and IV. Example: Please see the screen attached, it’s from ivolatility via the Options Council website:

    https://www.optionseducation.org/toolsoptionquotes/historical-and-implied-volatility, it’s a blue and gold line graph of the HV v’s the IV. Other vendors also supply IV 30, IV 60 and IV 90 comparisons.

    I was then hoping we could have an indicator like this one I found on Trading View (linked just below) so it shows not just the IV rank but also the Percentile (so it’s scaled by 100%). 

    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.

    https://www.tradingview.com/script/Z30icKNi-IV-Rank-IV-Percentile/

    “This indicator is meant to be a substitute for Implied Volatility 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 VIX , which charts the implied volatility of the SPX. The great thing about the VixFix is that it can be applied to any security, not just the SPX.

    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.

    PRC Version – High volatility market bottoms (but without low volatility market tops).

    2) Can it be programmed so that the IV also can find low volatility market tops as well as high volatility bottoms, — i.e. instead of just having a fear barometer when Put Premiums are rising sharply and the market is due to bottom out, also have a greed barometer for Call Premium rises and potential low volatility market tops) like this indicator here:

    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 below and sourced from here:

    https://ninza.co/product/williams-vix-fix

    Historical Volatility

    Please see the formula for HV is from the attached Fidelity Investment screenshot.

    On PRC we have this version fo HV:

    and also this version:

    Both give fairly similar outputs but the log version is more precise.

    Implied Volatility

    As noted on the Trading View IV indicator post the formula approximation for IV has been coded by Larry Williams and is called the Vix Fix (with a moving average):

    https://www.prorealcode.com/topic/indicator-request-for-nic/#post-89764

    Any help getting this codified would be much appreciated!

    Cheers
    Bard

    #110895

    Bard – you are doing information overload again. 🙂

    One image of how the indicator should look and the one piece of code that needs converting and a brief description of the indicator and the logic behind it is all that is required. You are asking Nicolas to wade through some pretty deep mud to work out what exactly you are requesting.

    #110920

    Well, if I am supposed to translate the Ninjatrader code provided in the dropbox link, I can’t. The code is compiled into a DLL.

    So if I understand correctly the request, you’d like to add the highest and lowest volatility values on Vonasi’s code?

    #110952

    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:

    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).

    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!

    #110961

    Phew, I got that out in a three paragraphs! Wait.. I forgot to mention

    Your idea of brief is four paragraphs, two images, two bits of code and a link to look at too! Rather less brief than my idea of brief!

    Have you never heard the phrase ‘less is more’?

    I get more confused with every post rather than less confused and English is my mother tongue so I’ll leave this one to Nicolas who’s first language is French to see how he gets on! 🙂

    #110968

    I believe that I’ve explained it as simply and clearly as possible (and one of those paragraphs and one image was for you)! 😀
    Do you know why I see <span style=”font-size: 16px;”> when using Safari and posting here? The Add Code didn’t work the first time (as it invariable doesn’t and probably since updating Safari) and this is where the CSS derives from. Thought I’d stripped it all out when I edited the post by re-adding both sets of code and re-submitting the post for the second time.

    #110969

    I cleaned it up. Nicolas might be able to suggest what is going wrong and causing the <span style=”font-size: 16px;”> etc in your posts.

    1 user thanked author for this post.
    #111029

    Ok, let’s do it step by step! 🙂 Here is the adapted code with a scale from -100 to 100. So now, next step is to identify tops and bottoms by using the same method as the William Fix code above? It used a “bollinger band” style adaptive overbought/oversold zones: 2 std deviation from the mean.

     

    1 user thanked author for this post.
    #111111

    Cheers for coding the low volatility market tops Nicolas, and yes one step at a time! (I also often find myself reading multiple books at the same time…)

    I was wondering about the relationship between the Percentile and Vix Fix. I was expecting a mirror image of the original indicator but notice how much wider the distance is between the Percentile and IV Vix Fix when compared to the original high implied volatility market bottoms indicator that Vonasi coded?

    The original indicator has 0-100% in positive integers as you’d expect but our new version has negative and positive percentile rank integers because of the scaling boundaries between -100 and +100. Which is more appropriate, 0 to 100 surely? Not quite sure how to configure the Return code to do that: 0’s , 50’s and 100’s because of the code “(PercentileRank*2)-100 coloured…” etc?

    Also why does *2 at the end of the the wfv equation make data appear below the zero line?

    #111121

    Also why does *2 at the end of the the wfv equation make data appear below the zero line?

    Because it also has a -100 in the calculation. So 25% would be: 25*2 = 50  then 50-100 = -50.

    -50 is 25% of the range -100 to 100.

    1 user thanked author for this post.
    #111189

    What would be the code to get this second indicator scaled between 0 and 100% like the original one, so I can see if the far wider gaps between the Percentile and IV are just due to the -100 to +100 scaling? Cheers.

    #111191

    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:

    Sorry but you did want a scale from -100 to +100, now i’m lost in your explanation just like Vonasi 🙄

    #111235

    Apologies for any misunderstanding Nicolas, yes I thought a scale of -100 to +100% but within a single indicator that would highlight in different colours both high volatility bottoms and low volatility tops, like the Ninza image with it’s blue and red bar extremes, would be a good idea. The scaling I’m not so sure about now.

    I thought it’d be possible to get it all in one indicator so the Vix Fix chart image shown here: https://www.prorealcode.com/topic/indicator-request-for-nic/#post-20056

    would show not only low volatility market bottoms but also high volatility market tops all scaled between -100 to +100.
    Basically I thought it would be a good reason to scale from -100 to 100% if the indicator was showing both high volatility market bottoms and low volatility market tops, like green highlighted bars facing upwards (market bottom, go long) and also red bars downwards all in one indicator.

    I guess the confusion for me is that I didn’t realise that Vonasi’s IV Rank and Percentile indicator that you’ve based my coding request upon does in fact show high and low IV rank and percentile, those low implied volatility red readings are generally timing nicely with market tops – it’s more a colour warning coding issue that’s apparent. That indicator is on a scale of 0 to 100%, for percentiles I guess traditionally that makes sense as they’re plotted 0 to 100%. (If a result is above the mean it’s plotted above 50 and if below the mean it’s plotted below 50).

    As you can see from the image posted below I’ve not been able to do that in the lowest indicator panel. That indicator is based on your code for the Vix Fix (url at the top of this post).

    I cannot get away from a mirror image of IV above and below the zero line?  — Unlike the Ninza image which is not symmetrical or supposed to be.

    I also cannot get it to highlight different colour warnings dependent upon whether there are extreme high volatility points or low volatility points because of the bars symmetrical issue? But as you said one step at at time I won’t post that code here!

    Ps// In fact, taking another look at that  Ninza blue warning bars and associated nearby IV bars, it looks like they’re back to front. Generally, but not always — because IV isn’t directional — when a markets bottoming out you get high implied volatilities in the premiums of options (it’s because of the Black Scholes option pricing model). In the Ninza indicator they’ve inexplicably associated low IV with market bottoms?

    The indicator panel second from the bottom in my image is the code converted by you Nicolas and derived from Vonasi’s IV Rank and Percentile code and now highlights high volatility only. So neither of these two new indicators (Vonasi’s and yours) show both extremes being highlighted for high and low volatility conditions in one indicator with different colour coding like the Ninza image.

    As an aside and explanation for the confusion, I asked a few times, to convert the wvf formula — as I thought this was the part of the code that determined high vol bottoms and which would need to be altered to show those low vol market tops! The reason I didn’t think Vonasi’s version showed both high and low volatility statuses, (although it is colour coded to show low vol extremes), is:

    a) The following code pasted below — from the url I provided above in this post — was commented out but looked like it would achieve my goal for spotting/marking high vol tops: (I realise this indicator uses Bollinger bands).

    b) The new version of Vonasi’s indicator (that had shown high volatility market bottoms) and which now shows only low volatility  markets tops shows the opposite of the original signal lines placement within the indicator and is a mirror of the original Vonasi indicator – pls see image.

    What I needed clarifying and which I’ve asked a few times on my informal indicator request at https://www.prorealcode.com/topic/a-better-implied-volatility-rank-and-percentile-indicator/

    is why this following code: “William’s Vix Fix”

    isn’t altered, as I thought this is what what would need to be amended and used to spot those low volatility market tops? I only know now that this following code below is the part that spots that low volatility condition:

    In summary, the Ninza indicator is a good idea, it’s an all in one IV indicator with both high and low implied volatility colour coding for extremes. The PRC IV Rank and Percentile indicators are great but are separates and I’m not sure they should be mirror images of each other? It would be good to have them in one indicator like the Ninza and scaled 0  to 100% if it’s going to show percentiles. It was only after seeing and comparing Vonasi’s 0 to 100% indicator to the new -100 to +100% scale version for the percentile that I think the former 0 to 100 % scale made more sense to me.

    I hope this better clarifies things.

    Have a great weekend.
    Cheers Bard,

     

    #111240

    Thanks for the explanation Bard. However,  would it be possible to summarize the request in one sentence please? I know you took time to explain it precisely and it’s valuable,  thank you.

    So, just guide me with something like: “take this code and make it look like this picture”. I will go through the math by myself.

    #111280

    I’ve emailed Ninza to see if we can get the code. That could simplify matters!

    1 user thanked author for this post.
Viewing 15 posts - 1 through 15 (of 22 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login