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;
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.
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.