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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.