BookmarkSubscribeRSS Feed
SeanZ
Obsidian | Level 7

hi, i am trying to calculate the drawdown in portfolio analysis. I have a time series daily portfolio returns. And would like to calculate max drawdown (from peaks to bottom) and recovery as well for certain periods. I found some codes below, but could not follow the logic here. Can someone explain a little bit the logic or have some codes without macro involed? Thanks.  

 

 

%MACRO DO_BRANCH;

 

 

%DO A = %EVAL((%SCAN(&W,&C)) %TO 1 %BY -1;

%DO B = %EVAL(&A -1) %TO 1 %BY -1;

A&A.B&B = (LAG&B(sp500) -LAG&A(sp500))/ LAG&A(sp500);

%END;

%END;

DRAW = MIN(A%EVAL(%SCAN(&W,&C))B%EVAL((%SCAN(&W,&C)) -1)

%DO A = %EVAL((%SCAN(&W,&C)) %TO 1 %BY -1;

%DO B = %EVAL(&A -1) %TO 1 %BY -1;

,A&A.B&B

%END;

%END;

);

P0 = sp500;

%DO A = 1 %TO %SCAN(&W,&C);

P&A = LAG&A(DOLLAR%SCAN(&Y,&D));

%END;

PEAK = MAX (P0

%DO A = 1 %TO %SCAN(&W,&C);

,P&A

%END;

);

 

 

%DO E = 300 %TO 1 %BY -1;

IF LAG&E(DOLLAR%SCAN(&Y,&D)) GE PEAK THEN RECOVER = &E;

%END;

 

 

%MEND DO_BRANCH;

%DO_BRANCH;

1 REPLY 1
Ksharp
Super User

Can you post some dummy data and the output you want to see ?

It seems you need RANGE() .

 

proc sql;

 select range(return) as range from have;

quit;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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