蒙特卡洛模拟与matlab,用MATLAB进行蒙特卡洛模拟?

%% This program is writed by Danniel tulip lew

%   Danny have this program`s copyright  @2010

%% The first step:Loading data to whcih will be used to analysis

CleanUp;

load mygarchdata

markpound = SSret;

figure

plot(markpound)

title('市场序列')

adfval = adftest(SSret);

disp('The test value of Augmented Dickey-Fuller test for unit root');

disp('------------------------------------------------------------');

disp(adfval)

kpssval = kpsstest(SSret);

disp('The test value of kpsstes');

disp('---------------------------');

disp(kpssval)

[h,pValue,stat,cValue] = archtest(SSret,1:5,0.01);

disp('Engle test for residual heteroscedasticity');

disp('---------------------------------------------');

disp(h)

disp('----------------------------------------------');

disp(pValue);

%% Bulding GARCH Model and fit the parameters

spec = garchset('VarianceModel','GJR','R',1,'M',1,'P',1,'Q',1);

spec = garchset(spec,'Display','off','Distribution','T');

[coeff,errros,LLF,~,~] = garchfit(spec,markpound);

[eFit,sFit] = garchinfer(coeff,markpound);

spec11=garchset;

spec11=garchset(spec11,'Display','off');

[coeff1,erros1,LLF1,eFit1,sFit1]=garchfit(spec11,markpound);

%% Monte carlo simulation and visulise the simulation result using

horizon = 30;

nPaths = 10000;

strm = RandStream('mt19937ar','Seed',5489);

RandStream.setDefaultStream(strm);

[eSim,sSim,ySim] = garchsim(coeff,horizon,nPaths,[],[],[],eFit,sFit,markpound);

Y=ret2tick(ySim);

[eSim1,sSim1,ySim1]=garchsim(coeff1,horizon,nPaths,[],[],[],eFit1,sFit1,markpound);

Y1=ret2tick(ySim1);

% plot result

figure

subplot(2,1,1),plot(Y)

subplot(2,1,2),plot(Y1)

%% Garch simulation and garch predict

NumPeriods=30;

fprintf('Garchpred result: Sigma and Mena\n');

[SigmaForecast,MeanForecast,sigmaTotal,meanRMSE] = ...

garchpred(coeff,markpound,NumPeriods);

disp('Sigma')

disp(SigmaForecast)

disp('Mean')

disp(MeanForecast)

%% Standardized residuel

figure

autocorr(markpound);

% Compare Sigmas

figure

plot(SigmaForecast,'.-b')

hold('on')

grid('on')

plot(sqrt(mean(sSim.^2,2)),'.r')

title('Forecast of STD of Residuals')

legend('forecast results','simulation results')

xlabel('Forecast Period')

ylabel('Standard Deviation')

% Compare Returns

figure

plot(MeanForecast,'.-b')

hold('on')

grid('on')

plot(mean(ySim,2),'.r')

title('Forecast of Returns')

legend('forecast results','simulation results',4)

xlabel('Forecast Period')

ylabel('Return')

% Compare Standard Errors

figure

plot(meanRMSE,'.-b')

hold('on')

grid('on')

plot(std(ySim'),'.r')

title('Standard Error of Forecast of Returns')

legend('forecast results','simulation results')

xlabel('Forecast Period')

ylabel('Standard Deviation')

%% Hypothesis test: | lrationtest |

% A likelihood ratio test is another way to compare the model which is

% beest

[H,pValue]=lratiotest(LLF,LLF1,1);

fprintf('Result of the GARCH model compare using "lrationtest"\n');

if H==0

disp('The GARCH(1,1) model is suported at the 5% significant level')

else

disp('The GJR(1,1) model is suported at the 5% significant level')

end

%-----------------------------EOF------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值