Sie sind auf Seite 1von 12

NESUG 17

Applications

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

NESUG 17

Applications

Figure 1. Performance (return x volatility) of simulated trades in June 2004.


A _D 20046 R T 0. 7

0. 6

0. 5

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

0. 3

0. 2

0. 1

0. 0

- 0. 1

- 0. 2

- 0. 3 0. 07 0. 08 0. 09 0. 10 0. 11 0. 12 0. 13 A _D 20046 V T S RT G T AEY P O1 RT P O2 RT P O3 RT R ankD R ankW 0. 14 0. 15 0. 16 0. 17 0. 18 0. 19

PROC PRINT LABEL DATA=TABLE; 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; 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.;

NESUG 17

Applications

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 doesnt 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); %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; 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 ;

NESUG 17

Applications

Figure 1. S&P500 Index daily close price (blue), and percent maximum drawdown (red) in rolling quarters from 1980 to 2000.

NESUG 17

Applications

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 Mean Std Deviation Skewness Uncorrected SS Coeff Variation Sum Weights Sum Observations Variance Kurtosis Corrected SS Std Error Mean 5051 -0.0624893 0.0416796 -3.16897 28.4965358 -66.698756 5051 -315.63358 0.00173719 15.4108872 8.77280605 0.00058646

NESUG 17

Applications

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 100% Max 99% 95% 90% 75% Q3 50% Median 25% Q1 10% 5% 1% 0% Min Estimate 0.0119554 -0.0122718 -0.0216696 -0.0265504 -0.0392829 -0.0505389 -0.0754761 -0.1020601 -0.1255877 -0.2985402 -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.

NESUG 17

Applications

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 Mean Std Deviation Skewness Coeff Variation Variance Kurtosis Std Error Mean 4908 57.643643 97.9578726 2.55813449 169.936991 9595.7448 6.05581948 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 100% Max 99% 95% 90% 75% Q3 50% Median 25% Q1 10% 5% 1% Estimate 485.0 445.0 311.0 183.0 55.0 18.5 4.0 1.0 1.0 1.0

NESUG 17

Applications

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 RECOVER

300

400

VALUE AT RISK (VAR)


Value At Risk (VAR) is calculated in one of three ways: 1. 2. 3. Historical return & parametric inference Historical correlations & parametric inference 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;

NESUG 17

Applications

Figure 6. Daily asset value with tomorrows lower boundary 95% confidence interval of VAR($) estimated from the undiversified analysis (method I: red) and diversified analysis (method II: green).

NESUG 17

Applications

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

NESUG 17

Applications

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;

%END; %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

NESUG 17

Applications

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

Das könnte Ihnen auch gefallen