Historic Volatility Label


Category:
0
0

Hey guys,

I’m trying to create a chart label that displays the Historic Volatility onto a chart label with the % to match the one on the options chain. I’m somewhat familiar with the Add Label feature, but having difficulty making sense of the formula in order to make it work properly. I keep getting odd results that don’t match the HV on the options chain. For example, the chart label’s HV should match the HV in the chain screenshot. The script included is from TOS .

Attachments:
Marked as spam
Posted by (Questions: 11, Answers: 10)
Asked on October 3, 2018 1:19 am
127 views
0

plot Data = close;

declare lower;

input length = 20;
input basis = {default Annual, Monthly, Weekly, Daily};

def ap = getAggregationPeriod();

assert(ap >= AggregationPeriod.MIN, “Study can only be calculated for time-aggregated charts: ” + ap);

def barsPerDay = (regularTradingEnd(getYyyyMmDd()) – regularTradingStart(getYyyyMmDd())) / ap;
def barsPerYear =
if ap > AggregationPeriod.WEEK then 12
else if ap == AggregationPeriod.WEEK then 52
else if ap >= AggregationPeriod.DAY then 252 * AggregationPeriod.DAY / ap
else 252 * barsPerDay;

def basisCoeff;
switch (basis) {
case Annual:
basisCoeff = 1;
case Monthly:
basisCoeff = 12;
case Weekly:
basisCoeff = 52;
case Daily:
basisCoeff = 252;
}

def clLog = log(close / close[1]);
plot HV = stdev(clLog, length) * Sqrt(barsPerYear / basisCoeff * length / (length – 1));
HV.SetDefaultColor(GetColor(0));

AddLabel(yes,Round( HV,2) +”%”, color.blue);

( at October 3, 2018 1:20 am)
0
Private answer

“Historic Volatility” and “Historic Volatility Percentile” are not the same. This likely explains why you are not getting matching values.

Historic Volatility Percentile is expressed as a percent of current value within the 52 week range. Notice in your screenshot, you have “52 week HV high” and “52 week HV low”. The range is the high minus the low: 0.461 – 0.096 = 0.365.

From your screenshot the “Historic Volatility Percentile” is 40%. This means that the current HV value is: 0.096 + (0.365 * 0.4) = 0.242

Now, I just did all that math first thing in the morning before having a drop of caffeine. Double check my work and make sure this is correct. Once you understand the math you will have the rest of your solution.

 

 

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on October 3, 2018 7:53 am