Published on :
Statistical EXTERNAL

Pain Index Calculation

This code is also available in: Deutsch Español Français
Awaiting validation
This macro calculates the Pain Index, defined as the average of 'drawdowns' (cumulative losses) over the analysis period. It differs from the Ulcer Index because drawdowns are not squared, and from the average drawdown because the denominator is the total number of observations. It depends on the external macros %get_number_column_names, %ranname, and %drawdowns.
Data Analysis

Type : EXTERNAL


Data is provided via the 'returns' macro parameter. Processing also depends on external utility macros.

1 Code Block
MACRO DEFINITION
Explanation :
Macro definition, declaration of local variables, and initialization of temporary table names via %ranname. Retrieval of numeric columns via %get_number_column_names.
Copied!
1%macro pain_index(returns,
2 method= DISCRETE,
3 dateColumn= DATE,
4 outData= painindex);
5
6%local vars drawdown stat_mean i;
7 
8%let vars= %get_number_column_names(_table= &returns, _exclude= &dateColumn);
9%put VARS IN Pain_Index: (&vars);
10 
11%let drawdown= %ranname();
12%let stat_mean= %ranname();
13%let i = %ranname();
2 Code Block
MACRO CALL Data
Explanation :
Call to the external macro %drawdowns to calculate the initial drawdown series.
Copied!
1%drawdowns(&returns, method= &method, dateColumn= &dateColumn, outData= &drawdown)
3 Code Block
DATA STEP Data
Explanation :
Data transformation: removal of the first observation and taking the absolute value of drawdowns for mean calculation.
Copied!
1DATA &drawdown(drop=&i);
2 SET &drawdown(firstobs=2);
3 array ret[*] &vars;
4 
5 DO &i= 1 to dim(ret);
6 ret[&i]= abs(ret[&i]);
7 END;
8RUN;
4 Code Block
PROC MEANS Data
Explanation :
Calculation of the mean of drawdowns (absolute values) to obtain the Pain Index.
Copied!
1 
2PROC MEANS
3DATA= &drawdown mean noprint;
4OUTPUT out= &stat_mean mean=;
5RUN;
6 
5 Code Block
DATA STEP Data
Explanation :
Formatting of the final output table, adding a '_STAT_' label.
Copied!
1DATA &outData (keep=_stat_ &vars);
2FORMAT _STAT_ $32.;
3 SET &stat_mean;
4 _STAT_= 'Pain Index';
5RUN;
6 Code Block
PROC DATASETS
Explanation :
Cleanup of generated temporary tables and end of the macro.
Copied!
1PROC DATASETS lib=work nolist;
2 delete &drawdown &stat_mean;
3RUN;
4QUIT;
5 
6%mend;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright (c) 2015 by The Financial Risk Group, Cary, NC, USA.