Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

For loop in PROC OPTMODEL

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

For loop in PROC OPTMODEL

I am a newbie in sas and trying to write a simplistic version of garch model in proc optmodel, here is the attached code,

proc optmodel;

number n = 8926;

/* var omega init 0.01, alpha init 0.02, beta init 0.92; */

var omega, alpha, beta, mu;

number epsilonsq{1..n}, y{1..n}, llh{1..n}, sigtsq{1..n};

read data ret into [_n_] y; llh[1] = 0;

for{i in 1..n} do; epsilonsq = (y-0.0005)**2; end;

sigtsq[1] = mean(of epsilonsq

  • );
  • for{j in 2..n} do;

      sigtsq = omega + alpha*epsilonsq[j-1] + beta*sigtsq[j-1];  end;

    min z = sum{k in 2..n}(0.5*(log(2*3.14156)

      + log(omega + alpha*epsilonsq[k-1] + beta*sigtsq[k-1])

      + epsilonsq/(omega + alpha*epsilonsq[k-1] + beta*sigtsq[k-1])));

    omega.lb = 1e-06; alpha.lb = 1e-06; beta.lb = 1e-06;

    omega.ub = 1-1e-06; alpha.ub = 1-1e-06; beta.ub = 1-1e-06;

    con c: alpha + beta <= 1-1e-06;

    solve with nlp / tech=ip; print sigtsq;

    quit;

    I want sigstq matrix (its defined as an array using the number declaration) to change as the parameters (omega, alpha, beta) changes at every step of optimization. However, it remains constant throughout the optimization.

    Please point me in the right direction. Thanks.


    Accepted Solutions
    Solution
    ‎06-01-2015 02:52 PM
    SAS Employee
    Posts: 449

    Re: For loop in PROC OPTMODEL

    If you want sigtsq to depend on decision variables, you should declare it as an implicit variable:

    impvar sigtsq {j in 1..n} =

         (if j = 1 then mean(of epsilonsq

  • ) else omega + alpha*epsilonsq[j-
  • 1] + beta*sigtsq[j-1]);

    See the IMPVAR statement in the PROC OPTMODEL documentation:

    SAS/OR(R) 13.2 User's Guide: Mathematical Programming

    View solution in original post


    All Replies
    Solution
    ‎06-01-2015 02:52 PM
    SAS Employee
    Posts: 449

    Re: For loop in PROC OPTMODEL

    If you want sigtsq to depend on decision variables, you should declare it as an implicit variable:

    impvar sigtsq {j in 1..n} =

         (if j = 1 then mean(of epsilonsq

  • ) else omega + alpha*epsilonsq[j-
  • 1] + beta*sigtsq[j-1]);

    See the IMPVAR statement in the PROC OPTMODEL documentation:

    SAS/OR(R) 13.2 User's Guide: Mathematical Programming

    New Contributor
    Posts: 3

    Re: For loop in PROC OPTMODEL

    Thanks Rob!

    SAS Employee
    Posts: 449

    Re: For loop in PROC OPTMODEL

    Glad to help.  You might also be interested in this book of 29 examples that illustrate various features of PROC OPTMODEL:

    SAS/OR(R) 13.2 User's Guide: Mathematical Programming Examples

    🔒 This topic is solved and locked.

    Need further help from the community? Please ask a new question.

    Discussion stats
    • 3 replies
    • 554 views
    • 0 likes
    • 2 in conversation