SRISK finance-network 的程序;他分享在MATHWORK 公司的程序分享网站以及github网站。
前后有好几个版本,四月份我下载的其他版本。然后最新的这个版本,还可以计算 finance risk spillover 金融风险溢出。
三个代码:第一个为这个版本的主程序 run 里的代码;只给大家看,这个程序不一定能运行到最后,而且电脑最后是6核16G内存的,比如我的4核4G内存的电脑就无法运行第三部分 金融分享溢出。
第二个代码和第三个代码是上一个版本的,我不上传,因为有朋友的数据,我只发给他修改的主程序。大家对比看自己怎么修改主程序。
Tommaso Belluzzo ,意大利人,他这个系列的程序都是用 run.m 代表调用工具箱。
第一个代码,请参阅。
- warning('off','all');
- spmd
- warning('off','all')
- end
- close('all');
- clearvars();
- clc();
- delete(allchild(0));
- [path_base,~,~] = fileparts(mfilename('fullpath'));
- if (~strcmpi(path_base(end),filesep()))
- path_base = [path_base filesep()];
- end
- if (~isempty(regexpi(path_base,'Editor')))
- path_base_fs = dir(path_base);
- is_live = ~all(cellfun(@isempty,regexpi({path_base_fs.name},'LiveEditorEvaluationHelper')));
- if (is_live)
- pwd_current = pwd();
- if (~strcmpi(pwd_current(end),filesep()))
- pwd_current = [pwd_current filesep()];
- end
-
- while (true)
- answer = inputdlg('It looks like the program is being executed in a non-standard mode. Please, confirm or change the root folder of this package:','Manual Input Required',1,{pwd_current});
-
- if (isempty(answer))
- return;
- end
-
- path_base_new = answer{:};
- if (isempty(path_base_new) || strcmp(path_base_new,path_base) || strcmp(path_base_new(1:end-1),path_base) || ~exist(path_base_new,'dir'))
- continue;
- end
-
- path_base = path_base_new;
-
- break;
- end
- end
- end
- if (~strcmpi(path_base(end),filesep()))
- path_base = [path_base filesep()];
- end
- paths_base = genpath(path_base);
- paths_base = strsplit(paths_base,';');
- for i = numel(paths_base):-1:1
- path_current = paths_base{i};
- if (~strcmp(path_current,path_base) && isempty(regexpi(path_current,[filesep() 'Scripts'])))
- paths_base(i) = [];
- end
- end
- paths_base = [strjoin(paths_base,';') ';'];
- addpath(paths_base);
- dataset = fullfile(path_base,['Datasets' filesep() 'Example_Large.xlsx']);
- data = parse_dataset(dataset);
- out_temp_stochastic = fullfile(path_base,['Templates' filesep() 'TemplateStochastic.xlsx']);
- out_file_stochastic = fullfile(path_base,['Results' filesep() 'ResultsStochastic.xlsx']);
- result_stochastic = run_stochastic(data,out_temp_stochastic,out_file_stochastic,0.95,0.40,0.08,0.40,true);
- mat_stochastic = fullfile(path_base,['Results' filesep() 'DataStochastic.mat']);
- save(mat_stochastic,'result_stochastic');
- pause(2);
- out_temp_connectedness = fullfile(path_base,['Templates' filesep() 'TemplateConnectedness.xlsx']);
- out_file_connectedness = fullfile(path_base,['Results' filesep() 'ResultsConnectedness.xlsx']);
- result_connectedness = run_connectedness(data,out_temp_connectedness,out_file_connectedness,252,0.05,true,0.06,true);
- mat_connectedness = fullfile(path_base,['Results' filesep() 'DataConnectedness.mat']);
- save(mat_connectedness,'result_connectedness');
- pause(2);
- out_temp_spillover = fullfile(path_base,['Templates' filesep() 'TemplateSpillover.xlsx']);
- out_file_spillover = fullfile(path_base,['Results' filesep() 'ResultsSpillover.xlsx']);
- result_spillover = run_spillover(data,out_temp_spillover,out_file_spillover,252,2,4,true,true);
- mat_spillover = fullfile(path_base,['Results' filesep() 'DataSpillover.mat']);
- save(mat_spillover,'result_spillover');
- mat_dataset = fullfile(path_base,['Results' filesep() 'Dataset.mat']);
- save(mat_dataset,'data');
后面两个我将演示修改主程序,下载ZIP 文件的人记得修改 run.m
- warning('off','all');
- close('all');
- clearvars();
- clc();
- delete(allchild(0));
- [path_base,~,~] = fileparts(mfilename('fullpath'));
- if (~strcmpi(path_base(end),filesep()))
- path_base = [path_base filesep()];
- end
- paths_base = genpath(path_base);
- addpath(paths_base);
- path_dset = strrep('Datasets\Example.xlsx','\',filesep()); % 修改这里替换为你的表格文件名字
- path_rpro = strrep('Results\ResultsPRO.xlsx','\',filesep());
- path_rnet = strrep('Results\ResultsNET.xlsx','\',filesep());
- data = parse_dataset(fullfile(path_base,path_dset));
- main_pro(data,fullfile(path_base,path_rpro),0.95,0.40,0.08,true);
- pause(2);
- main_net(data,fullfile(path_base,path_rnet),0.05,true,true);
- save('data.mat','data');
- rmpath(paths_base);
第二个文件17行我已经注释修改为你的数据文件哪里修改 excel 表格文件名字即可。这里我发一个修改的给你们看,当然没数据。
- warning('off','all');
- close('all');
- clearvars();
- clc();
- delete(allchild(0));
- [path_base,~,~] = fileparts(mfilename('fullpath'));
- if (~strcmpi(path_base(end),filesep()))
- path_base = [path_base filesep()];
- end
- paths_base = genpath(path_base);
- addpath(paths_base);
- path_dset = strrep('Datasets\weiFinanceData.xlsx','\',filesep()); % 修改这里替换为你的表格文件名字
- path_rpro = strrep('Results\wei20190825ResultsPRO.xlsx','\',filesep()); % 修改这里保存为另外的CoVaR结果表格名字
- path_rnet = strrep('Results\wei20190825ResultsNET.xlsx','\',filesep()); % 修改这里保存为另外的金融网络表格文件名字
- data = parse_dataset(fullfile(path_base,path_dset));
- main_pro(data,fullfile(path_base,path_rpro),0.95,0.40,0.08,true);
- pause(2);
- main_net(data,fullfile(path_base,path_rnet),0.05,true,true);
- save('weidata.mat','data');
- rmpath(paths_base);