After studying the page more closely, I get it now.

Here's what I came up with:

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=17j15":YangZhangVoly ohlc
)

As I note in my comments, the reference page calculates 2 mus - which is
usually the symbol for "mean" -
with a divisor of "n" but "n-1" matches the number of
observations, so this is really just the calculation
of the mean.

Since the page neglects to show
the limits of the summations, I also dropped the initial open and close
observation when calculating
"lnOiCi" so that I'm adding terms covering the same number of observations;
this leaves "sigmars2"
as the odd one having "n" terms summed - instead of "n-1" like the others -
but I left it alone.

In any case, I checked my answer by comparing my result on S&P 500 prices to
the value of the VIX
over the same period.  I used the correlation function "corr" from "stats"
for a range of values.  This
function
vixcorrYZ=: 4 : 0
'vixcl ohlc'=. y [ 'plen estp'=. x
((-plen-estp-1){.vixcl) corr estp (250&YangZhangVoly&.|:)\|:(-plen){."1 ohlc
)

allows me to generate a matrix by applying it to a parameter matrix thusly:

viewmat nn0=. (<"1 (45+i.90) ,"0/ 3+i.32) vixcorrYZ&><vixcl;<ohlc

using "viewmat" to look at the surface generated.  I get an interesting
surface I'll have to
analyze more to be confident that this is a good volatility estimator.

I downloaded the data from Yahoo Finance as .CSV files and read it in (using
my own
"c2m" which just reads in a CSV file to a matrix) like this:

getSPXohlc=: 0 : 0
NB. Get S&P500 Open, High, Low, Close; file from
http://finance.yahoo.com/q/hp?s=%5EGSPC.
spx=. c2m '\Data\SPX19500103-20070607.csv'
3{.spx
+----------+-------+-------+-------+-------+----------+---------+
|Date |Open |High |Low |Close |Volume |Adj Close|
+----------+-------+-------+-------+-------+----------+---------+
|2007-06-07|1517.36|1517.36|1490.37|1490.72|3538470000|1490.72 |
+----------+-------+-------+-------+-------+----------+---------+
|2007-06-06|1530.57|1530.57|1514.13|1517.38|2964190000|1517.38 |
+----------+-------+-------+-------+-------+----------+---------+

ohlc=. ".&>|:|.1 2 3 4{"1}.}: spx NB. "|."->dates old to new
$ohlc
4 14449
|:_2{."1 ohlc NB. Ensure this matches the spx text above
1530.57 1530.57 1514.13 1517.38
1517.36 1517.36 1490.37 1490.72
)

getVIXClose=: 0 : 0
NB. Get VIX data; file from http://finance.yahoo.com/q/hp?s=%5EVIX.
vix=. c2m '\Data\vix19900102-20070606.csv'
3{.vix
+----------+-----+-----+-----+-----+------+---------+
|Date |Open |High |Low |Close|Volume|Adj Close|
+----------+-----+-----+-----+-----+------+---------+
|2007-06-06|14.07|15.06|13.63|14.87|000 |14.87 |
+----------+-----+-----+-----+-----+------+---------+
|2007-06-05|13.58|14.17|13.29|13.63|000 |13.63 |
+----------+-----+-----+-----+-----+------+---------+

vixcl=. ".&>}:}.6{"1 vix NB. Get VIX close only
vixcl=. |.vixcl
)

I may put this up on the Wiki later.

On 6/7/07, Devon McCormick <[EMAIL PROTECTED]> wrote:

Just remembered that the VIX is now calculated on the S&P500.  A price
series for this can be found at
http://finance.yahoo.com/q/hp?s=%5EGSPC .

On 6/7/07, Devon McCormick <[EMAIL PROTECTED]> wrote:
>
> ...
> In any case, what answer do you get for the volatility of your made-up
> data?
>
> Even better, if you go to   http://finance.yahoo.com/q/hp?s=%5EOEX , you
> can
> download historical high, low, open and close data for the S&P 100 index
> (OEX) and
> run the calculation on real numbers.  You can then do a sanity check on
> the
> results of your calculation by comparing them to the values of the VIX -
> the
> volatility index on the OEX.  You can get VIX data at
> http://finance.yahoo.com/q/hp?s=%5EVIX .
>
> ...
>

--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail




--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to