DATA Step, Macro, Functions and more

How to calculate portfolio drawdown

Reply
Frequent Contributor
Posts: 122

How to calculate portfolio drawdown

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;

Super User
Posts: 10,023

Re: How to calculate portfolio drawdown

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;

Ask a Question
Discussion stats
  • 1 reply
  • 256 views
  • 0 likes
  • 2 in conversation