BookmarkSubscribeRSS Feed
opti_miser
Calcite | Level 5

I'm trying to run the optimization pasted below in optmodel.  The program is running, whereas earlier I was getting an out of memory message.  However, it is very slow.  I tried to do what I could to make the code more efficient.  Any other ideas?

On average, i=3,000.  t=465 and k=3.  One problem may be that I need to use 465 constraints, but I have to have these constraints in place.  I can run a similar program in Proc IML in a fraction of the time, but Proc Optmodel is so flexible that I really need to migrate as much of my coding as possible. Thank you for whatever ideas you can offer.t

proc optmodel PRINTLEVEL=0;

    *create a numerical index based on permno and date, read in below;

    set <num,num> STOCKS_DATES;

    *create another numerical index just based on dates;

    set DATES = setof {<i,t> in STOCKS_DATES} t;

    *create another numerical index just based on permnos;

    set STOCKS {t in DATES} = slice(<*,t>, STOCKS_DATES);

    *create a numerical index based on the characteristics upon which portfolio weights are based;

    set CHARACTERISTICS = {'alpha', 'beta', 'stdfirm'};

    *name variables that will be read in from the data set;

    num char {STOCKS_DATES, CHARACTERISTICS};

    num ret {STOCKS_DATES};

    *read in the sas data set, specifying that each column in the char matrix is a different characteristic, k;

    read data foriml into STOCKS_DATES=[permno obs]

        {k in CHARACTERISTICS} <char[permno,obs,k]=col(k)>

        ret;

    var Theta {CHARACTERISTICS} init 0;

    impvar portmean = (1/card(DATES)) * (sum {t in DATES} (sum {i in STOCKS} ((1/card(STOCKS)) + (1/card(STOCKS)) * sum {k in CHARACTERISTICS} Theta * char[i,t,k]) * ret[i,t]));

    impvar portvar = (1/card(DATES)) * (sum {t in DATES}(((sum {i in STOCKS} ((1/card(STOCKS)) + (1/card(STOCKS)) * sum {k in CHARACTERISTICS} Theta * char[i,t,k]) * ret[i,t])-portmean)**2));

    impvar sumneg_w {t in DATES} = sum {i in STOCKS} min(((1/card(STOCKS)) + (1/card(STOCKS)) * sum {k in CHARACTERISTICS} Theta * char[i,t,k]),0);

    con short50 {t in DATES}: sumneg_w >= -0.5 ;

    max Objective1 = portmean - (&y/2) * portvar;

    Problem Prob1 Include Theta short50 Objective1;

    USE PROBLEM Prob1;

    solve with NLP OBJ Objective1 / ms;

1 REPLY 1
RobPratt
SAS Super FREQ

You might try making portmean an explicit variable instead, to reduce the density of the expression for portvar.  Replace the impvar portmean statement with:

var portmean;

con portmean_con:

     portmean = (1/card(DATES)) * (sum {t in DATES} (sum {i in STOCKS} ((1/card(STOCKS)) + (1/card(STOCKS)) * sum {k in CHARACTERISTICS} Theta * char[i,t,k]) * ret[i,t]));

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1102 views
  • 0 likes
  • 2 in conversation