• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Using R in Finance
 

Using R in Finance

on

  • 377 views

 

Statistics

Views

Total Views
377
Views on SlideShare
377
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Using R in Finance Using R in Finance Presentation 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 the 58th 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 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
    • 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
    • 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 ? 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
    • 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 qMean 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
    • 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 lectureNumber 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
    • 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
    • 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 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
    • 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) option value option delta 1.080 QuantLib is a very 0.860 complete and very well 0.640 written C++ library for 0.4 quantitative finance.20 0.2 0.0 RQuantLib, first0 50 100 150 50 100 150 option gamma option vega released in 2002, 400.04 provides access to a 300.03 subset of QuantLib’s0.02 20 functionality directly from R, in particular for0.01 10 (equity) option pricing0.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
    • Background About R and CRAN Finance Task View Selected Finance Packages Summary and Outlook Rmetrics (Wuertz et al) Excess Distribution Tail of Underlying Distribution 1.0 qq q qqq qq qq qq q q q q qq qq qqqq qqqqqqq q qq q q qqq qqqqqq q qqqqqqq q qqq q qq q qqqqq q qqq qq qq qq qqqq qqqq qqq qqq qqq 5e−01 q qqq qq qq qq qq q q qq qq qq qq qq qq q q qq qq qq qq q qq qq qq q qq q q q q q q q q qq q q q q q q q q q q qq q q 0.8 q q q qq q q q q Rmetrics, first released q q q q q q q q q q q q q q q q q q qq qq q q q q qq q q 1−F(x) [log scale] qq q qq q q q 5e−02 q q q q qq q qx [log Scale] q q 0.6 q q q q q q q q q q q q q q q q in 2004 is a q q q qq q q q q q q qq q q q q q qq q q q q q q qq qq q q 0.4 q q q q q q qq q q q 5e−03 q qq q q q q q comprehensive set of R q qq q qq q q q q q u = 0.000599 qq q q q q q q 0.2 q qq q q qq q q qq q qq q qqq q q qq qq qq qq q q packages. q qq qq q qq qq 5e−04 qq qq q q qq q qq q 0.0 q q q qq qq qqq q qq q q q q 1e−03 1e−02 1e−01 1e+00 1e+01 1e−03 1e−02 1e−01 1e+00 1e+01 Fu(x−u) x [log scale] It covers time series, Scatterplot of Residuals QQ−Plot of Residuals GARCH and volatility modeling, Extreme Value 6 q q q q q q q 5 q q q qq q Theory and Copulae, 6 q q q q q Exponential Quantiles q q qq q q q q q 4 q q q q q q q q q qqResiduals q qq q q q q qq q qqq derivative pricing, q q qq q qq q q q q q q q q qq q 4 q q q q q q qq q q qq 3 q qq q qq q q q q q q q qq q q q q q qqq q q q qq q qq qqq q qqq q qq q q qq qq q q qq q q q qq q q q q q q q qq q q q q q q q q qq q qq qq q q q q q qq q q q q q q q q q q q qq q qq q qq q q q q q q q q q qq 2 q q qq q qq qqq portfolio analysis, q q qqq qq q q qq q q qq q qq q q qq q qq q qq qq q q q qq qq qq q q q q q q qq qq qq qq q q q q q q q q qq qq qq qq q q q qqqqqqqqq q q q q qq q q qq q q qq q qq q qq 2 q qq q q qq q q q qq q q q q q qq q q qq qq qq qq q q q qq qq q q q qq q q q qq qq q q qqq qq q q qq qq qq qq q q q q q q q qq qq q q q q q qq q q q q q q q q qqq q q q q qqq q qq q q qq qq q q qq q q q qq qq q q qq q q qq q qq q q q qq q q qq q qq q q q qq qqqq qq qq q q qqq q q q q q qq qq qq q q q q qq q q q qq q q q qq qq 1 q qq q q qq q q qq q q q q q q qqq q q q q qq q q qq q q q qq q q q q q q q q q qq q q qq qq qq qq qq qq q q q q q q q qq qq qq qq q q q qqqq q q q q q q q q q q q q qq q qq q q qq qq qq q q qq q qq q q qqq qq q qqq qqq qqqq qq qq qq q q q qq qqqqqqqqq q qqq qq qq q qq q q qq q q q q q q qq q qqqq qq qq qq q qqqq qq qq qq qq qq q qq qq qq qq qq qq q qq qq q q q q q q qq optimization and more. qq q q qq q q qq qq q q qqq qq q q q qq qq q q q q q q qq q q q qq qq qq qq qq qq qq qq q q qqqqq q q qq qqqq qqq qqq qqq qqqq qqq qqqqq qqq q q qqq qq qq qq q q q q q qq q q qq qq q qq q q q q q q qqq q q qq q q q qqq qq qq q qq q qq q q q qqq q q qq q q qqq qqqqqqqq qqqqqqqqqqq qqqqqqqqqqqq q qqqqqqq qqqq qq q q qqq qq q qqqq qqqqq qqq q qq q q qq q qq qq qq q q qq q qq q q qq q qq q qq qq qq qq qqq q q q q q q q q q qq q q q q q qqq q qq q qq qq q qq q qqqqqqq qq qqq qq q q q qq q q q q q q q q q q q q q q q q q q q qq qq qq q qq qq qq qq qq qq 0 0 0 200 400 600 800 1000 0 1 2 3 4 5 6 Ordering Ordered Data > example(GpdModelling) 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 20 Total return: −2.7 cap.usd Total return: 28 smi The portfolioReturn (%) 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
    • 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 60Density 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
    • 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 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
    • 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.com Dirk Eddelbuettel Using R in Finance