Elmer -
I was interested in this Yang-Zhang volatility measure when it was first
mentioned on the forum
(earlier this month?). You may or may not recall that I posted a version of
this volatility calculation
then. Comparing what I posted then to what you just posted, I have a few
comments.
The answer I get for the sample you use differs substantially from the
answer you get. To illustrate
just one point of difference, let's look at the calculation for what I call
"sigmars2" and you call "rho2_rs".
An initial difference is that I make the number of trading days the left
argument ("x") to my function and
default to 250 since this is a round number close to the actual value of
about 252 whereas you're
using Z=. 256 - this is a small difference so I'll use your value below.
So, whereas I defined this as
sigmars2=. (x%nn)*+/((^.high%close)*^.high%open)+(^.low%close)*^.low%open
and your equivalent is
rho2_rs =: ( Z % n ) * ( +/ ((ln( Hi % Ci)) * (ln( Hi % Oi ))) + ( ln (Li %
Ci)) * ( ln ( Li % Oi)))
Right away, I see that whereas I use, e.g. "open" and "close", you're using
"Oi" and "Ci" which
are slightly different, e.g.
open
1 2 3 4 5 6 7 8 9
Oi
2 3 4 5 6 7 8 9
Is there a particular reason you're dropping the initial observation here?
Looking at the page
you reference, I see nothing to indicate this though I may be missing
something.
Also, just from a readability standpoint, your code defines, e.g. "open",
then assigns
openData=: open, then assigns Oi=: }.openData. This seems like a couple of
extra levels
of assignment which makes me wonder what the reason is for this.
Anyway, the value I get differs substantially from the one you get:
]sigmars2=.
(Z%nn)*+/((^.high%close)*^.high%open)+(^.low%close)*^.low%open
90.424031
vs.
rho2_rs
66.590399
I can reconcile my answer to yours by making the adjustments I noted, i.e. I
could
calculate
(Z%n)*+/((^.(}.high)%}.close)*^.(}.high)%}.open)+(^.(}.low)%}.close)*^.(}.low)%}.open
66.590399
(where your "n" is 8 because of the initial dropped value versus my "nn" of
9 because I'm
using the whole series).
This difference between using "nn=. #close" vs. "n=. <:#close" is also
reflected in my
code where I deliberately changed the calculations of the Mu_o and Mu_c to
use the
mean instead of what it says on the page because I think this makes more
sense, i.e.
nn%~+/lnOiCi1 NB. This is what reference page says but
_1.8026062
mean lnOiCi1 NB. I think this is correct.
_2.027932
(<:nn)%~+/lnOiCi1 NB. This is how the mean relates to the stated
equation...
_2.027932
Also, "mu" is typically used as the symbol for the mean.
Can you clarify your assumptions here? In any case, these small initial
differences leading to
such large differences in the results do little to give me confidence in the
robustness of this
measure. I was unable to get a copy of the original paper so am unaware of
the justification
for these formulas. Do you have some idea of their bases?
In any case, I include my version of Yang-Zhang below, which I modeled after
the formulas at
http://www.sitmo.com/eq/417 . I'd like to know more about this.
I still wonder at the magic number "0.34" in the definition of "k" - any
idea where this comes from?
Thanks,
Devon
NB.* YangZhangVoly: volatility by Yang-Zhang method:
http://www.sitmo.com/eq/417
YangZhangVoly=: 3 : 0
250 YangZhangVoly y
:
'open high low close'=: <"1 y
nn=. #close
zn=. x%<:nn
lnOiCi1=. ^.(}.open)%}:close
NB. muo=. nn%~+/lnOiCi1 NB. This is what reference page says but
muo=. mean lnOiCi1 NB. I think this is correct.
sigmao2=. zn*+/*:muo-~lnOiCi1
lnOiCi=. ^.(}.open)%}.close
NB. muc=. nn%~+/lnOiCi NB. This is what reference page says but
muc=. mean lnOiCi NB. I think this is correct.
sigmac2=. zn*+/*:muc-~lnOiCi
sigmars2=. (x%nn)*+/((^.high%close)*^.high%open)+(^.low%close)*^.low%open
kk=. 0.34%>:(>:nn)%<:nn
%:sigmao2+(kk*sigmac2)+(1-kk)*sigmars2
NB.EG ohlc=. 1 2 3 4 5 6 7 8 9,15 25 35 45 55 65 75 85 95,1 2 3 4 5 6 7 8
9,:10 20 30 40 50 60 70 80 90
NB.EG 9.119673390362900=YangZhangVoly ohlc
)
On 6/23/07, Elmer Fittery <[EMAIL PROTECTED]> wrote:
I am 61 years old. I have been working as a software engineer since the
late 60's. I graduated from UCLA. I hope to retire from Northrup
Grumman in the next few years.
I started my career writing APL at UCLA on a student work program and
then upon graduation, started programming in Z80 and forth. Over the
years, I moved into Unix and C/C++. From the late 60's to now, there
has been a lot of water under the bridge and lots of Operating systems,
languages and projects.
Recently, I was a little bored writing regression testing in my
companies proprietary language "babalonia" ( I am 1 or 4 people in the
world that knows this language, but I doubt it will improve my
marketability ). Anyhow, I mentioned to a fellow worker that I had done
some APL and thought it was a great language. He said his father had
been a APL programmer prior to his death in a car wreck. We talked
about the character set problem and he said "look at J". My interests
was tweaked. I installed J on my ubuntu linix box at home and on my
Win2000 - running cygwin at work. Then started learning J in my spare
time. Then I found reference to the "Euler Project" and started writing
J code to solve the problems. Then Glen told me about opentick. He
said he didn't use it, but it was interesting. Anyhow, I got the
install package opentick code for Perl, C/C++ and java. This lead to
the thread on J and Opentick.
What is my motivation? I would say, the whole thing about J-Opentick is
just a sequence of fortunate "it just happened". Also, I have some
ideas about analyzing stock data that I wish to investigate and J will
do just fine once I get over the initial learning curve.
I will post a sample of my J code rendition for
Historical Open-High-Low-Close Volatility: Yang Zhang
which is defined at:
http://www.sitmo.com/eq/417
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm