-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathPerformanceAnalyticsPresentation-UseR-2007.Rnw
621 lines (513 loc) · 16.9 KB
/
PerformanceAnalyticsPresentation-UseR-2007.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
% $Id$
\documentclass[10pt,usletter]{beamer}
% may need full path to find these .sty files outside of R environment
\usepackage{Sweave}
% \usepackage{/usr/lib/R/share/texmf/Sweave}
\SweaveOpts{engine=R,eps=TRUE}
%\VignetteIndexEntry{PerformanceAnalytics Data Mining Presentation - UseR - 2007}
%\VignetteDepends{PerformanceAnalytics}
%\VignetteKeywords{returns, performance, risk, benchmark, portfolio}
%\VignettePackage{PerformanceAnalytics}
% - Talk at a conference/colloquium.
% - Talk length is about 60min.
% Beamer Presentation Template Copyright 2004 by Till Tantau <tantau@users.sourceforge.net>.
% Contents Copyright 2007 Peter Carl and Brian G. Peterson
%
% This file can be redistributed and/or modified under
% the terms of the GNU Public License, version 2.
\mode<presentation>
{
\usetheme{default}
% or ...
% \setbeamercovered{transparent}
% or whatever (possibly just delete it)
}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
%%\usepackage{noweb}
\usepackage{subfigure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[english]{babel}
\makeatother
\usepackage[latin1]{inputenc}
% or whatever
\usepackage{times}
\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.
\title[PerformanceAnalytics] % (optional, use only with long paper titles)
{Exploratory Data Analysis in Finance Using PerformanceAnalytics}
% \subtitle
% {Include Only If Paper Has a Subtitle}
\author[Brian Peterson \& Peter Carl] % (optional, use only with lots of authors)
{Brian~G.~Peterson \& Peter~Carl}
% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
% affiliation.
\institute[Braverock] % (optional, but mostly needed)
{
\inst{1}
Diamond Management \& Technology Consultants \\
Chicago, IL \\
brian@braverock.com
\and
\inst{2}
Guidance Capital\\
Chicago, IL\\
peter@braverock.com
} %the formatting of our companies is likely to be all screwed up
\date[July 2007] % (optional, should be abbreviation of conference name)
{UseR! International User and Developer Conference, Ames, Iowa, 8-10 Aug 2007}
% - Either use conference name or its abbreviation.
% - Not really informative to the audience, more for people (including
% yourself) who are reading the slides online
\subject{Data Mining using PerformanceAnalytics}
% This is only inserted into the PDF information catalog. Can be left
% out.
% If you have a file called "university-logo-filename.xxx", where xxx
% is a graphic format that can be processed by latex or pdflatex,
% resp., then you can add a logo as follows:
% \pgfdeclareimage[height=0.5cm]{university-logo}{university-logo-filename}
% \logo{\pgfuseimage{university-logo}}
% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
% \AtBeginSubsection[]
% {
% \begin{frame}<beamer>
% \frametitle{Outline}
% \tableofcontents[currentsection,currentsubsection]
% \end{frame}
% }
% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:
%\beamerdefaultoverlayspecification{<+->}
\begin{document}
%\right] \right\rbrace \right\rangle \right( \begin{document}
% this has to be after \begin{document} to work
\setkeys{Gin}{width=2.5in}
\begin{frame}
\titlepage
\end{frame}
<<LoadLibrary,echo=F,results=hide>>=
library('PerformanceAnalytics')
data(managers)
data(edhec)
@
<<CalcDataDimensions,echo=F>>=
managers.length = dim(managers)[1]
manager.col = 1
peers.cols = c(2,3,4,5,6)
indexes.cols = c(7,8)
Rf.col = 10
trailing12.rows = ((managers.length - 11):managers.length)
trailing36.rows = ((managers.length - 35):managers.length)
trailing60.rows = ((managers.length - 59):managers.length)
#assume contiguous NAs - this may not be the way to do it na.contiguous()?
frInception.rows = (length(managers[,1]) -
length(managers[,1][!is.na(managers[,1])]) + 1):length(managers[,1])
@
\begin{frame}
\frametitle{Outline}
\tableofcontents
% You might wish to add the option [pausesections]
\end{frame}
\section{Visualization}
%\subsection{Objectives}
\begin{frame}
\frametitle{Overview}
\begin{itemize}
\item
Exploratory data analysis with finance data often starts with visual examination to:
\begin{itemize}
\item
examine properties of asset returns
\item
compare an asset to other similar assets
\item
compare an asset to one or more benchmarks
\end{itemize}
\item
Application of performance and risk measures can build a set of statistics for comparing possible investments
\item
Examples are developed using data for six (hypothetical) managers, a peer index, and an asset class index
\item
Hypothetical manager data was developed from real manager timeseries using \emph{accuracy} and \emph{perturb} packages to disguise the data while maintaining some of the statistical properties of the original data.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Draw a Performance Summary Chart.}
\begin{figure}
\centering
\begin{tiny}
<<Graph1,echo=T,fig=T>>=
charts.PerformanceSummary(managers[,c(manager.col,indexes.cols)],
colorset=rich6equal, lwd=2, ylog=TRUE)
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Show Calendar Performance.}
\begin{figure}
\begin{tiny}
<<CalendarReturns,echo=T>>=
t(table.CalendarReturns( managers[,c(manager.col,indexes.cols)]) )
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Calculate Statistics.}
\begin{tiny}
<<MonthlyReturnStats,echo=T>>=
table.Stats(managers[,c(manager.col,peers.cols)])
@
\end{tiny}
\end{frame}
\begin{frame}[fragile]
\frametitle{Compare Distributions.}
\begin{tiny}
\begin{figure}
\centering
<<Graph10,echo=T,fig=T>>=
chart.Boxplot(managers[ trailing36.rows, c(manager.col, peers.cols,
indexes.cols)], main = "Trailing 36-Month Returns")
@
\end{figure}
\end{tiny}
\end{frame}
\begin{frame}[fragile]
\frametitle{Compare Distributions.}
\begin{figure}
\begin{tiny}
<<Graph13,echo=T,fig=T>>=
layout(rbind(c(1,2),c(3,4)))
chart.Histogram(managers[,1,drop=F], main = "Plain", methods = NULL)
chart.Histogram(managers[,1,drop=F], main = "Density", breaks=40,
methods = c("add.density", "add.normal"))
chart.Histogram(managers[,1,drop=F], main = "Skew and Kurt", methods = c
("add.centered", "add.rug"))
chart.Histogram(managers[,1,drop=F], main = "Risk Measures", methods = c
("add.risk"))
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Show Relative Return and Risk.}
\begin{figure}
\centering
\begin{tiny}
<<Graph3,echo=T,fig=T>>=
chart.RiskReturnScatter(managers[trailing36.rows,1:8], Rf=.03/12, main =
"Trailing 36-Month Performance", colorset=c("red", rep("black",5), "orange",
"green"))
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Examine Performance Consistency.}
\begin{figure}
\centering
\begin{tiny}
<<Graph5,echo=T,fig=T>>=
charts.RollingPerformance(managers[, c(manager.col, peers.cols,
indexes.cols)], Rf=.03/12, colorset = c("red", rep("darkgray",5), "orange",
"green"), lwd = 2)
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Display Relative Performance.}
\begin{figure}
\centering
\begin{tiny}
<<Graph6,echo=T,fig=T>>=
chart.RelativePerformance(managers[ , manager.col, drop = FALSE],
managers[ , c(peers.cols, 7)], colorset = tim8equal[-1], lwd = 2, legend.loc
= "topleft")
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Compare to a Benchmark.}
\begin{figure}
\centering
\begin{tiny}
<<Graph6a,echo=T,fig=T>>=
chart.RelativePerformance(managers[ , c(manager.col, peers.cols) ],
managers[, 8, drop=F], colorset = rainbow8equal, lwd = 2, legend.loc =
"topleft")
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Compare to a Benchmark.}
\begin{figure}
\centering
\begin{tiny}
<<tableCAPM,echo=T>>=
table.CAPM(managers[trailing36.rows, c(manager.col, peers.cols)],
managers[ trailing36.rows, 8, drop=FALSE], Rf = managers[ trailing36.rows,
Rf.col, drop=F ])
@
\end{tiny}
\end{figure}
\end{frame}
\section{Methods}
\begin{frame}[shrink=10]
\frametitle{Calculate Returns.}
\begin{itemize}
\item
The single-period arithmetic return, or simple return, can be calculated as \\
\begin{equation}
R_{t} = \frac{P_{t}}{P_{t-1}} - 1 = \frac{P_{t} - P_{t-1}}{P_{t-1}}
\end{equation}
\item
Simple returns, cannot be added together. A multiple-period simple return is calculated as: \\
\begin{equation}
R_{t} = \frac{P_{t}}{P_{t-k}} - 1 = \frac{P_{t} - P_{t-k}}{P_{t-k}}
\end{equation}
\item
The natural logarithm of the simple return of an asset is referred to as the continuously compounded return, or \emph{log return}:\\
\begin{equation}
r_{t} = ln(1+R_{t}) = ln \frac{P_{t}}{P_{t-1}} = p_{t} - p_{t-1}
\end{equation}
\item
Calculating log returns from simple gross return, or vice versa: \\
\begin{equation}
r_{t} = ln(1 + R_{t}), R_{t} = exp(r_{t}) - 1.
\end{equation}
\item
\emph{Return.calculate} or \emph{CalculateReturns} (now deprecated) may be used to compute discrete and continuously compounded returns for data containing asset prices.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{table.CAPM underlying techniques}
\begin{itemize}
\item
Return.annualized --- Annualized return using \\
\begin{equation}
prod(1+R_{a})^{\frac{scale}{n}}-1=\sqrt[n]{prod(1+R_{a})^{scale}}-1
\end{equation}
\item
TreynorRatio --- ratio of asset's Excess Return to Beta $\beta$ of the benchmark
\begin{equation}
\frac{(\overline{R_{a}-R_{f}})}{\beta_{a,b}}
\end{equation}
\item
ActivePremium --- investment's annualized return minus the benchmark's annualized return
\item
Tracking Error --- A measure of the unexplained portion of performance relative to a benchmark, given by \\
\begin{equation}
TrackingError = \sqrt{\sum\frac{(R_{a}-R_{b})^{2}}{len(R_{a})\sqrt{scale}}}
\end{equation}
\item
InformationRatio --- ActivePremium/TrackingError
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Compare to a Benchmark.}
\begin{figure}
\centering
\begin{tiny}
<<Graph8,echo=T,fig=T>>=
charts.RollingRegression(managers[, c(manager.col, peers.cols), drop =
FALSE], managers[, 8, drop = FALSE], Rf = .03/12, colorset = redfocus, lwd =
2)
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Calculate Downside Risk.}
\begin{figure}
\centering
\begin{tiny}
<<tableDownside,echo=T>>=
table.DownsideRisk(managers[,1:6],Rf=.03/12)
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Semivariance and Downside Deviation}
\begin{itemize}
\item
Downside Deviation as proposed by Sharpe is a generalization of semivariance which calculates bases on the deviation below a Minimumn Acceptable Return(MAR)
\begin{equation}
\delta_{MAR} = \sqrt{ \frac{\sum^{n}_{t=1}(R_{t} - MAR)^{2}}{n} }
\end{equation}
\item
Downside Deviation may be used to calculate semideviation by setting MAR=mean(R) or may also be used with MAR=0
\item
Downside Deviation (and its special cases semideviation and semivariance) is useful in several performance to risk ratios, and in several portfolio optimization problems.
\end{itemize}
\end{frame}
\begin{frame}[shrink=10]
\frametitle{Value at Risk}
\begin{itemize}
\item
Value at Risk (VaR) has become a required standard risk measure recognized by Basel II and MiFID
\item
Traditional mean-VaR may be derived historically, or estimated parametrically using \\
\begin{equation}
z_{c} = q_{p}=qnorm(p)
\end{equation}
\begin{equation}
VaR=\bar{R} - z_{c} \cdot \sqrt{\sigma}
\end{equation}
\item
Even with robust covariance matrix or Monte Carlo simulation, mean-VaR is not reliable for non-normal asset distributions
\item
For non-normal assets, VaR estimates calculated using GPD (as in VaR.GPD) or Cornish Fisher perform best
\item
Modified Cornish Fisher VaR takes higher moments of the distribution into account: \\
\begin{equation}
z_{cf}=z_{c}+\frac{(z_{c}^{2}-1)S}{6}+\frac{(z_{c}^{3}-3z_{c})K}{24}+\frac{(2z_{c}^{3}-5z_{c})S^{2}}{36}
\end{equation}
\begin{equation}
modVaR =\bar{R} - z_{cf}\sqrt{\sigma}
\end{equation}
\item
Modified VaR also meets the definition of a coherent risk measure per Artzner,et.al.(1997)
\end{itemize}
\end{frame}
\begin{frame}[shrink=10]
\frametitle{Risk/Reward Ratios in \emph{PerformanceAnalytics}}
\begin{itemize}
\item
SharpeRatio --- return per unit of risk represented by variance, may also be annualized by \\
\begin{equation}
\frac{\sqrt[n]{prod(1+R_{a})^{scale}}-1}{\sqrt{scale}\cdot\sqrt{\sigma}}
\end{equation}
\item
Sortino Ratio --- improvement on Sharpe Ratio utilizing downside deviation as the measure of risk \\
\begin{equation}
\frac{(\overline{R_{a} - MAR})}{\delta_{MAR}}
\end{equation}
\item
Calmar and Sterling Ratios --- ratio of annualized return (Eq. 1) over the absolute value of the maximum drawdown
\item
Sortino's Upside Potential Ratio --- upside semdiviation from MAR over downside deviation from MAR
\begin{equation}
\frac{ \sum^{n}_{t=1} (R_{t} - MAR) }{ \delta_{MAR} }
\end{equation}
\item
Favre's modified Sharpe Ratio --- ratio of excess return over Cornish-Fisher VaR
\begin{equation}
\frac{(\overline{R_{a}-R_{f}})}{modVaR_{R_{a},p}}
\end{equation}
\end{itemize}
\end{frame}
\section{Summary}
\begin{frame}[fragile]
\frametitle<presentation>{Summary}
\begin{itemize}
\item
Performance and risk analysis are greatly facilitated by the use of charts and tables.
\item
The display of your infomation is in many cases as important as the analysis.
\item
\emph{PerformanceAnalytics} contains several tool for measuring and visualizing data that may be used to aid investment decision making.
\end{itemize}
% The following outlook is optional.
\vskip0pt plus.5fill
\begin{itemize}
\item
Further Work
\begin{itemize}
\item
Additional parameterization to make charts and tables more useful.
\item
Pertrac or Morningstar-style sample reports.
\item
Functions and graphics for more complicated topics such as factor analysis and optimization.
\end{itemize}
\end{itemize}
\begin{figure}
\centering
\subfigure
{
% \includegraphics[totalheight=0.1\textheight,width=.36\textwidth]{Diamond_Logo_Tag.jpg}
}
\hfill
\subfigure
{
% \includegraphics[totalheight=0.15\textheight,width=.15\textwidth]{Rlogo.jpg}
}
\end{figure}
\end{frame}
\section{Appendix: Set Up PerformanceAnalytics}
\begin{frame}[fragile]
\frametitle{Install PerformanceAnalytics.}
\begin{itemize}
\item
As of version 0.9.4, PerformanceAnalytics is available in CRAN
\item
Version 0.9.5 was released at the beginning of July
\item
Install with: \linebreak \texttt{>
install.packages("PerformanceAnalytics")}
\item
Required packages include \texttt{Hmisc}, \texttt{zoo}, and Rmetrics packages such as \texttt{fExtremes}.
\item
Load the library into your active R session
using: \linebreak \texttt{> library("PerformanceAnalytics")}.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Load and Review Data.}
% The noweb code must be flush left
\begin{figure}
\begin{tiny}
<<LoadData,echo=T>>=
data(managers)
head(managers)
@
\end{tiny}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Set Up Data for Analysis.}
\begin{figure}
\begin{center}
\begin{tiny}
<<CalcDataDimensions,echo=T>>=
dim(managers)
managers.length = dim(managers)[1]
colnames(managers)
manager.col = 1
peers.cols = c(2,3,4,5,6)
indexes.cols = c(7,8)
Rf.col = 10
#factors.cols = NA
trailing12.rows = ((managers.length - 11):managers.length)
trailing12.rows
trailing36.rows = ((managers.length - 35):managers.length)
trailing60.rows = ((managers.length - 59):managers.length)
#assume contiguous NAs - this may not be the way to do it na.contiguous()?
frInception.rows = (length(managers[,1]) -
length(managers[,1][!is.na(managers[,1])]) + 1):length(managers[,1])
@
\end{tiny}
\end{center}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Draw a Performance Summary Chart.}
\begin{figure}
\centering
\begin{tiny}
<<Graph1,echo=T,fig=T>>=
charts.PerformanceSummary(managers[,c(manager.col,indexes.cols)],
colorset=rich6equal, lwd=2, ylog=TRUE)
@
\end{tiny}
\end{figure}
\end{frame}
\end{document}