Slideshare - ONS Economic Forum Slidepack - 18 March 2024.pptx
Using R in Finance
1. 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 the
58th Midwest Finance Association Meetings
Chicago, IL, March 5, 2009
Dirk Eddelbuettel Using R in Finance
2. 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
3. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Personal connections
Financial Econometrician by training, with twelve+ years as
a Quant in (Inv-)Banking, Hedge Funds, Prop Trading
Debian developer/contributor since 1995
Debian R co-maintainer since 1999, maintainer since 2001
R package author or co-author:
RQuantLib: R interface to the QuantLib libraries
digest: hash function ’digests’ of serialized R objects
random: R interface to true RNG via random.org
RDieHarder: R interface to DieHarder RNG testers
littler: R scripting front-end
RPostgreSQL: R interface to PostgreSQL RDBMS
Rcpp: C++ classes for extending R with C/C++ functions
RInside: C++ classes for embedding R in C++ programs
Dirk Eddelbuettel Using R in Finance
4. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Personal connections
Other R Open Source activities:
R-SIG-Finance, R-SIG-Debian, R-SIG-HPC list ’owner’
Editor of CRAN Task Views Empirical Finance and High
Performance Computing
Mentor for two R-related projects (cran2deb; RPostgreSQL)
at Google Summer of Code
Co-organizer of the first R in Finance conference in April
2009, Chicago (http://www.RinFinance.com)
useR! Tutorial lecturer on High Performance Computing
with R in 2008 and 2009, also at R / Finance
Other work-related R projects (spawning the CRAN
packages RLim, RBloomberg; others unreleased)
Quantian (live cdrom/dvd) author / developer
Associate Editor at Journal of Statistical Software
Dirk Eddelbuettel Using R in Finance
5. 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
6. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Where are we right now with R ?
R has grown tremendously in recent years, both in terms of
capabilities and users.
Widespread and increasing use in Finance.
S+ has been almost entirely eclipsed by R, much to the
chagrin of Insightful.
We now also have three companies offering commercial
support and extensions.
CRAN, the R package archive network, has grown
tremendously too: now north of 1600 packages.
There is more and more Finance content as shown in the
task view.
Dirk Eddelbuettel Using R in Finance
7. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Illustration: Growth of r-help and r-sig-finance
q R−Help q
R−SIG−Finance
2000
q
q
q
q
Total R usage is difficult
q
to measure.
1000
q
Mean Number of Messages / Month
q Mailing list activity is
500
q sometimes used as a
proxy.
200
q
While r-help growth is
q slowing, several ’special
100
interest group’ lists such
q
50
as r-sig-finance
experience strong
growth.
20
1997 1999 2001 2003 2005 2007
Year
Source: Fox (2008, 2009), our calculations.
Dirk Eddelbuettel Using R in Finance
8. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Illustration: Growth of CRAN packages
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
1700 q 1679
1400 q 1427
1200
q 1300
John Fox provided this
1000 q 1000
800
q 911 chart in an invited lecture
Number of CRAN Packages
q 739
600
q 647 at the last useR!
q 548
500 meetings.
400 q 406
q 357 Details, and more
300
q 273
metrics on R and the
q 219
200 dynamics of the R Core
q 162
q 129
group, are also in a
100
q 110 forthcoming R News
(soon: R Journal) article.
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
Source: Fox (2008, 2009), our calculations
Dirk Eddelbuettel Using R in Finance
9. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Aside: CRANberries
The CRANberries feed
summarizes both
changes to existing
packages, as well as
new packages.
Implemented in 200 lines
of R and using the tiny
blosxom blog engine, it
is available as a blog and
via an RSS feed.
Source:
http://dirk.eddelbuettel.com/cranberries/
Dirk Eddelbuettel Using R in Finance
10. 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
11. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
CRAN and CRAN Task View Finance
Given 1600+ CRAN packages, navigation is difficult.
Idea suggested a few years ago to have topical views.
These Task Views are not perfect, but the best currently
available approach at navigating CRAN packages.
We created the Empirical Finance view around 2004 which
contains several sections on
standard regression models
time series
finance
risk management
books / data sets
date and data management
Rather than repeating the task view, let us illustrate several
different packages.
Dirk Eddelbuettel Using R in Finance
12. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Finance Task View
Dirk Eddelbuettel Using R in Finance
13. 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
14. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
RQuantLib (QuantLib Group; Eddelbuettel)
option value option delta
1.0
80
QuantLib is a very
0.8
60
complete and very well
0.6
40
written C++ library for
0.4 quantitative finance.
20
0.2
0.0
RQuantLib, first
0
50 100 150 50 100 150
option gamma option vega released in 2002,
40
0.04
provides access to a
30
0.03
subset of QuantLib’s
0.02
20
functionality directly from
R, in particular for
0.01
10
(equity) option pricing
0.00
0
50 100 150 50
Strike is 100, maturity 1 year, riskless rate 0.03
100 150
and some yield curve
Underlying price from 10 to 180
Volatility from 0.1 to 0.9 analysis.
> example(EuropeanOptionArrays)
Dirk Eddelbuettel Using R in Finance
16. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
portfolio (Enos, Kane et al)
Cumulative Spread Return
20
Total return: −2.7
cap.usd
Total return: 28
smi
The portfolio
Return (%)
10
0 package provides code
−10
−20
Worst drawdown: −9 Worst drawdown: −− and data for real-life
Mar May Jul Sep Nov Mar May Jul Sep Nov
equity long/short portfolio
Cumulative Quantile Return analysis.
cap.usd smi The portfolioSim
30
quantile package adds simulation
high
Q9
Q8 support; the tradeCost
Return (%)
Q7
20 Q6
Q5
Q4
package analyses
Q3
10 Q2
low ex-post trade impact, and
0 the backtest package
Mar May Jul Sep Nov Mar May Jul Sep Nov permits to test portfolios.
Date
> example(backtest)
Dirk Eddelbuettel Using R in Finance
17. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
PerformanceAnalytics (Carl and Peterson)
Equity.Market.Neutral
This package provides a
99% VaR
99 % ModVaR
library of econometric
100
functions for
80
performance and risk
analysis of financial
60
Density
portfolios.
It offers practioners and
40
researcher some of the
latest research in
20
analysis of both normal
0
and non-normal return
−0.010 −0.005 0.000 0.005 0.010 0.015 0.020 0.025
streams.
Returns
> example(chart.Histogram)
Dirk Eddelbuettel Using R in Finance
18. 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
19. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Summary
R is a very vibrant platform for data analysis, visualization
and programming with data.
Hence, R provides an excellent platform for academic
research and teaching — as well as investment research
and trading.
Finance has traditionally been one of the two key users of
the S language, and this constiuency has moved from S+
to R.
The number of dedicated Finance packages for R is
increasing as well, the R-Forge site is a good place to
watch (http://R-Forge.R-Project.org).
Dirk Eddelbuettel Using R in Finance
20. 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
21. 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
22. Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook
Contact
http://dirk.eddelbuettel.com
dirk@eddelbuettel.com
Dirk Eddelbuettel Using R in Finance