PureBytes Links
Trading Reference Links
|
Dans un courrier daté du 16/02/98 19:56:01 , Mark Brown écrit :
<< I assume that you are referring to the volatility equation that is used in
calculating options
premiums. Here is my user function for calculating volitility. You may of
course thank me
profusely for the code. Wouldn't it be nice if others were so forth coming?
I think the more
examples of code you see the better you are able to code and test your
theories. I encourage
others to publish their code so we all will benefit.
>>
So do I...
<<
(You must name the user function MyVolatility or change the code to a new
name)}
Inputs : Price(NumericSeries),Length(NumericSimple);
Vars : SumSqr(0),Counter(0),R(0),vari(0),yr_var(0),
N(1);
If Length <> 0 then Begin
SumSqr = 0;
R = 0;
vari = 0;
yr_var = 0;
N = 1;
For counter = 1 to Length begin
R = (Price[counter] - Price[counter + 1]) / Price[counter + 1];
r = Log(1 + R);
SumSqr = SumSqr + (r - Log(1 + Average(R,Length) ) ) * (r - Log(1 +
Average(R,Length) ) );
End;
vari = SumSqr / (Length - 1);
If DataCompression = 2 then N = 252
Else If DataCompression = 3 then N = 52
Else If DataCompression = 4 then N = 12;
yr_var = vari * N;
VolatilityX = SquareRoot(yr_var);
End
Else
VolatilityX = 0;
>>
===============================================
As previously posted, a factor 100 is missing in the above formula.
VolatilityX = 100*SquareRoot(yr_var);
Here is an other one, shorter, close of above when plotted with Mark's
volatilityX, but seeming to lag of *less* than one bar.
===============================================
{User Function SrVola.
Code by Pierre Orphelin
www.sirtrade.com}
input:recvola(numeric); {lookback period}
vars:dlr(0),valueX(252);
if datacompression=3 then valueX=52;
if datacompression=4 then valueX=12;
if recvola>1 then begin
dlr=square(log((c/c[1])-average(log(c/c[1]),recvola)));
Srvola=100*(squareroot(valueX)*squareroot(Summation(dlr,recvola)/(recvola-1))
);
end;
=============================
====
Sincerely,
Pierre Orphelin
www.sirtrade.com
|