170 likes | 355 Views
Formulas. A formula is a (possibly) nonlinear mathematical relationship. A SERIES is a vector of numbers Formulas versus SET: You can use SET to create the variable y as: SET y = 2 + .5*x**2 This creates a new series equal to two plus ½ of the square of x
E N D
Formulas • A formula is a (possibly) nonlinear mathematical relationship. A SERIES is a vector of numbers • Formulas versus SET: • You can use SET to create the variable y as: • SET y = 2 + .5*x**2 • This creates a new series equal to two plus ½ of the square of x • A FORMULA can be used to express the mathematical relationship: • FRML y = a + bx**r • No variable is created—the three parameters can now be estimated Nonlinear Estimation
NNLS There are 4 statements required for nonlinear least squares: • indicate the coefficient to be estimated • Create the FRML to estimate • Initialize the coefficients • NLLS(FRML=name ,OPTIONS) depvar start end residuals coeffs Standard Regression Options METHOD=[GAUSS]/SIMPLEX/GENETIC robusterrors iterations = Defined Variables Those of LINREG %FUNCVAL Nonlinear Estimation
Example 1 Example 1: Let x and y be series and suppose you want to estimate a, b, and r. nonlin a b r frml z = a + b*x**r compute a = .4, b = -.3, c = 2 nlls(frml=z) y Nonlinear Estimation
Since the disturbance term is additive, you cannot simply take the log of each side and estimate the equation using OLS. However, nonlinear least squares allows you to estimate and without transforming the variables. In RATS, you use the following structure to estimate a model using nonlinear least squares: NONLINlist of parameters to be estimated FRMLformula namethe equation to be estimated COMPUTEinitial guesses for the parameters NNLS(FRML=formula name) dependent variable For the example at hand, you could use: nonlin alpha beta frml equation_1 y = alpha*x**beta com alpha = 1.0 , beta = 0.5 nlls(frml = equation_1) y If the model had the form yt = xtt where {t} is log-normal, it would be appropriate to estimate the regression in logs using LINREG. Nonlinear Estimation
NLLS(frml=formula name, other options) depvar start end residuals coeffs where: depvar Dependent variable used on the FRML instruction. start end Range to estimate. residuals Series to store the residuals (Optional). coeffs Series to store the estimated coefficients (Optional). The principal options are: METHOD = [GAUSS]/SIMPLEX/GENETIC. GAUSS requires a twice differential function. USE SIMPLEX if you have convergence problems. It is possible to use SIMPLEX or GENETIC to refine the initial guesses before using GAUSS. iterations = Maximum number of iterations to use. ROBUSTERRORS/ As in LINREG, this option calculates a [NOROBUSTERRORS] consistent estimate of the covariance matrix. Nonlinear Estimation
Example 2 Suppose that I want to estimate: dxt = 0.25*axt-1+ a sin1t + b cos1t + c dxt-1 This can be done with LINREG: lin dx # x{1} sin1 cos1 dx{1} But suppose that I want to constrain a to equal a2 + b2 nonlin a b c frml z = .25*(a*a + b*b)*x{1} + a*sin1 + b*cos1 + c*dx{1} compute a = .4, b = -.3, c = 2 nlls(frml=z) dx Nonlinear Estimation
Controlling the Estimation NLPAR: You will not need to use NLPAR unless you experience convergence problems or want to obtain more precise numerical answers. Numerical optimization algorithms use iteration routines that cannot guarantee precise solutions for β. NLPAR allows you to select the various criteria RATS uses to determine when (and if) the solution converges. There are two principal options; the syntax is: nlpar(options) CRITERION = In the default mode, CRITERION=COEFFICIENTS. Here, convergence is determined using the change in the numerical value of the coefficients between iterations. Setting CRITERION=VALUE means that convergence is determined using the change in the value of the function being maximized. CVCRIT = Converge is assumed to occur if the change in the COEFFICIENTS or VALUE is less than the number specified. The default is 0.00001. Nonlinear Estimation
Examples of NLPAR 1. nlpar(cvcrit=0.0001) Setting CVCRIT=0.0001 means that RATS will continue to search for the values of the coefficients that maximize f( ) until the change in the coefficients between iterations is not more than 0.0001. 2. nlpar(criterion=value,cvcrit=0.0000001) Setting CVCRIT=0.0000001 and CRITERION=VALUE means that RATS will continue to search for the values of the coefficients that maximize f( ) until the change in the value of f( ) between iterations is less than 0.0000001. Nonlinear Estimation
Maximize Suppose your data set contains T observations of the variables yt and xt and you have used the FRML instruction to define the function: L = f(yt , xt; β) where: xt and β can be vectors (and xt can represent a lagged value of yt). MAXIMIZE is able to find the value(s) of β that solve: The syntax and principal options of MAXIMIZE are: maximize(options) frml start end funcval where: frml A previously defined formula start end The range of the series to use in the estimation funcval (Optional) The series for the computed values of f(yt, xt; β) Nonlinear Estimation
Options for MAXIMIZE The key options for our purposes are: METHOD = RATS is able to use any one of three different algorithms to find the maximum: BFGS, BHHH, or SIMPLEX. The technical details of each maximization algorithm are provided in the RATS manual. Use either the default BFGS method or the BHHH method for twice-differentiable functions and SIMPLEX in other cases. If you have convergence problems with BFGS, try BHHH. Note that SIMPLEX is extremely slow and often requires many iterations. ITERATIONS= The upper limit of the number of iterations used in the maximization. RECURSIVE Use this option if the formula must be solved recursively. It is necessary to use RECURSIVE if the value of the value of f( ) depends on the value of a variable at t-i. Note: You can use TEST and RESTRICT with the BFGS and BHHH options. Coefficients are numbered by their position in the NONLIN statement. Nonlinear Estimation
Maximum Likelihood Under the usual normality assumption, the log likelihood of observation t is: With T independent observations: We want to select band s2 so as to maximize L Nonlinear Estimation
ML II We want to select band s2 so as to maximize L Note that this is the same as maximizing: Which we would have obtained by writing the likelihood for obs. t as Nonlinear Estimation
Maximum Likelihood in RATS As in NLLS, to use MAXIMIZE, you must first: 1. List the name(s) of the parameters over which RATS is to perform the maximization. This is done using the NONLIN command. 2. Define the likelihood function f( ) using a FRML statement. 3. Set the initial values of the parameters using the COMPUTE command. Consider the following RATS statements used to estimate the linear regression y = a + bx: NONLIN b var FRML L = -log(var) - (y - b*x)**2/var COMPUTE b = initial guess, var = initial guess MAXIMIZE L start end OR, you can use to formulas frml e = y ‑ b*x frml L = ‑log(var) - e**2/var Nonlinear Estimation
Subformulas yt = t + 1t-1 Since the {t} sequence is unobserved, it is not possible to use LINREG or NLLS to estimate the process. To estimate 1 using maximum likelihood techniques, it is necessary to construct a formula of the form t = yt - 1t-1. However, the following is an illegal statement because etis defined in terms of its own lagged value (a nonresolvable recursive expression): frml e = y – b1*e{1} The way to circumvent this problem is to create a “placeholder” series using the SET instruction. Then, define the desired formula in terms of the placeholder series. Finally, use a SUBFORMULA to equate the placeholder and the desired series. For example, a simple way to create the formula for the MA(1) process is: set temp = 0.0 nonlin b1 var frml e = y - b*temp{1} frml L = (temp = e), -log(var) - e**2/var) Nonlinear Estimation
Subformulas (cont.) drst = 1drst-1 + 7drst-7 + t + 1t-1 + 2t-2 Now, the NONLIN instruction contains the coefficient b2. The first FRML instruction uses temp{1} and temp{2} as placeholders for et-1 and et-2. The second FRML instruction creates the desired log likelihood and the COMPUTE instruction provides the initial guesses. Notice that the start date can remain at 9 since no usable observations are lost from the MA terms. set temp = 0. nonlin a1 a7 b1 b2 var frml e = drs - a1*drs{1} - a7*drs{7} - b1*temp{1} - b2*temp{2} frml L = (temp=e), -log(var) - (e)**2/var com a1 = 0.4, a7 = -.3, b1 = .5, b2 = 0.3, var = 1. max L 9 * Nonlinear Estimation
The GARCH Likelihood Function Nonlinear Estimation
ARMA(1,1)-IGARCH(1,1) set temp = 0. nonlin a0 a1 a2 a3 b0 b1 c1 b0.ge.0. b1.ge.0. c1.ge.0. frml e = spread - a0 - a1*spread{1} - a2*spread{2} - a3*spread{3} frml h = b0 + b1*e{1}**2 + c1*temp{1} frml L = (temp = h), -log(temp) - (e)**2/temp After initializing the parameters with the LINREG and COMPUTE instructions, the first MAXIMIZE instruction refines the initial guesses with the SIMPLEX method. The second obtains the final estimates using to BFGS method: lin(noprint) spread ; # constant spread{1 to 3} com a0 = %beta(1), a1 = %beta(2) , a2 = %beta(3), a3 = %beta(4) , b0 = %seesq, $ b1 = 0.2, c1 = 0.5 max(method=simplex,iters=5) L 7 * max(iters=200) L 7 * Nonlinear Estimation