【时间序列】简单garch+arma模型,金融时间序列
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模型,金融时间序列相关推荐
- AR模型、MA(Moving Average)模型、ARMA模型、时间序列的定阶、ARIMA、SARIMAX
AR模型.MA(Moving Average)模型.ARMA模型.时间序列的定阶.ARIMA.SARIMAX 目录 AR模型.MA(Moving Average)模型.ARMA模型.时间序列的定阶.A ...
- 使用最大离散重叠小波变换MODWT和支持向量回归 SVR的金融时间序列预测
本例使用的数据链接如下:https://www.histdata.com/download-free-forex-historical-data/?/ascii/tick-data-quotes/AU ...
- arma模型_GARCH模型应用:以国泰君安为例
1.下载国泰君安股票数据,计算对数收益率 (1)首先安装包"quantmod",这个包可以从雅虎财经的下载股票数据,具体包的解释见"[量化基础]R语言获取金融数据之qua ...
- 时间序列分析ARMA模型原理及Python statsmodels实践(上)
目录 1. 时间序列及相关基本概念 1.1. 时间序列分解 1.2. 时间平稳序列 1.3. 自相关与自相关函数(ACF) 1.4. 白噪声及Ljung-Box检验 1.4.1. 白噪声 1.4.2. ...
- R语言GARCH族模型:正态分布、t、GED分布EGARCH、TGARCH的VaR分析股票指数
全文链接:http://tecdat.cn/?p=31023 如何构建合适的模型以恰当的方法对风险进行测量是当前金融研究领域的一个热门话题(点击文末"阅读原文"获取完整代码数据). ...
- Python玩转金融时间序列之ARCH与GARCH模型
01 引言 作为金融时间序列的专题推文,[手把手教你]时间序列之日期处理主要介绍了使用Python处理时间序列的日期和统计分析:[Python量化基础]时间序列的自相关性与平稳性主要介绍了时间序列的一 ...
- arch检验python_Python玩转金融时间序列之ARCH与GARCH模型
01 引言 作为金融时间序列的专题推文,[手把手教你]时间序列之日期处理主要介绍了使用Python处理时间序列的日期和统计分析:[Python量化基础]时间序列的自相关性与平稳性主要介绍了时间序列的一 ...
- 时间序列学习(3):AR、MA及ARMA模型
时间序列学习(3):AR.MA及ARMA模型 1.AR模型 2.MA模型 3.ARMA模型 上篇笔记第2节说指数的对数收益率序列近似为一个白噪声. 如果投资标的的每日收益率就是白噪声,那完全可以建立多 ...
- 金融计量模型(六):金融时间序列及其特征
文章目录 金融时间序列及其特征 正态分布 t分布 样本矩 资产收益率的样式化统计属性 金融时间序列及其特征 rrr 为随机变量: μ=E[r]σ2=var(r)=E[(r−μ)2]偏度:skew(r) ...
最新文章
- python快速小教程
- 30百度人撑起自动驾驶半壁江山
- iOS UI基础-11.0 UINavigationController
- 转]Window, Linux动态链接库的分析对比
- 机器人鸣人是哪一集_火影忍者:四个机器人,机器丁次,机械鸣人,你见过哪个...
- 张腾:腾讯云融合通信应用场景及案例分享
- css中px、em和rem的区别总结
- MTK 8127平台使用busybox
- 矩量法 惠更斯 matlab,矩量法分析振子天线粗细对天线的影响毕业设计(论文).doc...
- 《C#线程参考手册》读书笔记(三):.NET中的线程池
- 拓端tecdat|R语言分析协变量之间的非线性关系
- FLC-Regular Grammar
- python编写web漏洞扫描器_Python脚本实现Web漏洞扫描工具
- dotween路径移动_unity 移动物体到指定位置的几种方法
- linux编译gdal geos,GDAL编译支持GEOS
- yii 进入后台 inex.php,PHP应用:Yii中实现处理前后台登录的新方法
- MGF病毒的利用代码
- oracle的透明网关是什么,ORACLE透明网关的配置
- 极线的绘制(已知相机的内外参数,极线几何)
- windows查看端口占用情况
热门文章
- 东风科技php,东风科技(600081)违规记录_新浪财经_新浪网
- hadoopsdk使用_Hadoop的一些基本操作
- boot spring 启动 文本_springboot 选择启动某个配置文件
- 通用mapper_通用Mapper快速开发,搭建项目
- F - Wormholes(判断是否存在负环)
- Ubuntu——运维的学习笔记
- 使用transforms.Normalize((0.5,), (0.5,))异常报错“Process finished with exit code -1073741676 (0xC0000094)”
- 用计算的方式,求两个数之间的最大值和最小值
- hihocoder第229周:最大连续字母个数
- Unity3D_(游戏)卡牌03_选关界面