General Topics
Technical Topics
Brokerage Firms
Community Lounge
Site Support

# Historical Volatility Equation?

Discussion in 'Technical Analysis' started by cashonly, Apr 2, 2004.

I'm looking for an equation to calculate the historical volatility of a stock based on a close to close basis.

I know websites where I can find the actual volatility numbers.

But, what I want is the equation to calculate these. Does anyone have it or can you point me in the right direction?

Thanks,

Cash

2. ### Option_Attack

Here is the formula for the historical log-normal vol. It can be used as an input to Black-Scholes. It's directly from McMillan's "Strategic" book, but written in Pascal-like WealthScript. Easy to convert to C.

function LogVol(xdays, currentBar: integer):float;
begin

var AvgOfLns, SumOfAvgs: float;
var count, i, endloop: integer;

var Pratio: array[0..500] of float;
var LNratio: array[0..500] of float;
var Avgarray: array[0..500] of float;

count := currentBar;
AvgOfLns := 0.0;
SumOfAvgs := 0.0;
endloop := xdays - 1;

for i := 0 to endloop do //Get ratio of Closes
begin
Pratio := PriceClose(count)/PriceClose(count - 1);
count := count - 1;
end;

for i := 0 to endloop do //Take the LN and get average
begin
LNratio := LN(Pratio);
AvgOfLns := AvgOfLns + LN(Pratio);
end;

AvgOfLns := AvgOfLns/xdays;

for i := 0 to endloop do //Square difference and get average
begin
Avgarray := Sqr(LNratio - AvgOfLns);
SumOfAvgs := SumOfAvgs + Sqr(LNratio - AvgOfLns);
end;
//Result is normalized to 1 year and expressed as a percent
Result := Sqrt(SumOfAvgs/(xdays-1)) * Sqrt(250.0) * 100.0;

end; //End LogVol function