>Message: 2
>Date: Sun, 24 Jun 2007 03:09:34 -0400
>From: "Devon McCormick" <[EMAIL PROTECTED]>
>Subject: Re: [Jprogramming] J - OpenTick and Elmer
>Fittery's bio To: "Programming forum"
><[email protected]> Message-ID:
>   
><[EMAIL PROTECTED]
>m> Content-Type: text/plain; charset=ISO-8859-1;
>format=flowed
>
>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.

It would be useful to have test data against which the
Yang-Zhang volatility measure can be calculated.

As an example:

open =: 0 1 2 3 4 5 6 7 8 9 10
close =: 1 2 3 4 5 6 7 8 9 10 11
high  =: 1 2 3 4 5 6 7 8 9 10 11
low    =: 0 1 2 3 4 5 6 7 8 9 10

If you had a standard input set for open, close, high and
low all implimentations should yeild the same results.

>
>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%o
>pen 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

The reason I did this is to allow me to represent all my Hi,
Li, Oi and Ci as representing days 0 1 2 3 4 and so on...
and Ci_1 to represent days -1 0 1 2 3 4 and so on.

So I drop the first days data from close to get Ci_1 and
drop the last day from the other data.

This gives me the same number of elements in Hi, Li, Oi, Ci
and Ci_1.

>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.

There was nothing in the reference page saying I had to do
this.  It just occured to me the algorithm required all data
open, close, high and low to have the same number of
elements.  Hence I came up with the Hi, Li, Oi, Ci and Ci_1
nouns.

>
>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%o
>pen 90.424031
>vs.
>   rho2_rs
>66.590399

It is very likely my code isn't correct.

>
>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).

I did not think I could use the whole series because Hi, Li,
Ci, Oi are one day shifted from Ci_1.

>
>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

This definitely bears looking into.  I will mull it over.

>
>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?

No I don't know why k should be 0.34


>
>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%o
>pen
>   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
>)

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to