PureBytes Links
Trading Reference Links
|
The code needs to include a divide by zero check as follows:
Inputs: NumberDays(Numeric);
Variables: AssetPrice(0), Answer(0), Count(0), AvgDiff(0), SumDiff(0);
If NumberDays - 1 <> 0 then begin
AvgDiff = Average((log(Close[0] / Close[1])), NumberDays);
SumDiff = Summation(((Log(Close[0] / Close[1])) - AvgDiff) * ((Log(Close[0]
/ Close[1])) - AvgDiff), NumberDays);
Answer = (SquareRoot(SumDiff / NumberDays - 1)) * 16 ; {Annualize
Calculation sq root of 256 days}
If Answer <= 0 Then
Answer = 0;
If Answer >= 2.99 Then
Answer = 2.99;
VolatilityStdDev = Answer;
end;
If a 1 was entered in for the number of days you would be in trouble.
thanks for your input Brian.
Jim Bronke
>
> ----- Original Message -----
> From: "Brian Mense" <bmense@xxxxxxxxxx>
> To: <omega-list@xxxxxxxxxx>
> Sent: Friday, August 17, 2001 7:39 PM
> Subject: Correction to TS function - 'VolatilityStdDev'
>
>
> : Hi,
> :
> : I thought I would pass along a correction we made in a formula in
TS2000i.
> : The VolatilityStdDev function contains a line which reads 'Answer =
> : (SquareRoot(SumDiff / NumberDays) * SquareRoot(252); {Annualize
> : Calculation}' which should read 'Answer = (SquareRoot(SumDiff /
> : (NumberDays-1))) * SquareRoot(256); {Annualize Calculation - 256 is the
#
> of
> : trading days}'. Notice the NumberDays now has a -1 after it. Don't
worry
> : about the change from 252 to 256 right now.
> :
> : I discovered this after comparing Volatility calculations that I had in
> : Excel were not matching what was in TS. This appears to be the root
cause
> : of the difference and this is the primary difference in our formula
versus
> : TS. The next task was to determine which fomula was correct. It
appears
> : our original formula is the accepted method of calculating the
historical
> : volatility based on a centered approach, not TS's. At least according
to
> : Active Trader magazine and FutureSource.
> :
> : For what it's worth, this 'little' difference caused some pretty big
> : differences in my numbers.
> :
> : I also change the number used to Annualize the value from 252 to 256.
My
> : wife tells me I'm anal, I'm not sure why she thinks that. ;-)
> :
> : Brian
> :
>
|