hi, i'm new, i have some problem this fprintf('Results from optimization In Sample \n',fid); fprintf('fid,tit1'); why this code only show one solution? "filename = junk/MRSGARCH_N.txt Results from optimization In Sample fid,tit1flag1 = 1 "
3 次查看(过去 30 天)
显示 更早的评论
% File mrsgarchestfor_con_all.m % File to estimate Markov Regime-Switching GARCH % Written by Juri Marcucci % PhD student in Economics @ % Dept of Economics - UCSD % Constrained optimization: fmincon % The model is an M-state Markov Switching model with GARCH effects % Main references: Gray (1996, Journal of Financial Economics) % Klaassen (2002, Empirical Economics) % Author: Juri Marcucci % Dept. of Economics - UCSD % % Revised version: January 2011 % This program has been tested on new versions of Matlab (2008a, 2009a, 2010a).
clc clear all format compact warning off seconds=clock; %Loading data [y]=textread('coba.txt');
N = size(y,1); T=281 ; % In-Sample dataf =y ; % data to be forecast N = N - 1; clear y; %ERRORS datafm = mean(dataf); %mean of all the sample for the forecast error errors = dataf - datafm; % errors data = dataf(1:T); % In-Sample data % ERRORTYPE -> 1 = NORMAL 2 = t-DF 4 = t 1df 5 = GED 1df % In the following loop, just put 'errortype = [j]', j=(1,2,4,5) to estimate only one model reducing % the computational burden. You can leave it as it is, but it would take around 4/5 days to run everything.
for errortype = [1]; data = dataf(1:T); % In-Sample data % Initialization of the parameters % Starting values % x0(1,1) = a01; x0(2,1) = a02; x0(3,1) = b01; x0(4,1) = b02; x0(5,1) = b11; % x0(6,1) = b12; x0(7,1) = b21; x0(8,1) = b22; x0(9,1) = p; x0(10,1) = q; % x0(11,1) = \nu1; x0(12,1) = \nu2; x0=[1.5*datafm; %a01 .5*datafm; %a02 .0005; %b01 .0002; %b02 .15; %b11 .25; %b12 .6; %b21 .7; %b22 .9; %p .9 %q 4.5; %\nu1 4.5 %\nu2 ]; switch errortype case 1 %Normal x0=x0(1:10,1); case {2,3} % t & GED with 2DoF x0 = x0(1:12,1) ; case {4,5} % t and GED with 1DoF x0 = x0(1:11,1); otherwise error('Variable errortype must be integer in (1,5)') end end original_param = zeros(size(x0,1),N-T+1); VF = []; Loglike = zeros(size(x0,1),N-T+1); Exitflag = zeros(size(x0,1),N-T+1); Parameters = zeros(size(x0,1),N-T+1,11); % Parameters for the conditional mean: a01, a02, i.e. x0(1 through 2) % Parameters for the conditional variance: b01, b02, b11, b12, b21, b22, i.e. x0(3 through 8) % Parameters for the P: p, q i.e. x0(9 through 10) % Parameters for the DoF: \nu_j, j=1,2, i.e. x0(11 through 12) % Print all results in a file modelname = ['MRSGARCH_']; switch errortype case 1 distr_name = ['N']; case 2 distr_name = ['t_2DoF']; case 4 distr_name = ['t_1DoF']; case 5 distr_name = ['GED_1DoF']; otherwise end % Mac/Linux filename=strcat('junk/',modelname,distr_name,'.txt') % Windows % filename=strcat('junk\',modelname,distr_name,'.txt') fid = fopen(filename,'w'); tit1 = strcat('Model: \n',char(32),modelname,distr_name,' \n\n'); fprintf('Results from optimization In Sample \n',fid); fprintf('fid,tit1'); %%%%%%%%%%%%%%%% MAIN LOOP %%%%%%%%%%%%%%%%%%%%%%%%%%% index = 0; % time index for the rolling window constr = 0; % unconstrained paramters flag1=1 % 1 for Klaassen and 0 for Gray (default) max_forecast = 5 ; % max number of forecasts
2 个评论
Geoff Hayes
2014-8-13
dilah - please either format the above code so that it is readable, or attach the code to your question using the paperclip button. As well, please clarify what the problem is - why do you expect more than one solution?
回答(1 个)
Star Strider
2014-8-13
It is printing (or not) to your file what your code is telling it to print.
See if:
fprintf(fid, 'Results from optimization In Sample \n');
fprintf(fid, tit1);
improves things. You might have to make similar changes in your other fprintf statements.
Remember to use:
fclose('all')
at the end of your code to close all open files.
I don’t understand your code (and I don’t have the Econometrics Toolbox so I can’t run it) so that is the limit of the help I can provide.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Risk Management Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!