rollingvol.m

来自「Modeling and Forecasting Electricity Loa」· M 代码 · 共 35 行

M
35
字号
function vyear=rollingvol(x,N1,N2);
%ROLLINGVOL Annual rolling volatility.
%   VYEAR=ROLLINGVOL(X,N1,N2) returns the annual (i.e. of length 365), 
%   averaged rolling volatility for vector X of daily data, see [1], 
%   Section 2.4.5. N1 is the length of the rolling volatility vector and 
%   N2 of the moving average (default values: N1=N2=25). Note, that only 
%   first (365*D + 1), where D is an integer, values of the input vector X 
%   are used.
%
%   Reference(s):
%   [1] R.Weron (2007) "Modeling and Forecasting Electricity Loads and 
%   Prices: A Statistical Approach", Wiley, Chichester.   

%   Written by Rafal Weron (2006.09.22)
%   Copyright (c) 2006 by Rafal Weron

% Define default length of the moving average 
if nargin<3,
    N2 = 25;
end
% Define default length of the rolling volatility vector
if nargin<2,
    N1 = 25;
end

% Select first (365*D + 1) values of the input vector
D = floor(length(x)/365);
x = x(1:D*365+1);

%  Compute the N1-day rolling volatility
v = volaplot(logret(x),N1);

%  Smooth the averaged annual volatility by taking a N2-day MA 
vyear = average(mean((reshape(v,365,D))'),ones(N2,1),1);
vyear = vyear(:);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?