Вы находитесь на странице: 1из 4

Code:

# IV_Rank - IMPLIED VOLATILITY RANK - Adds a colored label to the chart


showing IV Rank
#
# This study simply places a label on the chart showing the current IV
# Rank, otherwise known as IV Percentile. In addition, the label is
# color-coded to hint at the IV Rank, where lower values appear red and
# higher values are green, suggesting greater premium available to be
# sold at a higher IV Rank.
#
# For a more complex presentation of IV Rank in the context of past implied
# volatility, see my other thinkScript: http://pastebin.com/0Vumd8Gt
#
# By: Chris Baker <ChrisBaker97@gmail.com> @ChrisBaker97
# Latest version maintained at: http://pastebin.com/jRDkHvXE
# More thinkScripts at: http://pastebin.com/u/ChrisBaker97
#
# Credit goes to Allen Everhart (http://www.smalldoginvestor.com) for the
# original idea and implementation of IV Percentile as a chart label.
#
# Portions of this code are derived from the IV_percentile Scan tab
# thinkScript included with the thinkorswim platform by TD Ameritrade.
#
# This thinkScript is designed for use in the Charts tab.
#
# This work is licensed under the Creative Commons Attribution-ShareAlike
# 3.0 Unported License. To view a copy of this license, visit:
# http://creativecommons.org/licenses/by-sa/3.0/deed.en_US
#
# This version of the IV Rank study adds dynamic color-coding, for quick
# identification of high- or low-IV Rank. The code has also been
# streamlined for faster execution and ease of interpretation. There is
# also no need to specify a period for the study - the entire aggregation
# period on the chart is used.
#
# The user input brightness can range from 0 to 100 and controls the
# intensity of the plot's red-green color scheme. A lower brightness will
# show up better on a light background, and vice versa.

input brightness = 80 ; # overall brightness of IV display


q
declare upper ;
declare hide_on_intraday ; # IV shows N/A for intraday
aggregations, so we hide it

def ivClean = if isNaN(impVolatility()) # if IV data doesn't exist for a


particular period ...
then ivClean[1] # ... set it to the previous value so
it won't taint the hi/lo
else impVolatility() * 100 ;

def ivHi = HighestAll(ivClean) ; # highest IV over range


def ivLo = LowestAll(ivClean) ; # lowest IV over range

def ivRange = ivHi - ivLo ; # IV range from low to high

def ivRank = Round( 100 * (ivClean - ivLo) / ivRange, 1) ; # IV rank

# Define a color level from 0 to 255 based on current IV%


def level = ivRank * 2.55;

# Check bounds and convert brightness input to an intensity factor between


0.2 and 1.0
def intensity = if brightness < 0 then 0.2
else if brightness > 100 then 1.0
else 0.2 + (brightness * 0.008) ;

# Calculate red and green color levels (modified by intensity) for the color
function
def rLvl = intensity * (255 - level) ;
def gLvl = intensity * (level) ;

# Add label, colored according to current IV Rank.


AddLabel(yes, "IV Rank: " + ivRank + "%", CreateColor(rLvl, gLvl, 0)) ;
Code:
def vol = Imp_Volatility();
#rec data = if !isNaN(vol) then vol else data[1];
def data = vol;
def hi = highest(data,252);
def lo = lowest(data,252);
def perct = round((data - lo)*100/ (hi - lo),0);
plot x = perct;
Code:
# IV_Rank - IMPLIED VOLATILITY RANK - Adds a colored label to the chart
showing IV Rank
#
# This study simply places a label on the chart showing the current IV
# Rank, otherwise known as IV Percentile. In addition, the label is
# color-coded to hint at the IV Rank, where lower values appear red and
# higher values are green, suggesting greater premium available to be
# sold at a higher IV Rank.
#
# For a more complex presentation of IV Rank in the context of past implied
# volatility, see my other thinkScript: http://pastebin.com/0Vumd8Gt
#
# By: Chris Baker <ChrisBaker97@gmail.com> @ChrisBaker97
# Latest version maintained at: http://pastebin.com/jRDkHvXE
# More thinkScripts at: http://pastebin.com/u/ChrisBaker97
#
# Credit goes to Allen Everhart (http://www.smalldoginvestor.com) for the
# original idea and implementation of IV Percentile as a chart label.
#
# Portions of this code are derived from the IV_percentile Scan tab
# thinkScript included with the thinkorswim platform by TD Ameritrade.
#
# This thinkScript is designed for use in the Charts tab.
#
# This work is licensed under the Creative Commons Attribution-ShareAlike
# 3.0 Unported License. To view a copy of this license, visit:
# http://creativecommons.org/licenses/by-sa/3.0/deed.en_US
#
# This version of the IV Rank study adds dynamic color-coding, for quick
# identification of high- or low-IV Rank. The code has also been
# streamlined for faster execution and ease of interpretation. There is
# also no need to specify a period for the study - the entire aggregation
# period on the chart is used.
#
# The user input brightness can range from 0 to 100 and controls the
# intensity of the plot's red-green color scheme. A lower brightness will
# show up better on a light background, and vice versa.

input brightness = 80 ; # overall brightness of IV display


q
declare upper ;
declare hide_on_intraday ; # IV shows N/A for intraday
aggregations, so we hide it

def ivClean = if isNaN(impVolatility()) # if IV data doesn't exist for a


particular period ...
then ivClean[1] # ... set it to the previous value so
it won't taint the hi/lo
else impVolatility() * 100 ;

def ivHi = HighestAll(ivClean) ; # highest IV over range


def ivLo = LowestAll(ivClean) ; # lowest IV over range

def ivRange = ivHi - ivLo ; # IV range from low to high

def ivRank = Round( 100 * (ivClean - ivLo) / ivRange, 1) ; # IV rank

# Define a color level from 0 to 255 based on current IV%


def level = ivRank * 2.55;

# Check bounds and convert brightness input to an intensity factor between


0.2 and 1.0
def intensity = if brightness < 0 then 0.2
else if brightness > 100 then 1.0
else 0.2 + (brightness * 0.008) ;

# Calculate red and green color levels (modified by intensity) for the color
function
def rLvl = intensity * (255 - level) ;
def gLvl = intensity * (level) ;

# Add label, colored according to current IV Rank.


AddLabel(yes, "IV Rank: " + ivRank + "%", CreateColor(rLvl, gLvl, 0)) ;

Вам также может понравиться