全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件
4874 4
2015-02-08

function [Z] = ARFIMA_SIM(N,F,O,d,stdx,er)

%The code performs the simulation of time series with autoregressive

%fractionally integrated moving average (ARFIMA) models that generalize

%ARIMA (autoregressive integrated moving average) and ARMA autoregressive

%moving average models.  ARFIMA models allow non-integer values of the

%differencing parameter and are useful in modeling time series with long memory.

%The model is generally represented  as ARFIMA(p,d,q) model where d is the differencing parameter

%and p and q are the order of the autoregressive and moving average parts of the model respectively.


%%% INPUTS

%%%->N =  # % Length of the time series we would like to generate  

%%%->F = [ F1 F2 F3 .... ] % Parameters of the AR model, length(F) is the order p. Default p = 0

%%%->O = [ O1 O2 O3 .... ] % Parameters of the MA model, length(O) is the order q. Default q = 0   

%%%->d = # ; % Fractionally differencing parameter, default d = 0

%%%->stdx = % Optional input: parameter to force the standard deviation of the

%output time series. Impose std(Z)==stdx   

%%%-->er = % Optional input: predefined time ser

%%%%%%%%% THE ARFIMA PROCESS IS DEFINED AS:  

%%%% F(B)[(1-B)^d]Z=O(B)er

%%%% F(B)Z=[(1-B)^-d]O(B)er

%%%%%%% where B is the backshift operator,

%%%% F(B)= 1+ B F1 + B^2 F2 ... + B^p Fp --> AR PART

%%%% O(B)= 1+ B O1 + B^2 O2 ... + B^q Oq --> MA PART  

%%%% er = white noise, it can be specified as an input

%%% Note that F(B) and O(B) are both defined with plus sign as in the "armax" function of matlab

%and in  Box et al., (1994).

%%% OUTPUTS

%-->Z =  Time series simulated with the ARFIMA mo

%%%%%%%%%% EXAMPLES

%%% White noise

%[Z] = ARFIMA_SIM(N);

%%% AR(1) model

%[Z] = ARFIMA_SIM(N,[F1]);

%%% MA(1) model

%[Z] = ARFIMA_SIM(N,[],[O1])

%%% ARMA(2,2) model

%[Z] = ARFIMA_SIM(N,[F1,F2],[O1,O2])

%%% ARFIMA(0,d,0)

%[Z] = ARFIMA_SIM(N,[],[],d)

%%% ARFIMA(1,d,1)

%[Z] = ARFIMA_SIM(N,[F1],[O1],d)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%   Simone Fatichi -- simonef@dicea.unifi.it

%   Copyright 2009

%   $Date: 2009/10/19 $

%%%inizialization

X=zeros(1,N); Y=zeros(1,N); Z=zeros(1,N);

%%%% FI(B)[(1-B)^d]Z=O(B)e

%%%% FI(B)Z=[(1-B)^-d]O(B)e

%%%% FI(B)= 1+ B F1 + B^2 F2 ...

%%%% O(B) = 1+ B O1 + B^2 O2 ...

switch nargin

    case 1

        d=0;

        F=[];

        O=[];

        t=0;

        stdx=NaN;

    case 2

        d = 0;

        O =[];

        t = 0;

        stdx=NaN;

    case 3

        d = 0;

        t=0;

         stdx=NaN;

    case 4

        t=0;

         stdx=NaN;

    case 5

        t=0;

    case 6

        t=1;

    otherwise

        msgbox('ERROR: Not enough or too much input arguments')

        Z=[];

        return

end

e=normrnd(0,1,N,1);

if t==1

    e=er;

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if isempty(O) && isempty(F) && (d==0)

    Z=e;

    return

end

%%%%% N =length

MA_ord=length(O);

AR_ord=length(F);

%%%%%%%%%%%% Computing part: MA(q)

t=0;

if MA_ord >= 1

    for t=1:N

        j=0;map=0;

        for j=1:MA_ord

            if t > j

                map = map + O(j)*e(t-j);

            end

        end

        X(t)= e(t)+ map;

    end

else

    X=e;

end

t=0;

%%%%%%%%%%% Computing part: d

if d == 0

    Y=X;

else

    infi =100; s=0;

    for s=0:infi

        %b(s+1)=((-1)^s)*gamma(-d+1)./(gamma(s+1)*gamma(-d-s+1));

        b(s+1)=gamma(s+d)/(gamma(s+1)*gamma(d));

    end

    for t=1:N

        Y(t)=0;

        for s=0:infi

            if t > s

                Y(t)= Y(t)+ b(s+1)*X(t-s);

            end

        end

    end

end

%%%%%%%%%%%%% Computing part: AR(p)

t  = 0;

if AR_ord >= 1

    for t=1:N

        j=0; arp=0;

        for j=1:AR_ord

            if t > j

                arp = arp - F(j)*Z(t-j);

            end

        end

        Z(t)= Y(t)+ arp;

    end

else

    Z=Y;

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Z=Z';

if not(isnan(stdx))

    Z=Z*stdx/std(Z);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

end


下载地址:http://www.mathworks.com/matlabcentral/fileexchange/?search_submit=fileexchange&query=ARFIMA&term=ARFIMA  第一个就是。


已经有122个RV数据 想做lnRV-ARFIMA模型,但是不知道怎么用这个模型。


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-2-9 09:33:43
你首先需要对数据进行处理,取对数,然后选择ARIMA模型来进行拟合,得到AR,MA的参数及取差分的次数之后,再代入到函数中,如:
F=[0.1 0.2 0.3];
>> O=[0.2 0.4 0.6];
ARFIMA_SIM(10,F,O,1)
结果: -1.3499
    1.5500
    2.3225
    2.5563
    4.3217
    4.2146
    3.8851
    5.2215
    6.7202
    8.6223
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2017-1-22 10:56:40
有所受用,多谢。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2017-5-14 23:29:25
求教求教 同要用ARFIMA模型 不知道要怎么带数据进去
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-3-7 15:41:35
1. 这是一个ARFIMA数据生成代码,非参数估计
2. 参数估计可以采用非线性最小二乘,只要想明白分整(1-L)^d操作,很容易matlab实现
3.ARFIMA可以和GARCH族、SV族结合,不断扩展。不过再怎么变最后的估计都是参数寻优,只要ARFIMA(0,d,0)会了,可举一反三
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群