Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 01-22-2017 11:02 PM
(1073 views)

Hi,

I want to minimise the following function;

Varience (e) = Varience (R) - Varience (w1r1+w2r2+w3r3+w4r4)

However, I am not quite sure that how to state its objective function using the SAS coding, can someone help me out in that?

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I think the following does what you want, first calling PROC CORR to compute the covariance from the historical data and then calling PROC OPTMODEL to formulate and solve the optimization problem:

```
proc corr data=styledata(drop=date)
out=corrout(where=(_type_ ne 'CORR')) cov noprint;
run;
data stats(drop=_name_);
set corrout;
if _type_ = 'COV' then delete;
run;
proc transpose data=stats out=stats;
id _type_;
run;
proc optmodel;
/* declare parameters and read data */
set <str> ASSETS;
str target = 'AMP';
set BENCH = ASSETS diff {target};
num cov {ASSETS, ASSETS};
read data stats into ASSETS=[_name_];
read data corrout(where=(_type_='COV')) into [_name_]
{i in ASSETS} <cov[_name_,i]=col(i)>;
/* declare optimization model */
var W {BENCH} >= 0 <= 1;
/* Var(X - Y) = Var(X) + Var(Y) - 2 Cov(X,Y) */
min Variance =
sum {i in BENCH, j in BENCH} cov[i,j] * W[i] * W[j]
+ cov[target,target]
- 2 * sum {i in BENCH} cov[i,target] * W[i];
con InvestAll:
sum {i in BENCH} W[i] = 1;
/* call solver and print optimal solution */
solve;
print W;
quit;
```

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I'd like to help, but I need more detail. Which are decision variables, and which are data?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Rob,

I am actually conducting style analysis of AMP fund on 4 benchmark returns,

I actually want to minimise the variance of the tracking error and find the weights that minimise the following function,

min VAR(R.f - SUM[w_i * R.s_i]) = min VAR(F - w*S) s.t. SUM(w_i) = 1; w_i > 0 where: R.f Fund returns R.s Style returns w_i Style weights

For my case it becomes,

min Var(AMP_AIT) – Var (w1*US_Small_Val + w2*US_Small_Gr + w3*US_Large_Gr + w4*_US_Large_Val)

subject to the constraints where sum Wi = 1 and Wi >= 0

How to use the proc optmodel in this regard will be greatly helpful for me. I have also attaced my dataset for your reference.

Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I think the following does what you want, first calling PROC CORR to compute the covariance from the historical data and then calling PROC OPTMODEL to formulate and solve the optimization problem:

```
proc corr data=styledata(drop=date)
out=corrout(where=(_type_ ne 'CORR')) cov noprint;
run;
data stats(drop=_name_);
set corrout;
if _type_ = 'COV' then delete;
run;
proc transpose data=stats out=stats;
id _type_;
run;
proc optmodel;
/* declare parameters and read data */
set <str> ASSETS;
str target = 'AMP';
set BENCH = ASSETS diff {target};
num cov {ASSETS, ASSETS};
read data stats into ASSETS=[_name_];
read data corrout(where=(_type_='COV')) into [_name_]
{i in ASSETS} <cov[_name_,i]=col(i)>;
/* declare optimization model */
var W {BENCH} >= 0 <= 1;
/* Var(X - Y) = Var(X) + Var(Y) - 2 Cov(X,Y) */
min Variance =
sum {i in BENCH, j in BENCH} cov[i,j] * W[i] * W[j]
+ cov[target,target]
- 2 * sum {i in BENCH} cov[i,target] * W[i];
con InvestAll:
sum {i in BENCH} W[i] = 1;
/* call solver and print optimal solution */
solve;
print W;
quit;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I just can't thank you enough Rob, the coding worked. I am really grateful to you for this.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.