matlab做数据间方差,用matlab做方差比检验的问题

本文提供了一个用于计算时间序列方差比检验的MATLAB函数,包括同方差和异方差条件下的统计量。该函数接收时间序列数据及参数k作为输入,输出方差比及其对应的统计量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下的这个程序是用来做方差比检验的m-file 大家看看有问题么

我跑出来的结果只有一个数,而我要得到两个数的,即同方差和异方差下的方差比

function [VR,Zk,Zhk]=vrt_full(x,k)

%

% Syntax: [vr,zk,zhk]=vrt(x,k)

%

% Calculates the Variance Ratio Test (VR Test) of a time series x, with

% and without the heteroskedasticity assumption.

% input  : x is a vector of time serie (observed prices)

%          k is a scalar

% output : VR is the value of the VRTest

%          Zk is the homoscedastic statistic of the variance ratio

%          Zhk is the heteroscedastic statistic of the variance ratio

%

x=xlsread('D:\A股\数\book1.xls');

k=2;

rt1=diff(x); % one period rate of return

T=length(rt1);

i=1:T-k+1;

M=zeros(T-k+1,k);

for j=1:k,

M(:,j)=i+j-1;

end

rtk=sum(rt1(M'));  % k period rate of return

moy=mean(rt1);

v=var(rt1);

m=k*(T-k+1)*(1-k/T);

VR=1/m*sum((rtk-k*moy).^2)/v; % Variance ratio statistic

Zk=sqrt(T)*(VR-1)*(2*(2*k-1)*(k-1)/(3*k))^(-.5); % homoscedastic statistic

j=1:k-1;

vec1=(2/k*(k-j)).^2;

rst=(rt1-moy).^2;

aux=zeros(1,k-1);

for i=1:k-1,

aux(i)=rst(i+1:T)'*rst(1:T-i);

end

vec2=aux/((T-1)*v)^2;

Zhk=(VR-1)*(vec1*vec2')^(-.5); % heteroscedastic statistic

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值