SlideShare une entreprise Scribd logo
1  sur  18
Télécharger pour lire hors ligne
Introduction   Extension Architecture    Real-Time Interface   Historical Interface   Implementation Notes   Future Work




                Building Market Data
                  Interfaces For R
                                           Rory Winston




                                        rory@theresearchkitchen.com
Introduction     Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Contents



       1       Introduction

       1       Extension Architecture

       1       Real-Time Interface

       1       Historical Interface

       1       Implementation Notes

       1       Future Work
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




About Me




               Independent Software Consultant
               M.Sc. Applied Computing, 2000
               M.Sc. Finance, 2008
               Working in the financial sector, building trading systems in
               Java/C++
               Interested in practical applications of functional languages and
               machine learning
               Relatively recent convert to R
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




The Reuters Marketfeed System


               Ubiquitous (especially in Foreign Exchange)
               APIs, Excel plugins, graphical workbenches, and trading GUIs
               Used by traders, structurers, quants, analysts....
               A market data item is identified by a RIC (Reuters Information
               Code)
               Format: CODE=[specifiers]
               Examples (FX): EUR=, EUR=EBS, GBPJPY=D2
               Examples (Equities): MSFT.O, IBM.N
               Examples (Fixed Income): EUR3M=, US30YT=RR
               Each market data item contains a number of data fields, e.g.
               BID, ASK
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Reuters Desktop

       Example Reuters 3000 session:
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Reuters Interfaces
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Extension Architecture
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Potential Uses:



               Testing real-time trading algorithms
               Market data collection and validation
               Dynamic portfolio optimization algorithms
               Trading cost / spread analysis
               Real-time interest rate curve building
               Econometric analysis
               Applying R’s vast library of computational statistics and
               machine learning routines to tick data
               Turn R into a "trading workbench"
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Example - Real Time Subscription


       Real-time interface:

                   rsub <- function(duration, items, callback)


       The call rsub will subscribe to the specified rate(s) for the duration
       of time specified by duration (ms). When a tick arrives, the
       callback function callback is invoked, with a data frame
       containing the fields specified in items.

       Multiple market data items may be subscribed to, and any
       combination of fields may be be specified.

       Uses the underlying RFA API, which provides a C++ interface to
       real-time market updates.
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Real-Time Example


       # Specify field names to retrieve
       fields <- c("BID","ASK","TIMCOR")

       # Subscribe to EUR/USD and GBP/USD ticks
       items <- list()
       items[[1]] <- c("IDN_SELECTFEED", "EUR=", fields)
       items[[2]] <- c("IDN_SELECTFEED", "GBP=", fields)

       # Simple Callback Function
       f <- function(df) { print(paste("Received",df)) }

       # Subscribe for 1 hour
       ONE_HOUR <- 1000*(60)^2
       rsub(ONE_HOUR, items, callback)
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Real-Time C++ Interface


       I used the .Call interface, as it enabled me to easily deal with the
       data frame arguments and callback functions.


       DL_EXPORT SEXP subscribe(SEXP t, SEXP spec, SEXP callback) {
       ...
       }



       Boost provides nice type-based visitor functionality, which I use to
       convert between Reuters wire-level data type and native R
       SEXP-based types.
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Example - Historical Fetch


       Historical interface:

         fetch <- function(code, n=0, t="d", sd=NULL, ed=NULL)



       Returns a data frame with data specified by code. The number of
       items returned can be specified by n, or it is defined as the number
       of items of the specified periodicity t (e.g. "d" = "daily") between
       start date sd and end date ed.

       Uses the Reuters SFC API to obtain historical data.
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Historical Interface Examples

       > fetch("IBM.N", n=20)
                Date    CLS    OPN     HI     LO      VOL   VWAP
       1 2008-07-31 127.98 127.77 129.50 127.76 2334800 128.4172
       2 2008-07-30 128.86 128.42 129.00 127.10 1936400 128.2872
       ...
       > fetch("EUR=", sd="1/1/2007", ed="1/1/2008")
                 Date    BID    OPN     HI     LO     ASK
       1   2008-01-01 1.4587 1.4585 1.4608 1.4576 1.4591
       2   2007-12-31 1.4589 1.4719 1.4747 1.4568 1.4592
       ...
       > fetch("EUR3M=", n=20, t="w")
                Date    BID    OPN     HI     LO     ASK
       1 2008-07-25 -75.60 -77.60 -74.96 -79.30 -74.41
       2 2008-07-18 -76.94 -76.30 -75.44 -81.10 -76.04
       ...
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Historical Interface Example




       msft.vol <- fetch("MSFT.O",sd="1/1/2008",ed="7/1/2008")

       layout(matrix(c(1,1,1,1,2,2), 3, 2, T))

       plot(msft.vol$Date, msft.vol$CLS,
        main="MSFT Close Price", type="l", ylab="", xlab="Date")

       plot(msft.vol$Date, msft.vol$VOL,
        main="Volume", type='h', ylab="", xlab="")
Introduction   Extension Architecture     Real-Time Interface       Historical Interface   Implementation Notes   Future Work




Historical Interface Example

                                                         MSFT Close Price




                          34
                          32
                          30
                          28




                                    Jan            Mar                      May                   Jul

                                                                 Date



                                                                Volume
                          2.0e+08
                          5.0e+07




                                    Jan            Mar                      May                   Jul
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Historical Fetch C++ Interface



       Again using the .Call interface:



       DL_EXPORT SEXP fetch(SEXP item, SEXP nItems,
        SEXP intervalCode, SEXP startDate, SEXP endDate) {
       ...



       Code handles missing dates (e.g. market holidays), and coercion of
       underlying datatypes to appropriate R datatypes
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Notes on Implementation

               Reuters Issues:
                      Reuters APIs are generally awful (newer APIs, i.e. RFA are slightly
                      better)
                      Confusing / inconsistent functionality; Peculiarities with C++
                      runtime
               R-related issues:
                      Generally very few, once you get used to the idiosyncratic
                      "Lisp-via-C-macros" style;
                      Some issues with asynchronous real-time updates and the
                      single-threaded R interpreter
               The combination of Boost, C++ and R is extremely powerful
               Combining this with market data functionality adds a new
               dimension of capabilities
               FX, options, futures, forwards, interest rates, bonds, indices,
               equities...even news updates
Introduction   Extension Architecture   Real-Time Interface   Historical Interface   Implementation Notes   Future Work




Future Work


       There are still some issues to work on, mainly some configuration
       and threading issues in the real-time extension

       Mathworks bundle a number of financial data feed providers in their
       DataFeed toolbox for Matlab:
       http://www.mathworks.com/products/datafeed/
       Maybe a similar extension (bundling say, connections to Reuters,
       Bloomberg, Lim, Thomson, etc) for R may be a useful addition?

       A financial "showcase application" for R would be great: maybe a
       financial analysts’ toolkit, similar to the Holt system (combining
       elements of statistical learning and quantitative accounting
       analysis).

Contenu connexe

Similaire à Real-TIme Market Data in R

Microsoft SQL Server - StreamInsight Overview Presentation
Microsoft SQL Server - StreamInsight Overview PresentationMicrosoft SQL Server - StreamInsight Overview Presentation
Microsoft SQL Server - StreamInsight Overview Presentation
Microsoft Private Cloud
 
What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?
ukdpe
 
CoverPage_Resume V2
CoverPage_Resume V2CoverPage_Resume V2
CoverPage_Resume V2
Gary Lewis
 
Core .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsCore .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 Enhancements
Robert MacLean
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
Talbott Crowell
 
Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)
Paulo Gandra de Sousa
 

Similaire à Real-TIme Market Data in R (20)

Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
 
Microsoft SQL Server - StreamInsight Overview Presentation
Microsoft SQL Server - StreamInsight Overview PresentationMicrosoft SQL Server - StreamInsight Overview Presentation
Microsoft SQL Server - StreamInsight Overview Presentation
 
Extending Flux - Writing Your Own Functions by Adam Anthony
Extending Flux - Writing Your Own Functions by Adam AnthonyExtending Flux - Writing Your Own Functions by Adam Anthony
Extending Flux - Writing Your Own Functions by Adam Anthony
 
pythonOCC PDE2009 presentation
pythonOCC PDE2009 presentationpythonOCC PDE2009 presentation
pythonOCC PDE2009 presentation
 
What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?
 
SQL Server 2008 Overview
SQL Server 2008 OverviewSQL Server 2008 Overview
SQL Server 2008 Overview
 
Reactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and RxReactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and Rx
 
Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data. Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data.
 
CoverPage_Resume V2
CoverPage_Resume V2CoverPage_Resume V2
CoverPage_Resume V2
 
F sharp - an overview
F sharp - an overviewF sharp - an overview
F sharp - an overview
 
OneTick and the R mathematical language, a presentation from R in Finance
OneTick and the R mathematical language, a presentation from R in FinanceOneTick and the R mathematical language, a presentation from R in Finance
OneTick and the R mathematical language, a presentation from R in Finance
 
Core .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsCore .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 Enhancements
 
2021 04-20 apache arrow and its impact on the database industry.pptx
2021 04-20  apache arrow and its impact on the database industry.pptx2021 04-20  apache arrow and its impact on the database industry.pptx
2021 04-20 apache arrow and its impact on the database industry.pptx
 
Python business intelligence (PyData 2012 talk)
Python business intelligence (PyData 2012 talk)Python business intelligence (PyData 2012 talk)
Python business intelligence (PyData 2012 talk)
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
 
PoEAA by Example
PoEAA by ExamplePoEAA by Example
PoEAA by Example
 
Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)
 
Complex Event Processing: What?, Why?, How?
Complex Event Processing: What?, Why?, How?Complex Event Processing: What?, Why?, How?
Complex Event Processing: What?, Why?, How?
 
Benefits of Using MongoDB Over RDBMSs
Benefits of Using MongoDB Over RDBMSsBenefits of Using MongoDB Over RDBMSs
Benefits of Using MongoDB Over RDBMSs
 
Data Pipeline at Tapad
Data Pipeline at TapadData Pipeline at Tapad
Data Pipeline at Tapad
 

Plus de Rory Winston (6)

Building A Trading Desk On Analytics
Building A Trading Desk On AnalyticsBuilding A Trading Desk On Analytics
Building A Trading Desk On Analytics
 
The Modern FX Desk
The Modern FX DeskThe Modern FX Desk
The Modern FX Desk
 
KDB+/R Integration
KDB+/R IntegrationKDB+/R Integration
KDB+/R Integration
 
An Analytics Toolkit Tour
An Analytics Toolkit TourAn Analytics Toolkit Tour
An Analytics Toolkit Tour
 
Creating R Packages
Creating R PackagesCreating R Packages
Creating R Packages
 
Streaming Data and Concurrency in R
Streaming Data and Concurrency in RStreaming Data and Concurrency in R
Streaming Data and Concurrency in R
 

Dernier

Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
amitlee9823
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
dlhescort
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
lizamodels9
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
daisycvs
 

Dernier (20)

Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 

Real-TIme Market Data in R

  • 1. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Building Market Data Interfaces For R Rory Winston rory@theresearchkitchen.com
  • 2. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Contents 1 Introduction 1 Extension Architecture 1 Real-Time Interface 1 Historical Interface 1 Implementation Notes 1 Future Work
  • 3. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work About Me Independent Software Consultant M.Sc. Applied Computing, 2000 M.Sc. Finance, 2008 Working in the financial sector, building trading systems in Java/C++ Interested in practical applications of functional languages and machine learning Relatively recent convert to R
  • 4. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work The Reuters Marketfeed System Ubiquitous (especially in Foreign Exchange) APIs, Excel plugins, graphical workbenches, and trading GUIs Used by traders, structurers, quants, analysts.... A market data item is identified by a RIC (Reuters Information Code) Format: CODE=[specifiers] Examples (FX): EUR=, EUR=EBS, GBPJPY=D2 Examples (Equities): MSFT.O, IBM.N Examples (Fixed Income): EUR3M=, US30YT=RR Each market data item contains a number of data fields, e.g. BID, ASK
  • 5. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Reuters Desktop Example Reuters 3000 session:
  • 6. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Reuters Interfaces
  • 7. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Extension Architecture
  • 8. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Potential Uses: Testing real-time trading algorithms Market data collection and validation Dynamic portfolio optimization algorithms Trading cost / spread analysis Real-time interest rate curve building Econometric analysis Applying R’s vast library of computational statistics and machine learning routines to tick data Turn R into a "trading workbench"
  • 9. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Example - Real Time Subscription Real-time interface: rsub <- function(duration, items, callback) The call rsub will subscribe to the specified rate(s) for the duration of time specified by duration (ms). When a tick arrives, the callback function callback is invoked, with a data frame containing the fields specified in items. Multiple market data items may be subscribed to, and any combination of fields may be be specified. Uses the underlying RFA API, which provides a C++ interface to real-time market updates.
  • 10. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Real-Time Example # Specify field names to retrieve fields <- c("BID","ASK","TIMCOR") # Subscribe to EUR/USD and GBP/USD ticks items <- list() items[[1]] <- c("IDN_SELECTFEED", "EUR=", fields) items[[2]] <- c("IDN_SELECTFEED", "GBP=", fields) # Simple Callback Function f <- function(df) { print(paste("Received",df)) } # Subscribe for 1 hour ONE_HOUR <- 1000*(60)^2 rsub(ONE_HOUR, items, callback)
  • 11. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Real-Time C++ Interface I used the .Call interface, as it enabled me to easily deal with the data frame arguments and callback functions. DL_EXPORT SEXP subscribe(SEXP t, SEXP spec, SEXP callback) { ... } Boost provides nice type-based visitor functionality, which I use to convert between Reuters wire-level data type and native R SEXP-based types.
  • 12. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Example - Historical Fetch Historical interface: fetch <- function(code, n=0, t="d", sd=NULL, ed=NULL) Returns a data frame with data specified by code. The number of items returned can be specified by n, or it is defined as the number of items of the specified periodicity t (e.g. "d" = "daily") between start date sd and end date ed. Uses the Reuters SFC API to obtain historical data.
  • 13. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Historical Interface Examples > fetch("IBM.N", n=20) Date CLS OPN HI LO VOL VWAP 1 2008-07-31 127.98 127.77 129.50 127.76 2334800 128.4172 2 2008-07-30 128.86 128.42 129.00 127.10 1936400 128.2872 ... > fetch("EUR=", sd="1/1/2007", ed="1/1/2008") Date BID OPN HI LO ASK 1 2008-01-01 1.4587 1.4585 1.4608 1.4576 1.4591 2 2007-12-31 1.4589 1.4719 1.4747 1.4568 1.4592 ... > fetch("EUR3M=", n=20, t="w") Date BID OPN HI LO ASK 1 2008-07-25 -75.60 -77.60 -74.96 -79.30 -74.41 2 2008-07-18 -76.94 -76.30 -75.44 -81.10 -76.04 ...
  • 14. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Historical Interface Example msft.vol <- fetch("MSFT.O",sd="1/1/2008",ed="7/1/2008") layout(matrix(c(1,1,1,1,2,2), 3, 2, T)) plot(msft.vol$Date, msft.vol$CLS, main="MSFT Close Price", type="l", ylab="", xlab="Date") plot(msft.vol$Date, msft.vol$VOL, main="Volume", type='h', ylab="", xlab="")
  • 15. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Historical Interface Example MSFT Close Price 34 32 30 28 Jan Mar May Jul Date Volume 2.0e+08 5.0e+07 Jan Mar May Jul
  • 16. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Historical Fetch C++ Interface Again using the .Call interface: DL_EXPORT SEXP fetch(SEXP item, SEXP nItems, SEXP intervalCode, SEXP startDate, SEXP endDate) { ... Code handles missing dates (e.g. market holidays), and coercion of underlying datatypes to appropriate R datatypes
  • 17. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Notes on Implementation Reuters Issues: Reuters APIs are generally awful (newer APIs, i.e. RFA are slightly better) Confusing / inconsistent functionality; Peculiarities with C++ runtime R-related issues: Generally very few, once you get used to the idiosyncratic "Lisp-via-C-macros" style; Some issues with asynchronous real-time updates and the single-threaded R interpreter The combination of Boost, C++ and R is extremely powerful Combining this with market data functionality adds a new dimension of capabilities FX, options, futures, forwards, interest rates, bonds, indices, equities...even news updates
  • 18. Introduction Extension Architecture Real-Time Interface Historical Interface Implementation Notes Future Work Future Work There are still some issues to work on, mainly some configuration and threading issues in the real-time extension Mathworks bundle a number of financial data feed providers in their DataFeed toolbox for Matlab: http://www.mathworks.com/products/datafeed/ Maybe a similar extension (bundling say, connections to Reuters, Bloomberg, Lim, Thomson, etc) for R may be a useful addition? A financial "showcase application" for R would be great: maybe a financial analysts’ toolkit, similar to the Holt system (combining elements of statistical learning and quantitative accounting analysis).