dirk eddelbuettel, ph.d. debian andrprojects chicago, il...
TRANSCRIPT
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Using R in Finance
Dirk Eddelbuettel, Ph.D.Debian and R Projects
Invited Panel Presentation at the58th Midwest Finance Association Meetings
Chicago, IL, March 5, 2009
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Outline
Background
About R and CRAN
Finance Task View
Selected Finance Packages
Summary and Outlook
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Personal connections
I Financial Econometrician by training, with twelve+ years asa Quant in (Inv-)Banking, Hedge Funds, Prop Trading
I Debian developer/contributor since 1995I Debian R co-maintainer since 1999, maintainer since 2001I R package author or co-author:
I RQuantLib: R interface to the QuantLib librariesI digest: hash function ’digests’ of serialized R objectsI random: R interface to true RNG via random.orgI RDieHarder: R interface to DieHarder RNG testersI littler: R scripting front-endI RPostgreSQL: R interface to PostgreSQL RDBMSI Rcpp: C++ classes for extending R with C/C++ functionsI RInside: C++ classes for embedding R in C++ programs
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Personal connections
I Other R Open Source activities:I R-SIG-Finance, R-SIG-Debian, R-SIG-HPC list ’owner’I Editor of CRAN Task Views Empirical Finance and High
Performance ComputingI Mentor for two R-related projects (cran2deb; RPostgreSQL)
at Google Summer of CodeI Co-organizer of the first R in Finance conference in April
2009, Chicago (http://www.RinFinance.com)I useR! Tutorial lecturer on High Performance Computing
with R in 2008 and 2009, also at R / FinanceI Other work-related R projects (spawning the CRAN
packages RLim, RBloomberg; others unreleased)I Quantian (live cdrom/dvd) author / developerI Associate Editor at Journal of Statistical Software
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Outline
Background
About R and CRAN
Finance Task View
Selected Finance Packages
Summary and Outlook
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Where are we right now with R ?
I R has grown tremendously in recent years, both in terms ofcapabilities and users.
I Widespread and increasing use in Finance.I S+ has been almost entirely eclipsed by R, much to the
chagrin of Insightful.I We now also have three companies offering commercial
support and extensions.I CRAN, the R package archive network, has grown
tremendously too: now north of 1600 packages.I There is more and more Finance content as shown in the
task view.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Illustration: Growth of r-help and r-sig-finance
Year
Mea
n N
umbe
r of
Mes
sage
s / M
onth
1997 1999 2001 2003 2005 2007
2050
100
200
500
1000
2000
●
●
●
●
●
●
●
●●
●●
●● R−HelpR−SIG−Finance
Source: Fox (2008, 2009), our calculations.
I Total R usage is difficultto measure.
I Mailing list activity issometimes used as aproxy.
I While r-help growth isslowing, several ’specialinterest group’ lists suchas r-sig-financeexperience stronggrowth.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Illustration: Growth of CRAN packagesN
umbe
r of
CR
AN
Pac
kage
s
2001
−06
−21
2001
−12
−17
2002
−06
−12
2003
−05
−27
2003
−11
−16
2004
−06
−05
2004
−10
−12
2005
−06
−18
2005
−12
−16
2006
−05
−31
2006
−12
−12
2007
−04
−12
2007
−11
−16
2008
−03
−18
2008
−10
−20
100
200
300
400
500
600
800
1000
1200
1400
1700
1.3
1.4
1.5
1.7
1.8
1.9
2.0
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
110
129
162
219
273
357406
548
647739
9111000
13001427
1679
●
●
●
●
●
●
●
●
●
●
●●
●●
●
Source: Fox (2008, 2009), our calculations
I John Fox provided thischart in an invited lectureat the last useR!meetings.
I Details, and moremetrics on R and thedynamics of the R Coregroup, are also in aforthcoming R News(soon: R Journal) article.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Aside: CRANberries
Source:
http://dirk.eddelbuettel.com/cranberries/
I The CRANberries feedsummarizes bothchanges to existingpackages, as well asnew packages.
I Implemented in 200 linesof R and using the tinyblosxom blog engine, itis available as a blog andvia an RSS feed.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Outline
Background
About R and CRAN
Finance Task View
Selected Finance Packages
Summary and Outlook
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
CRAN and CRAN Task View Finance
I Given 1600+ CRAN packages, navigation is difficult.I Idea suggested a few years ago to have topical views.I These Task Views are not perfect, but the best currently
available approach at navigating CRAN packages.I We created the Empirical Finance view around 2004 which
contains several sections onI standard regression modelsI time seriesI financeI risk managementI books / data setsI date and data management
I Rather than repeating the task view, let us illustrate severaldifferent packages.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Finance Task View
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Outline
Background
About R and CRAN
Finance Task View
Selected Finance Packages
Summary and Outlook
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
RQuantLib (QuantLib Group; Eddelbuettel)
50 100 150
020
4060
80
option value
50 100 150
0.0
0.2
0.4
0.6
0.8
1.0
option delta
50 100 150
0.00
0.01
0.02
0.03
0.04
option gamma
50 100 150
010
2030
40
option vega
Strike is 100, maturity 1 year, riskless rate 0.03 Underlying price from 10 to 180
Volatility from 0.1 to 0.9
> example(EuropeanOptionArrays)
I QuantLib is a verycomplete and very wellwritten C++ library forquantitative finance.
I RQuantLib, firstreleased in 2002,provides access to asubset of QuantLib’sfunctionality directly fromR, in particular for(equity) option pricingand some yield curveanalysis.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Rmetrics (Wuertz et al)
● ● ●●●●●●●●●●● ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●
1e−03 1e−02 1e−01 1e+00 1e+01
0.0
0.2
0.4
0.6
0.8
1.0
Excess Distribution
Fu(x−u)
x [lo
g S
cale
]
u =
0.0
0059
9
● ● ●●●●●●●●●●● ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●
●
●
1e−03 1e−02 1e−01 1e+00 1e+01
5e−
045e
−03
5e−
025e
−01
Tail of Underlying Distribution
x [log scale]
1−F
(x)
[log
scal
e]
●
●
●
●
●
●●
●
●●●
●
●
●●●
●
●●
●●
●
●
●
●
●
●
●
●
●●
●
●●●
●
●
●
●
●
●
●
●
●
●●
●●
●●●●●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●●
●
●
●
●●
●
●
●
●
●●●
●
●
●●●
●
●
●
●
●
●●●
●
●●●●
●
●●●●
●●
●
●●
●
●
●
●
●
●
●
●
●●●
●
●
●●
●
●●
●
●
●
●
●
●
●
●●
●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●●
●●
●
●
●
●
●
●
●●
●
●
●
●
●●
●●
●
●
●
●
●●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●●
●●
●
●
●
●
●
●
●
●
●
●
●●●●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●●
●
●
●●●
●
●
●
●
●
●
●
●
●●●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●
●●
●
●
●
●
●
●●
●●
●
●
●
●
●●
●
●
●
●
●
●●●
●●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●●
●●●
●
●
●●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●●●●
●
●
●●●
●●
●
●
●
●
●
●●
●
●●
●●
●
●
●●
●
●
●●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●●
●
●
●
●●
●
●●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●●●
●
●●
●
●
●
●
●
●●
●●●
●
●
●
●
●
●
●
●
●
●●●●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●●●●
●
●
●
●
●●
●
●
●
●●
●
●
●
●●
●
●
●
●
●
●●
●
●
●●●
●
●
●
●
●
●
●
●
●
●
●●
●●
●●
●
●
●
●
●●
●
●
●
●
●●
●
●
●
●
●
●●
●●
●
●
●
●
●
●
●
●●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●●
●
●
●
●●
●
●
●●
●
●
●●
●
●●
●
●
●
●
●
●
●●
●
●●
●
●
●●●
●●
●
●
●●
●
●
●
●●●●
●
●
●
●
●
●
●
●
●
●●
●●
●
●
●
●
●
●●
●
●
●
●
●●●●
●●
●
●●
●
●●●
●
●
●●
●●
●
●
●
●
●●
●
●
●
●●
●
●●●●
●
●
●●
●
●●●
●●●
●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●●
●●
●●
●
●●
●
●
●
●●●
●
●●
●
●
●
●
●
●●●
●
●●
●●
●
●●●●
●
●
●
●
●
●●
●●
●
●●
●
●
●
●
●
●
●●●
●
●
●●●
●
●●
●
●
●
●
●
●
●●
●
●
●
●
●●
●●
●
●
●●●
●
●
●
●
●
●●●
●
●
●
●●●
●●●●
●
●
●
●
●●●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●●
●
●
●
●●
●
●●●
●
●
●
●
●
●
●
●
●
●●
●
●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●●
●
●●
●
●
●
●
●●
●●
●
●
●
●●●
●
●●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●●
●●●
●
●●
●
●
●●●●
●
●
●●
●
0 200 400 600 800 1000
01
23
45
6
Scatterplot of Residuals
Ordering
Res
idua
ls
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●
● ●●●●●●
●●●●●
●●●●●
●●
●
●
●
0 1 2 3 4 5 6
02
46
QQ−Plot of Residuals
Ordered Data
Exp
onen
tial Q
uant
iles
> example(GpdModelling)
I Rmetrics, first releasedin 2004 is acomprehensive set of Rpackages.
I It covers time series,GARCH and volatilitymodeling, Extreme ValueTheory and Copulae,derivative pricing,portfolio analysis,optimization and more.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
portfolio (Enos, Kane et al)
Cumulative Spread Return
Ret
urn
(%)
−20−10
01020
Mar May Jul Sep Nov
Total return: −2.7
Worst drawdown: −9
cap.usd
Mar May Jul Sep Nov
Total return: 28
Worst drawdown: −−
smi
Cumulative Quantile Return
Date
Ret
urn
(%)
0
10
20
30
Mar May Jul Sep Nov
cap.usd
Mar May Jul Sep Nov
smi
quantilehighQ9Q8Q7Q6Q5Q4Q3Q2low
> example(backtest)
I The portfoliopackage provides codeand data for real-lifeequity long/short portfolioanalysis.
I The portfolioSimpackage adds simulationsupport; the tradeCostpackage analysesex-post trade impact, andthe backtest packagepermits to test portfolios.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
PerformanceAnalytics (Carl and Peterson)
Equity.Market.Neutral
Returns
Den
sity
−0.010 −0.005 0.000 0.005 0.010 0.015 0.020 0.025
020
4060
8010
0
99 %
Mod
VaR
99%
VaR
> example(chart.Histogram)
I This package provides alibrary of econometricfunctions forperformance and riskanalysis of financialportfolios.
I It offers practioners andresearcher some of thelatest research inanalysis of both normaland non-normal returnstreams.
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Outline
Background
About R and CRAN
Finance Task View
Selected Finance Packages
Summary and Outlook
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Summary
I R is a very vibrant platform for data analysis, visualizationand programming with data.
I Hence, R provides an excellent platform for academicresearch and teaching — as well as investment researchand trading.
I Finance has traditionally been one of the two key users ofthe S language, and this constiuency has moved from S+to R.
I The number of dedicated Finance packages for R isincreasing as well, the R-Forge site is a good place towatch (http://R-Forge.R-Project.org).
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Outlook
If you don’t go with R now, you will someday.– David Kane on r-sig-finance, 30 Nov 2004
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
R / Finance in April 2009
Dirk Eddelbuettel Using R in Finance
Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Contact
http://dirk.eddelbuettel.com
Dirk Eddelbuettel Using R in Finance