Coding Rogers Satchell HV
Creation Date: 8/14/2008 4:37 PM

#1
I am trying to code a historical volatility formula according to Rogers-Satchell,the formula is here http://www.sitmo.com/eq/414. I used Eugene's code for Correlation as an example and below is as far as I could get. I get "index outside the bounds" error.

Also, I was looking into how to make a fully functional indicator, but could not locate the instructions for that.

CODE:

#### Eugene

#2
Shouldn't
CODE:
be
CODE:
?

#3
Eugene, with your change the error goes away. i don't see anything charted for some reason. also, this script presumably calculates volatility for all bars while i would like to be able to change the period (20 days, 50 days, etc.)
CODE:

is it possible to see the code for HV that is already in WL5? i probably would be able to adjust it to make it into Rogers-Satchell's formula. ideally, i would like to create several varieties of historical volatilities as fully-functional indicator(s) and make them available to the community. or maybe somebody else could code them. for example, there could be one new volatility indicator HV_new that accepts switches to make it into different volatiities (several formulas are here: http://www.sitmo.com/eqcat/4)

#### Eugene

#4
Now I get your point on calculating volatility for all bars. Respectively, to see the function's actual output you would have to start the bar loop at bar 0 (instead of n).

QUOTE:
is it possible to see the code for HV that is already in WL5?

I'd like to help you but I'm afraid that since Fidelity decided to obfuscate their code for Common Indicators, chances are low.

#### Eugene

#5
Well, here's my quick take:
CODE:

QUOTE:
"The Roger and Satchell historical volatility estimator allows for non-zero drift, but assumed no opening jump."
Then what's the point in using this estimator if it assumes no opening gaps?

P.S.
CODE:
I don't think it should be coded this way.

#6
Eugene, thank you for the code!

QUOTE:
"The Roger and Satchell historical volatility estimator allows for non-zero drift, but assumed no opening jump."
Then what's the point in using this estimator if it assumes no opening gaps?

I guess different volatility estimators have their strengths and weaknesses. Several estimators listed on that site are 7-14 fold more efficient than the classical HV from WL. I think Rogers-Satchell is 7x more efficient. One could always try them out and chose which one is the best or combine several.

QUOTE:
I'd like to help you but I'm afraid that since Fidelity decided to obfuscate their code for Common Indicators, chances are low.

This is very unfortunate decision by Fidelity for several reasons. First, mistakes are possible in the code and they won't come out until somebody notices strange behavior of a particular indicator. Second, some indicators could have alternative formulas and it would be good to know which version exactly was coded. Third, the open source would help create more community indicators, which should be good for Fidelity in the long run.

#### Eugene

#7
QUOTE:
Third, the open source would help create more community indicators, which should be good for Fidelity in the long run.
Take a look at our open source projects: Community.Indicators and TASCIndicators.

#8
eugene, could you help me to iron out a problem with your code for Rogers-Satchell volatility? It does not work correctly, because i think it does not sum up values for different days. i am checking with formulas in TC2007 and i see that the output matches for a period=1, but is different for higher periods. the formula i use in TC2007 for 2 day volatility: SQR (LOG(H1/C1)*LOG(H1/O1)+LOG(L1/C1)*LOG(L1/O1)+LOG(H/C)*LOG(H /O)+LOG(L/C)*LOG(L/O))*SQR (262/2). For example, i get for AIG 0.40 (TC2007) vs. 0.22 (your code).

I have tried modifying the code but this did not work
CODE:

#### Eugene

#9
This code for a 2-period HV translates to:
CODE:

And shows me 0.42/0.40 (Fidelity/Yahoo! data.)

But the formula looks different than the one at sitmo.com?

#10
QUOTE:
And shows me 0.42/0.40 (Fidelity/Yahoo! data.)

But the formula looks different than the one at sitmo.com?

actually, they seem the same to me. except i put 262/2 under a separate SQRT. this should not make any difference.

where do you see the difference? i noticed that you used Math.Abs in your earlier code, but i thought that was just to make sure you don't run into SQRT(negative number). in any case, Abs is not a problem, i think.

according to the formula at sitmo.com: you Sum by i, not by n, even though max_i=n. maybe this is a problem.

#### Eugene

#11
QUOTE:
i noticed that you used Math.Abs in your earlier code,

Perhaps I mistook .Round for .Abs.

#12
QUOTE:
Perhaps I mistook .Round for .Abs.

i don't know. it is hard for me to read c# syntax. should not the code have s+= somewhere?
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).