volaplot.m

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

M
34
字号
function v=volaplot(x,n)
%VOLAPLOT Volatility plot.
%   VOLAPLOT(X,N) plots volatility of times series X averaged over N 
%   periods (eg. days).
%   V=VOLAPLOT(X,N) instead of plotting returns the volatility series.

%   Written by Rafal Weron (2000.12.15)
%   Copyright (c) 2000-2006 by Rafal Weron

x = x(:);
Lx = length(x);
k = floor(n/2);

if n/2 == k,
    if nargout == 0,
        disp(['Volatility calculated over ' num2str(n-1) ' periods']);
    end
    n = n-1;
    k = floor(n/2);
end;

xx = [ones(k,1)'*x(1) x' ones(k,1)'*x(Lx)]';

v = zeros(Lx,1);
for i = 1:Lx,
    v(i) = std(xx(i:i+n-1));
end;

if nargout == 0,
    plot(1:Lx,x,1:Lx,v)
    s = [num2str(n) '-day volatility'];
    legend('Times series',s)
end;

⌨️ 快捷键说明

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