matlab->garch+arma模型,金融时间序列模型

  • 1. 原理
    • 1.1 代码参考
  • 2. 代码脚本
    • 2.1 数据处理
    • 2.2 ARMA
    • 2.3 garch

1. 原理

在网上看到zhihu上有个很好的专栏在这里码一下:

  • 基础篇:https://zhuanlan.zhihu.com/p/38320827
  • 初级篇:https://zhuanlan.zhihu.com/p/38321845
  • 进阶篇:https://zhuanlan.zhihu.com/p/38322333
  • 应用篇:https://zhuanlan.zhihu.com/p/38322638
  • 补完篇:https://zhuanlan.zhihu.com/p/77307871

1.1 代码参考

使用ARMA做时间序列预测全流程:https://zhuanlan.zhihu.com/p/69630638

matlab官网的economic 工具箱的实例:
https://ww2.mathworks.cn/discovery/garch-models.html
https://ww2.mathworks.cn/help/releases/R2013a/econ/arima.forecast.html
https://ww2.mathworks.cn/help/econ/conditional-variance-models.html
https://ww2.mathworks.cn/help/econ/garch-model.html
等等

2. 代码脚本

2.1 数据处理


clear;
close all;%% 一、数据处理
% 1.ascii2fts导入数据,要求数据大于100期,必须显示前五期时间序列数据;
% ascii2fts无法选择读取列,先处理了一下
dis = ascii2fts('000157.txt');
dis = chfield(dis, {'series1','series2','series3','series4'},{'Open','High','Low','Close'});% 2.利用candle函数显示前100期数据;
figure;
% candle(dis(1:100));
dis.freq = 1;                              %指明为日数据
ftsma5 = filter(ones(1,5)/5,1,dis);         %计算5日移动平均
ftsma10 = filter(ones(1,10)/10,1,dis);      %计算10日移动平均
ftsclose5 = ftsma5.Close;                   %提取5日收盘平均
ftsclose10 = ftsma10.Close;                 %提取10日收盘平均
candle(dis(10:100));                        %绘制蜡烛图
hold on;                                    %保持图形窗口
plot(ftsclose5(10:100), 'k');         %绘制5日均线
plot(ftsclose10(10:100), 'r');            %绘制10日均线title("中联重科(000157)");% 3.利用fts2mat转换成矩阵,并提取收盘序列;
mat = fts2mat(dis);
close_data = mat(:,4);% 4.利用price2ret转换成收益率序列,绘制收益率折线图;
[Returns,~] = price2ret(close_data);figure;
plot(Returns, 'b');
axis on; grid on;
set(gca,'gridlinestyle',':','GridAlpha',.8);
title("Returns Plot");% 5.单位根检验。
h_adf = adftest(Returns);
h_kpss = kpsstest(Returns);% r_temp = diff(Returns);   % 一阶差分

2.2 ARMA


%% 二、ARMA模型分析
% 1、用autocorr进行自相关分析;
% 2、用parcor进行偏相关分析;
figure;
subplot(2,1,1);
autocorr(Returns);
subplot(2,1,2);
parcorr(Returns);% 3、分析运行结果,进行定阶,如果不能直接定阶,利用函数armax进行估计,并利用函数
%   fpe计算最终预报误差,选择最小fpe的阶作为ARMA模型的阶;% 4、估计ARMA模型参数,写出最终的ARMA模型
% data = iddata(Returns);
% modelAR = ar(data, na);
% modelMA = armax(data, nc);[na,nc,m] = demoarmax(Returns,4,4);Mdl = arima(na, 0, nc);
EstMdl = estimate(Mdl,Returns);
[res,~,logL] = infer(EstMdl,Returns);stdr = res/sqrt(EstMdl.Variance);
figure('Name','残差检验');
subplot(2,3,1);
plot(stdr);
title('Standardized Residuals');
subplot(2,3,2);
histogram(stdr,10);
title('Standardized Residuals');
subplot(2,3,3);
autocorr(stdr);
subplot(2,3,4);
parcorr(stdr);
subplot(2,3,5);
qqplot(stdr);m = armax(iddata(Returns),'na',na,'nc',nc);%% 三、GARCH模型分析【不估计均值方程,估计方差方程,这就要选取好的数据(单位根检验做不下去,
%      可以重新找数据或直接做),不可能有Garch阶为0,ARCH为1,模型矫正为科幻为Garch(1,2)/Garch(2,1)】% 1、GARCH(1,1)模型估计;
% 1.1、选择一个或多个模型,如garch(1,1)、garch(2,1)
% spec11 = garchset('P',1,'Q',1,'Display','off');% spec11 = garch('Offset',NaN,'GARCHLags',1,'ARCHLags',1);
spec11 = garch(1,1);
% spec11.Offset = NaN;spec21 = garch(2,1);
spec21.Offset = NaN;% 1.2、估计模型参数根据数据对每个模型进行参数估计。
% [Coeff11,Errors11,LLF11,Innovations11,Sigmas11] = garchfit(spec11,Returns);
[est11,~,LogL11] = estimate(spec11, Returns);
[est21,~,LogL21] = estimate(spec21, Returns);
% garchplot(Innovations11,Sigmas11,dem2gbp);% garchdisp(Coeff11,Errors11);
disp(est11);% 1.3、利用合适的评估方法选择合适的模型
[h,p] = lratiotest(LogL21,LogL11,1,0.05);
[h,p] = lratiotest(LogL21,LogL11,1,0.02);% 赤池信息准则(AIC)和贝叶斯信息准则(BIC)检验模型
% format long;
% n11 = garchcount(Coeff11);
% n21 = garchcount(Coeff21);% n11 = sum(any(Coeff11));
% n21 = sum(any(Coeff21));
%
% [AIC11,BIC11] = aicbic(LLF11,n11,1974);
% [AIC21,BIC21] = aicbic(LLF21,n21,1974);
% disp([AIC11,BIC11; AIC21,BIC21]);

2.3 garch

% 2、GARCH仿真;【一定要做对比】
%%
rng default; % For reproducibility
[V,Y] = simulate(est11,100,'NumPaths',20);figure;
subplot(2,2,1);
plot(V);
title('est11-Simulated Conditional Variances');subplot(2,2,2);
plot(Y);
title('est11-Simulated Responses');[V,Y] = simulate(est21,100,'NumPaths',20);subplot(2,2,3);
plot(V);
title('est21-Simulated Conditional Variances');subplot(2,2,4);
plot(Y);
title('est21-Simulated Responses');%%
numObs = numel(Returns); % Sample size (T)
numPaths = 100;     % Number of paths to simulate
rng(1);             % For reproducibility
[VSim,YSim] = simulate(est21,numObs,'NumPaths',numPaths);VSimBar = mean(VSim,2);
VSimCI = quantile(VSim,[0.025 0.975],2);
YSimBar = mean(YSim,2);
YSimCI = quantile(YSim,[0.025 0.975],2);figure;
subplot(2,1,1);
h1 = plot(VSim,'Color',0.8*ones(1,3));
hold on;
h2 = plot(VSimBar,'k--','LineWidth',2);
h3 = plot(VSimCI,'r--','LineWidth',2);
hold off;
title('Simulated Conditional Variances');
ylabel('Cond. var.');
xlabel('Year');subplot(2,1,2);
h1 = plot(YSim,'Color',0.8*ones(1,3));
hold on;
h2 = plot(YSimBar,'k--','LineWidth',2);
h3 = plot(YSimCI,'r--','LineWidth',2);
hold off;
title('Simulated Nominal Returns');
ylabel('Nominal return (%)');
xlabel('Year');
legend([h1(1) h2 h3(1)],{'Simulated path' 'Mean' 'Confidence bounds'},...'FontSize',7,'Location','NorthWest');
%%
% 3、GARCH预测。【最多预测五期】
% [v,y] = simulate(est11,100);
% vF1 = forecast(est11,30,'Y0',y);
% vF2 = forecast(est11,30);
%
% figure;
% plot(v,'Color',[.7,.7,.7]);
% grid on;
% hold on;
% plot(101:130,vF1,'r','LineWidth',2);
% plot(101:130,vF2,':','LineWidth',2);
% title('Forecasted Conditional Variances');
% legend('Observed','Forecasts with Presamples',...
%       'Forecasts without Presamples');
% hold off;[v,y] = simulate(est11,100);
vF1 = forecast(est11,5,'Y0',y);
vF2 = forecast(est11,5);figure;
plot(v,'Color',[.7,.7,.7]);
grid on;
hold on;
plot(101:105,vF1,'r','LineWidth',2);
plot(101:105,vF2,':','LineWidth',2);
title('Forecasted Conditional Variances');
legend('Observed','Forecasts with Presamples',...'Forecasts without Presamples');
hold off;

【时间序列】简单garch+arma模型,金融时间序列相关推荐

  1. AR模型、MA(Moving Average)模型、ARMA模型、时间序列的定阶、ARIMA、SARIMAX

    AR模型.MA(Moving Average)模型.ARMA模型.时间序列的定阶.ARIMA.SARIMAX 目录 AR模型.MA(Moving Average)模型.ARMA模型.时间序列的定阶.A ...

  2. 使用最大离散重叠小波变换MODWT和支持向量回归 SVR的金融时间序列预测

    本例使用的数据链接如下:https://www.histdata.com/download-free-forex-historical-data/?/ascii/tick-data-quotes/AU ...

  3. arma模型_GARCH模型应用:以国泰君安为例

    1.下载国泰君安股票数据,计算对数收益率 (1)首先安装包"quantmod",这个包可以从雅虎财经的下载股票数据,具体包的解释见"[量化基础]R语言获取金融数据之qua ...

  4. 时间序列分析ARMA模型原理及Python statsmodels实践(上)

    目录 1. 时间序列及相关基本概念 1.1. 时间序列分解 1.2. 时间平稳序列 1.3. 自相关与自相关函数(ACF) 1.4. 白噪声及Ljung-Box检验 1.4.1. 白噪声 1.4.2. ...

  5. R语言GARCH族模型:正态分布、t、GED分布EGARCH、TGARCH的VaR分析股票指数

    全文链接:http://tecdat.cn/?p=31023 如何构建合适的模型以恰当的方法对风险进行测量是当前金融研究领域的一个热门话题(点击文末"阅读原文"获取完整代码数据). ...

  6. Python玩转金融时间序列之ARCH与GARCH模型

    01 引言 作为金融时间序列的专题推文,[手把手教你]时间序列之日期处理主要介绍了使用Python处理时间序列的日期和统计分析:[Python量化基础]时间序列的自相关性与平稳性主要介绍了时间序列的一 ...

  7. arch检验python_Python玩转金融时间序列之ARCH与GARCH模型

    01 引言 作为金融时间序列的专题推文,[手把手教你]时间序列之日期处理主要介绍了使用Python处理时间序列的日期和统计分析:[Python量化基础]时间序列的自相关性与平稳性主要介绍了时间序列的一 ...

  8. 时间序列学习(3):AR、MA及ARMA模型

    时间序列学习(3):AR.MA及ARMA模型 1.AR模型 2.MA模型 3.ARMA模型 上篇笔记第2节说指数的对数收益率序列近似为一个白噪声. 如果投资标的的每日收益率就是白噪声,那完全可以建立多 ...

  9. 金融计量模型(六):金融时间序列及其特征

    文章目录 金融时间序列及其特征 正态分布 t分布 样本矩 资产收益率的样式化统计属性 金融时间序列及其特征 rrr 为随机变量: μ=E[r]σ2=var(r)=E[(r−μ)2]偏度:skew(r) ...

最新文章

  1. python快速小教程
  2. 30百度人撑起自动驾驶半壁江山
  3. iOS UI基础-11.0 UINavigationController
  4. 转]Window, Linux动态链接库的分析对比
  5. 机器人鸣人是哪一集_火影忍者:四个机器人,机器丁次,机械鸣人,你见过哪个...
  6. 张腾:腾讯云融合通信应用场景及案例分享
  7. css中px、em和rem的区别总结
  8. MTK 8127平台使用busybox
  9. 矩量法 惠更斯 matlab,矩量法分析振子天线粗细对天线的影响毕业设计(论文).doc...
  10. 《C#线程参考手册》读书笔记(三):.NET中的线程池
  11. 拓端tecdat|R语言分析协变量之间的非线性关系
  12. FLC-Regular Grammar
  13. python编写web漏洞扫描器_Python脚本实现Web漏洞扫描工具
  14. dotween路径移动_unity 移动物体到指定位置的几种方法
  15. linux编译gdal geos,GDAL编译支持GEOS
  16. yii 进入后台 inex.php,PHP应用:Yii中实现处理前后台登录的新方法
  17. MGF病毒的利用代码
  18. oracle的透明网关是什么,ORACLE透明网关的配置
  19. 极线的绘制(已知相机的内外参数,极线几何)
  20. windows查看端口占用情况

热门文章

  1. 东风科技php,东风科技(600081)违规记录_新浪财经_新浪网
  2. hadoopsdk使用_Hadoop的一些基本操作
  3. boot spring 启动 文本_springboot 选择启动某个配置文件
  4. 通用mapper_通用Mapper快速开发,搭建项目
  5. F - Wormholes(判断是否存在负环)
  6. Ubuntu——运维的学习笔记
  7. 使用transforms.Normalize((0.5,), (0.5,))异常报错“Process finished with exit code -1073741676 (0xC0000094)”
  8. 用计算的方式,求两个数之间的最大值和最小值
  9. hihocoder第229周:最大连续字母个数
  10. Unity3D_(游戏)卡牌03_选关界面