SAS Portfolio Analysis - Serving the Kitchen Sink Haftan Eckholdt, DayTrends, Brooklyn, NY ABSTRACT Portfolio management has surpassed the capabilities of financial software platforms both in terms of analysis and information delivery. Investment strategies are usually back-tested over decades before entering the market, and new investment strategies often change position very rapidly. On top of this are new investor demands for immediate access to up to date and detailed information on fund performance, risk, and activity. No brand of financial software allows users to analyze extended daily histories, much less share detailed reports over the WEB. SAS has a long history of delivering detailed analyses over the WEB, and this presentation will demonstrate how to meet the demands of managers and investors with in depth analyses of portfolio performance, risk, and activity using rich WEB based reports that are easily formatted in GIF, JAVA, and ActiveX. INTRODUCTION Whether reporting on a backtested portfolio, or recent trading activities, the challenges are much the same. There is a common set of performance metrics that most analysts demand in terms of performance, risk, activity, and content. In each case, an investor or reviewer will eventually want everything from large time frame summaries to raw data from the smallest available time frame. Note that pilot data for this paper were derived from the S&P500 Index. Membership history was taken from published records of SP500 membership and equity histories were bought from suppliers close equity data (TC2000, Bloomberg, etc.). Overall, the portfolio averages 150-200 equities when full, with an average hold less than 1 month. Costs were $0.01 / share each way and $10 per trade each way. Strategies were traded with the goal of keeping data from 1980 to 2000 "out of sample". This talk will follow a draft of a web based portfolio report at www.daytrends.com. Performance There are many performance measures, and the following six are probably the most popular: Return, Volatility, Sharpe Ratio, Alpha, Beta, RSquare. Calculating these requires generating a daily (weekly, monthly, etc.) series of profit / loss. If you have the actual asset values of the account (DAV: daily asset value), then you can convert them back and forth as follows: DPL, DAV DPL = (FUND-LAG1(FUND))/LAG1(FUND); DATA PERF; SET PERF; RETAIN DAV 500000; by date; DAV = (1+DTDPL)*DTAV; And these in tern can be used to calculate the performance metrics. PROC MEANS N MIN MAX MEAN STD KURT SUM DATA=PERF; ods output summary=meanz; VAR DPL; DATA MEANZ; SET MEANZ; * DAILY RETURN; DR_DT=DTDPL_MEAN-(0.5*DTDPL_STDDEV**2); * ANNUAL VOLATILITY; AV_DT=SQRT(250)*DTDPL_STDDEV; * ANNUAL RETURN; AR_DT=EXP(250*DR_DT)-1; * SHARPE RATIO; RR_DT=(AR_DT-0.017)/AV_DT; 1
Figure 1. Performance (return x volatility) of simulated trades in June 2004. AR_DT20046 0. 7 0. 6 0. 5 0. 4 0. 3 0. 2 0. 1 0. 0 Other performance measures can be calcaulated from the same return series: PROC CORR DATA=PERF; ods output PearsonCorr=cor; VAR DPL; WITH SPDPL; PROC GLM DATA=PERF; ods output parameterestimates=reg; MODEL DPL = SPDPL / SOLUTION; -0.1-0.2-0.3 0. 07 0. 08 0. 09 0. 10 0. 11 0. 12 0. 13 0. 14 0. 15 0. 16 0. 17 0. 18 0. 19 AV_DT20046 STRATEGY PROT1 PROT2 PROT3 RankD RankW ods HTML path=odsout body="persummary.html"; TITLE1 "Annual Performance Summary"; VAR AV_DT AV_SP AR_DT AR_SP tbillm RR_DT RR_SP ; FORMAT DR_DT DR_SP AR_DT AR_SP TBILLM PERCENT9.4; PROC PRINT LABEL DATA=TABLE; DATA PERF; SET PERF; E40M40S20 = DTDPL; sp500 = SPDPL; proc gplot DATA=DPL0; ods HTML path=odsout body="char2n.html"; TITLE2 "Daily Portfolio CASH Position"; plot CASHP * DATE; format CASHP PERCENT6.2; proc gplot DATA=PERF; ods HTML path=odsout body="char3.html"; TITLE2 "Daily Portfolio Short Position"; plot hedgep * DATE / VREF = 0.20; format DATE mmddyy10. hedgep PERCENT8.1 ; proc gplot DATA=PERF; ods HTML path=odsout body="char1.html"; TITLE2 "Daily Portfolio Size (blue) and Position Age (red)"; title3 " "; plot davclo_n * DATE / vaxis = axis1; PLOT2 AGE_MEAN * DATE / vaxis = axis2; format DATE mmddyy10. ; proc gplot DATA=PERF; ods HTML path=odsout body="daily2.html"; TITLE1 " "; TITLE2 "Daily Profit / Loss"; TITLE3 "SP500 Index (red) and E40M40S20 (blue)"; plot (E40M40S20 SP500) * DATE / OVERLAY VREF=0;* xmax = 0.03 xmin = -0.03 ymax = 0.03 ymin = -0.03; format DATE mmddyy10.; 2
Risk Portfolio risk management is an art and a science that is critical to maintaining and understanding financial instruments. While drawdown, recovery, and value at risk (VAR) refer to standard monitoring devices in the industry, there is little clarity on the approaches used for each. Comparing established approaches like risk metrics that are based on historical correlations, with newer approaches using a layered boot strap of historical data can reveal discrepancies. What was the biggest loss? Drawdown is defined as the relative equity loss from the highest peak to the lowest valley of a price decline within a given window of observation. How long did it take to recover those losses? The time that it takes to recover from that drawdown is called a recovery. What might I typically lose tomorrow? Value at risk measures the maximum expected loss for a given portfolio in a given holding period at a given confidence level. What could I lose in a worse case scenario? A newer metric called a Crash Kappa can provide insights to this question. Using SAS (%MACRO, STAT, GRAPH), to model drawdown and recovery reveals discrepancies between the observed distribution and the normal distribution. This argues strongly that empirical distributions should be used for the drawdown measurements of the strategies. These discrepancies also suggest that empirical distributions are probably necessary for other measures of risk, like value at risk (VAR), and the crash Kappa. DRAWDOWN The SAS calculation of drawdown is relatively simple, although the %MACRO code doesn t suggest that. We calculated drawdown for 2 days, 5 days (1 week), 20 days (1 month), and 60 days (1 quarter), as held by the macro variable &W. %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); 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 ); P0 = sp500; %DO A = 1 %TO %SCAN(&W,&C); P&A = LAG&A(DOLLAR%SCAN(&Y,&D)); PEAK = MAX(P0 %DO A = 1 %TO %SCAN(&W,&C);,P&A );... %DO E = 300 %TO 1 %BY -1; IF LAG&E(DOLLAR%SCAN(&Y,&D)) GE PEAK THEN RECOVER = &E; Figure 1 shows both the daily close price as well as the maximum drawdown for the Index over the 21 year period. Note that the value axis ranges from $1 to $12 assuming that you invested just one dollar from the start. On the right hand axis, percent drawdown ranges from 34% to 2%. This figure is very informative in terms of the frequency and depth of drawdown that is likely to be experienced. proc gplot; TITLE1 "Max DrawDown and Recovery in %SCAN(&W,&C) Trading Days"; TITLE2 "Strategy: %SCAN(&V,&D) 1981-2000"; plot DRAW * DATE / haxis=axis1 vaxis=axis2 frame ; plot2 RECOVER * DATE / vaxis=axis3 ; 3
Figure 1. S&P500 Index daily close price (blue), and percent maximum drawdown (red) in rolling quarters from 1980 to 2000. 4
Several observations can be made from the Index analysis alone. The percent drawdown has a clustering that looks a little Gaussian on the right hand side of the distribution in Figure 2. Table 1 describes the important moments in the distribution, which is definitely not normally distributed. Figure 2. Density function of percent maximum drawdown of S&P500 Index from 1990 to 2000. Table 1. Descriptive statistics of the maximum quarterly drawdown of the S&P500 Index from 1990 to 2000. N 5051 Mean -0.0624893 Std Deviation 0.0416796 Skewness -3.16897 Uncorrected SS 28.4965358 Coeff Variation -66.698756 Sum Weights 5051 Sum Observations -315.63358 Variance 0.00173719 Kurtosis 15.4108872 Corrected SS 8.77280605 Std Error Mean 0.00058646 5
Table 2 describes the quantiles of the distribution. For monitoring purposes we will focus on the 1st and 99th quantiles which provide a 98% observation interval around the data (-0.012, -0.29). Table 2. Quantiles of the maximum quarterly drawdown of the S&P500 Index from 1980 to 2000. Quantile Estimate 100% Max 0.0119554 99% -0.0122718 95% -0.0216696 90% -0.0265504 75% Q3-0.0392829 50% Median -0.0505389 25% Q1-0.0754761 10% -0.1020601 5% -0.1255877 1% -0.2985402 0% Min -0.3323633 Figure 3 shows the drawdown plotted against the time to recovery from the peak. Figure 3. S&P500 percent maximum drawdown (blue) and days to recovery 9red) in rolling quarters from 1980 to 2000. 6
The density function of the recovery period shows that there are plenty of drawdown events that require a year or more to recover. Figure 4 shows the temporal relationship between these events. It seems as if drawdown of 15% to 20% takes about a year to recover, except for the crash in 1997 which took little recovery time. Deeper drawdown, greater than 20%, which only occurred in 1987, required almost 2 years of recovery time. Figure 4. Density function of recovery time of S&P500 Index from 1980 to 2000. Table 3. Descriptive statistics of the recovery time of the S&P500 Index from 1980 to 2000. N 4908 Mean 57.643643 Std Deviation 97.9578726 Skewness 2.55813449 Coeff Variation 169.936991 Variance 9595.7448 Kurtosis 6.05581948 Std Error Mean 1.39825721 Table 4 provides the quantiles which have more positive and negative extremes. Overall, the maximum recovery time was 485 days or nearly two years. Table 4. Quantiles of the recovery of the Index from 1980 to 2000. Quantile Estimate 100% Max 485.0 99% 445.0 95% 311.0 90% 183.0 75% Q3 55.0 50% Median 18.5 25% Q1 4.0 10% 1.0 5% 1.0 1% 1.0 7
0% Min 1.0 Figure 5 cuts to the heart of the matter. While the two measures, drawdown and recovery are not well correlated, the greatest drawdowns are associated with some of the greatest recovery periods as pointed out by the arrows in the lower right hand portion of figure 5. Figure 5. Drawdown by recovery for the S&P500 index in rolling quarters from 1980 to 2000 (time is graded color). 0.0-0.1 D R A W -0.2-0.3 100 200 300 400 RECOVER VALUE AT RISK (VAR) Value At Risk (VAR) is calculated in one of three ways: 1. Historical return & parametric inference 2. Historical correlations & parametric inference 3. Monte Carlo & parametric inference. The code that follows can be used to calculate VAR using the first two methods. PROC IML; USE MATRIXV; READ VAR _NUM_ INTO V; PRINT V; USE MATRIXC; READ ALL VAR _NUM_ INTO C; PRINT C; X = V*C; PRINT X; W=T(V); PRINT W; Y = X*W; PRINT Y; Z = SQRT(Y); PRINT Z; CREATE VARDIV FROM Z[COLNAME="VAR"]; APPEND FROM Z; 8
Figure 6. Daily asset value with tomorrow s lower boundary 95% confidence interval of VAR($) estimated from the undiversified analysis (method I: red) and diversified analysis (method II: green). 9
Figure 7. Log(daily return) with the lower boundary 95% confidence interval of VAR(%) boundaries estimated from the undiversified analysis (method I: red) and diversified analysis (method II: green). Several conclusions can be made from figure 7. Mostly one notices that the undiversified asset approach leads to many exceptions, and this presentation will include discussion of the Kupiec test which quantifies the probability of exceptions. CRASH KAPPA Extreme markets require extreme calculations. In order to predict behavior during extreme market conditions, one needs to constrain the sample to extreme conditions. This can be done with the Crash Kappa, where the analytic sample is confined to those days of +/- 3% change. The code for such estimates will be described in detail during the presentation. Activity Buy, Sell, realized pl DATA CONTENT; MERGE TRADE SECTOR; BY TICKER; IF BPRICE NE.; DATA SECTOR; SET SECTOR; POSITION = ASSET; MONTH = 1; DATA CONTENTB; SET SECTOR CONTENT; IF MONTH LT 7; POSIT = "LONG "; if TICKER = "SPY" then SECTOR_NAME = "Hedge"; if TICKER = "SPY" then POSIT = "SHORT"; 10
PROC SORT; BY MONTH; PROC GCHART; ods HTML path=odsout body="consummary.html"; TITLE1 " "; TITLE2 "Attribution of Realized Gains by Sector"; HBAR SECTOR_NAME / PERCENT FREQ=GAIN SUBGROUP=MONTH; BY MONTH; PROC FREQ; TABLES POSIT*MONTH / LIST;; WEIGHT GAIN; PROC GCHART; TITLE2 "Attribution of Realized Losses by Sector"; HBAR SECTOR_NAME / PERCENT FREQ=LOSS SUBGROUP=MONTH; BY MONTH; PROC FREQ; TABLES POSIT*MONTH / LIST;; WEIGHT LOSS; IntraDay data capture: FILENAME MOMENT DDE "EXCEL DASH!R2C5:R4C6"; LIBNAME MONITOR "E:\DAYTRENDS\RESEARCH\MONITOR\DATA\"; data _null_; * slept=wakeup("02jun2003:09:30:00"dt); slept=wakeup("09:30:00"t); run; DATA MONITOR.NOW; INFILE MOMENT; INPUT FUND $ ASSETS $; NOW = DATETIME(); %MACRO LOOKER; %DO A = 1 %TO 70; DATA NOW&A; INFILE MOMENT; INPUT FUND$ ASSETS $; NOW = DATETIME(); PROC APPEND BASE=MONITOR.NOW DATA=NOW&A; DATA _NULL_; RC = SLEEP(358); RUN; %MEND LOOKER; %LOOKER; RUN; PROC EXPORT DATA=INTRADAY OUTFILE= "E:\DAYTRENDS\RESEARCH\MONITOR\WEB\INTRADAY.XLS" DBMS=EXCEL2000 REPLACE; Content Size, Age, Sector, Live data DATA CONTENTC; MERGE TABLE1 CONTENTB; 11
BY MONTH; PERPOS = (POSITION / MAV)*10000; PROC GCHART DATA=CONTENTC; ods HTML path=odsout body="char4.html"; TITLE2 "Sector Allocation of SP500 and Tracker Fund by Month"; HBAR3D MONTH / DISCRETE NOSTATS FREQ=PERPOS SUBGROUP=SECTOR_NAME ; WHERE TICKER NE "SPY"; format month smonth.; PROC FREQ DATA=CONTENTC; TABLES SECTOR_NAME*MONTH / LIST; WHERE TICKER NE "SPY"; WEIGHT PERPOS; format month smonth.; REFERENCES Buyya, R. (1999). High Performance Cluster Computing: Architecture and Systems, volume 1. Prentice Hall: New Jersey. Buyya, R. (1999b). High Performance Cluster Computing: Programming and applications, volume 2. Prentice Hall: New Jersey. Foster, I. (1994). Designing and Building Parallel Programs: Concepts and Tools for Parallel Software Engineering. Addison_Wesley Publishing Company: New York. Hill, T. (1998). WINDOWS NT: Shell Scripting. Macmillian Technical Publishing: Indianapolis, IN. Wilkinson, B. and Allen, M. (1999). Parallel Programming: techniques and applications using networked workstations and parallel computers. Prentice Hall: New Jersey. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Haftan Eckholdt DayTrends 10 Jay Street Brooklyn, New York 11201 Work Phone: (718) 522-3170 Fax: (718) 504-4365 Email: haftan@daytrends.com Web: www.daytrends.com SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are trademarks of their respective companies. 12