function [ FCVARoptions ] = DefaultEstnOptions(db0, k, r, p)
% 
% function [ FCVARoptions ] = DefaultEstnOptions(db0, k, r, p)
% Lee Morin & Morten Nielsen
% August 26, 2011
%
% 
% DefaultEstnOptions(db0, k, r, p) returns a set of preliminary setings
%       corresponding to the default set of options specified below.
% 
% These options are later processed by AdjustEstnOptions(db0, k, r, p, initialFCVARoptions),
%       which completes the specification of the options array.
% 
% 
% input = vector or scalar db0 of fractional differencing parameters.
%       The size of db0 indicates whether or not restriction d = b is imposed
%           based on the number of free parameters.
%       scalars k, r and p denote the number of lags, cointegrating rank
%           and the number of variables, respectively.
% 
% 
% output = cell array FCVARoptions of options for use in estimation routines.
% 
% FCVARoptions = { dbEstnOptions, EstnOptions }, an array of 2 arrays.
% 
% dbEstnOptions is an array of options for the estimation of the fractional differencing parameters d and b.
% dbEstnOptions = { constrained, C_db, c_db, R_db, r_db, dbFminOptions }
%   constrained is an indicator for the restriction that dbMax >= d >= b >= dbMin.
%   C_db and c_db are the matrices that specify the above restriction.
%   dbMax is an upper bound for the estimation of d and b.
%   dbMin is a lower bound for the estimation of d and b.
%   R_db and r_db are optional matrices for defining restrictions of the form R_db*db = r_db.
%       These are left blank in the default model.
%   dbFminOptions is an array of options for built-in matlab (numerical optimization) 
%		functions for the optimization over d and b.
% 
% EstnOptions is a cell array of options for estimating the remaining parameters.
% EstnOptions = { N, M, deterministics, R_Gamma, r_Gamma, [], [], [],
%                   nCols, A, H, a, b, [], {}, {}, {}, {},
%                   [], [], [], print2screen, printGammas, printRoots
%                   restrictFminOptions }
%   scalar N is the number of initial values of x that are conditioned upon in the estimation.
%   scalar M is the number of MA lags in the fractional differencing operator.
%       If M is positive, the fractional differencing filter is truncated at lag M.
%   string deterministics is a switch to determine if, eg. a 'restricted constant'
%       term should be added to the model.
%   R_Gamma and r_Gamma are optional matrices for defining restrictions of the
%       form R_Gamma*Gamma = r_Gamma (intended for exclusion restrictions only).
%       These are left blank in the default model, but are used in RestrictEstnOptions.
%   nCols, A, H, a, b are optional matrices for use when estimating with
%       Johansens's switching algorithm.
%       These are left blank in the default model, but are used in RestrictEstnOptions.
%   print2screen is a scalar indicator to print results (in RankTests and FCVARestn) 
%      to screen and to generate graphs of characteristic roots.
%   printGammas is a scalar indicator to print coefficients of lagged differences as well.
%   printRoots is a scalar indicator to also print and plot roots of the characteristic polynomial.
%   restrictFminOptions is an array of options for optimization over alpha and beta in the 
%       switching algorithm implemented in GetParamsSwitching.
%______________________________________________________



% Add the folder containing FCVARtools to the Matlab search path.
pathToFCVARtools = sprintf('%s\\FCVARtools',pwd);
path(path, pathToFCVARtools);

% Set numerical optimization settings for the optimization over d and b.
% A switching algorithm is implemented in case [ alpha, beta, or rho ] are restriced.

% Specify options for matlab optimization functions.
dbFminOptions = optimset('MaxFunEvals', 1000, 'TolFun', 1e-8, 'TolX', 1e-8, 'Display', 'off');

% Additional optimization settings.
warning off;
format('long');



% Specify constraints for optimization with fractional differencing parameters.

% Constrain optimization so that d and b satisfy dbMax >= d >= b > 0.
% Note: The tolerance dbMin is introduced to impose an inequality restriction
%   using the equality restriction dbMax >= d >= b >= dbMin.
constrained = 1;
dbMax = 10;
dbMin = 0.01;


% Collect into one array of options for this specification.
dbEstnOptions = { constrained, dbMax, dbMin, [], [], dbFminOptions };

% Later, AdjustEstnOptions function generates C_db and c_db from db0, constrained
%   and dbMax, dbMin, which constrains d and b so that C_db*dbHat <= c_db.
% Takes in (initial) dbEstnOptions, starting with FCVARoptions created here
%   and outputs the same with blanks filled in.
% AdjustEstnOptions returns:
% dbEstnOptions = { constrained, C_db, c_db, R_db, r_db, dbFminOptions };



% Specify additional options for estimation.

% Number of observations reserved for initial values to be conditioned upon 
%	in the estimation.
N = 5;
% Truncation of MA lags in fractional differencing operator.
M = 0;     % M = 0 is ignored, i.e. no truncation.

% Specify deterministics in the fractional AR model.
% deterministics = '         none      ';
deterministics =   'restricted constant';


% Default model places no restrictions on Gamma.
R_Gamma = [];
r_Gamma = [];


% Default model also places no restrictions on either alpha or beta.
nCols = [];
A = [];
H = [];
a = [];
b = [];




% Specify an indicator to print results to screen and generate graphs.
print2screen = 1;
% Set a separate indicator to print lagged coefficients as well.
printGammas = 1;
% Set a separate indicator to print and plot roots of the characteristic polynomial.
printRoots = 1;




% Specify options for matlab optimization functions used in restricted estimation. These 
%	specifications apply to the optimization performed in GetParamsSwitching().
restrictFminOptions = optimset('MaxFunEvals', 100, 'TolFun', 1e-6, 'TolX', 1e-6);





% Collect these options in a single array.
EstnOptions = { N, M, deterministics, R_Gamma, r_Gamma, [], [], [],...
                    nCols, A, H, a, b, [], {}, {}, {}, {},...
                    [], [], [], print2screen, printGammas, printRoots, restrictFminOptions };
% Later, AdjustEstnOptions generates
% EstnOptions = { N, M, deterministics, R_Gamma, r_Gamma, [], [], [],
%                   nCols, A, H, a, b, [], Abar, Aperp, replaceCols,
%                   keepCols, [], [], [], print2screen, printGammas, printRoots, restrictFminOptions },
% the rest of which is filled in by the function AdjustEstnOptions.



% The options are carried through all functions as needed.
% dbEstnOptions carries the options for the estimation of fractional parameters.
% EstnOptions carries the options for all other functions and restrictions.
FCVARoptions = { dbEstnOptions, EstnOptions };


% Complete the specification of options using AdjustEstnOptions.
[ FCVARoptions ] = AdjustEstnOptions(db0, k, r, p, FCVARoptions);




% end