%检测序列x是否是均值为0的,随机游走序列,如果是随机游走序列,返回方差值,否则返回0
%模型仍然假设随机游走方差不变,且期望是0(没有飘逸项)
%参考The Extreme Value Method for Estimating the Variance of the Rate of Return
%返回样本1/n时间段内的方差值
function [parkinson1,parkinson2,test]=parkinson(x,n)
if nargin==1
n=25;
end
dis=length(x)/n;
x_max=zeros(n,1);
x_min=zeros(n,1);
j=1;
while j*dis<=length(x)
x_max(j)=max(x((round((j-1)*dis)+1):round(j*dis)));
x_min(j)=min(x((round((j-1)*dis)+1):round(j*dis)));
j=j+1;
end
l=x_max-x_min;
parkinson1=mean(l.*l)/(4*log(2));
parkinson2=mean(l)^2*pi/8;
test=2*mean(l.*l)/(log(2)*pi)/(mean(l)^2);
end
=====================================================================
%w模型参考estimating variance from high low and closing prices
%模型假设价格随机游走,方差保持不变,可以带常数项漂移
%返回结果是1/n数据长度的方差
%返回第一项是Rogers-Satchell波动率,第二项是Garman-Klass波动率(漂移项为0是使用)
function [var,vargarm]=rog_sat_var(x,n)
if nargin==1
n=30;
end
dis=length(x)/n;
x_max=zeros(n,1);
x_min=zeros(n,1);
x_t=zeros(n,1);
j=1;
while j*dis<=length(x)
x_max(j)=max(x((round((j-1)*dis)+1):round(j*dis)));
x_min(j)=min(x((round((j-1)*dis)+1):round(j*dis)));
x_t(j)=x(round(j*dis));
j=j+1;
end
var1=x_max.*(x_max-x_t)+x_min.*(x_min-x_t);