Tuesday, January 13, 2015

thinkscript included: sdi_impvol - yet another implied volatility script

sdi_impvol plots implied volatility in a chart subgraph like the tos impVolatility study does but with some additional stuff that I think you will find is an improvement. here is an image of sdi_impvol at work:
spy with sdi_impvol showing the high, low and mid levels and the rank.
the green plot line is the implied volatility and the blue lines are the high, low and mid levels. the rank label indicates where the current implied volatility is with respect to the range between high and low. the rank and range lines contain a correction for equities that have discontinuous or infinite values for implied volatility and will display values for rank even when the tos iv percentile (same as iv-rank) does not. the label text and color are adjustable from the customize study dialogue as are the plot properties. in fact, the plots can be hidden, leaving only the rank label showing, and the study moved to the upper chart graph to replace my previous sdi_ivp study with an improved rank label.

here's the code: (how to install)




#########################
# sdi_impvol - implied volatility with improvements.
#hint: plot implied volatility as a lower study with low, mid, high lines and rank label. rev:1.0.0 http://www.smalldoginvestor.com 
# author: allen everhart
# date: 13jan2015
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale. 
# Help me get the word out about my blog by keeping this header
# in place.
declare lower;
input labelText = "Rank";
#hint labelText: controls the text of the rank label.rev:1.0.0 http://www.smalldoginvestor.com 

plot iv = ImpVolatility();
iv.SetDefaultColor(Color.DARK_GREEN);

def ivGapHi = 
    if IsNaN(ImpVolatility()) then Double.POSITIVE_INFINITY
    else if ImpVolatility() == Double.NEGATIVE_INFINITY then Double.POSITIVE_INFINITY 
    else ImpVolatility();
def ivGapLo = if IsNaN(ImpVolatility()) then Double.NEGATIVE_INFINITY
    else if ImpVolatility() == Double.POSITIVE_INFINITY then Double.NEGATIVE_INFINITY
    else ImpVolatility();
def periodHigh = HighestAll( ivGapLo );
plot hi=periodHigh;
hi.setDefaultColor(color.BLUE);
def periodLow = LowestAll( ivGapHi );
plot lo=periodLow;
lo.setDefaultColor(color.BLUE);
plot mid = (periodHigh + periodLow) / 2;
mid.SetDefaultColor(Color.BLUE);
mid.SetStyle(Curve.SHORT_DASH);

plot label=double.naN;
label.hideTitle();
label.setDefaultColor(color.BLUE);
addlabel(1, 
    concat(labelText, 
    concat(":", aspercent(round((iv - periodLow)/(periodHigh-periodLow),2)))), 
    label.takeValueColor());

###############

No comments:

Post a Comment