I'm a noob trying to calculate IntraDay and Overnight Volatility.

For Intraday volatility we can get the annualization factor with the following:

Length (hours, Open to Close): 6.5

Time frames per day: 24 / 6.5 = 3.6923

Time frames per year: 252 * 3.6923 = 930.4596

Annualization factor: SQRT(930.4596) = 30.5034

For Overnight volatility, the annualization factor is:

Length (hours, Close to Open): 17.5

Time frames per day: 24 / 17.5 = 1.3714

Time frames per year: 252 * 1.3714 = 345.5928

Annualization factor: SQRT(345.5928) = 18.5901

With these parameters, I can calculate intraday volatility as the standard deviation of the 20 most recent open-to-close price changes, multiplied by the annualization factor, 30.5034

And overnight volatility can be calculated by the standard deviation of the 20 most recent close-to-open price changes, multiplied by the annualization factor, 18.5901

It seems like this should be pretty straightforward since I have all the inputs but I'm not sure if I'm doing it right, especially in thinkorswim.

For example, I tried editing ThinkorSwim's default historical volatility study to the following (I only changed the the last two lines from the bottom):

# TD Ameritrade IP Company, Inc. (c) 2007-2017

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(open / close[1]);
plot HV = stdev(clLog, length) * 30.5;

Is this correct? Is there a simpler thinkscript/formula? Thanks very much. I appreciate it.

** Here's the graph its spitting out: enter image description here

  • 1
    $\begingroup$ Looks Good. What's the issue here? $\endgroup$
    – james
    Commented Jul 21, 2017 at 0:54
  • $\begingroup$ I'm honestly just not sure if the output is correct. Just want to verify. I just added an image of the intraday and overnight below implied/historical. For example, why is the line for overnight (0.89) lower than the line for intraday (0.40) and ImpVolatility (0.86)? $\endgroup$
    – reknirt
    Commented Jul 21, 2017 at 1:00

2 Answers 2


Looks correct to me, the open of the last bar divided by the close of the previous bar.

def clLog = log(open / close[1]);

For intraday it would be...

def clLog = log(open / close);

Also, to answer your comment, when combining plots all lines are scaled to use the full vertical space of the graph (i.e. 0-100%) which is why a lower number value from one line may show above a higher value from another line.


You can find a greast summary on volatility estimation here.

I also suggest to get familiar with Garman-Klass volatility. Discussed here and in this article.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.