SlideShare a Scribd company logo
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).

More Related Content

Similar to Real-TIme Market Data in R

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 ...
Flink Forward
 
Microsoft SQL Server - StreamInsight Overview Presentation
Microsoft SQL Server - StreamInsight Overview PresentationMicrosoft SQL Server - StreamInsight Overview Presentation
Microsoft SQL Server - StreamInsight Overview PresentationMicrosoft Private Cloud
 
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
InfluxData
 
pythonOCC PDE2009 presentation
pythonOCC PDE2009 presentationpythonOCC PDE2009 presentation
pythonOCC PDE2009 presentation
Thomas Paviot
 
SQL Server 2008 Overview
SQL Server 2008 OverviewSQL Server 2008 Overview
SQL Server 2008 Overview
Eric Nelson
 
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
 
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
Sumant Tambe
 
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.
Keshav Murthy
 
CoverPage_Resume V2
CoverPage_Resume V2CoverPage_Resume V2
CoverPage_Resume V2Gary Lewis
 
F sharp - an overview
F sharp - an overviewF sharp - an overview
F sharp - an overview
Christoph Santschi
 
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
OneMarketData, LLC
 
Core .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsCore .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsRobert MacLean
 
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
Andrew Lamb
 
Python business intelligence (PyData 2012 talk)
Python business intelligence (PyData 2012 talk)Python business intelligence (PyData 2012 talk)
Python business intelligence (PyData 2012 talk)
Stefan Urbanek
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#Talbott Crowell
 
PoEAA by Example
PoEAA by ExamplePoEAA by Example
PoEAA by Example
Paulo Gandra de Sousa
 
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
 
Complex Event Processing: What?, Why?, How?
Complex Event Processing: What?, Why?, How?Complex Event Processing: What?, Why?, How?
Complex Event Processing: What?, Why?, How?
Alexandre Vasseur
 
Benefits of Using MongoDB Over RDBMSs
Benefits of Using MongoDB Over RDBMSsBenefits of Using MongoDB Over RDBMSs
Benefits of Using MongoDB Over RDBMSs
MongoDB
 
Data Pipeline at Tapad
Data Pipeline at TapadData Pipeline at Tapad
Data Pipeline at Tapad
Toby Matejovsky
 

Similar to 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
 
SQL Server 2008 Overview
SQL Server 2008 OverviewSQL Server 2008 Overview
SQL Server 2008 Overview
 
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?
 
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
 

More from Rory Winston

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

More from 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
 

Recently uploaded

buy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accountsbuy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accounts
Susan Laney
 
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s DholeraTata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Avirahi City Dholera
 
LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024
Lital Barkan
 
Observation Lab PowerPoint Assignment for TEM 431
Observation Lab PowerPoint Assignment for TEM 431Observation Lab PowerPoint Assignment for TEM 431
Observation Lab PowerPoint Assignment for TEM 431
ecamare2
 
Building Your Employer Brand with Social Media
Building Your Employer Brand with Social MediaBuilding Your Employer Brand with Social Media
Building Your Employer Brand with Social Media
LuanWise
 
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
bosssp10
 
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
taqyed
 
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdfMeas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
dylandmeas
 
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdfModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
fisherameliaisabella
 
Premium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern BusinessesPremium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern Businesses
SynapseIndia
 
Chapter 7 Final business management sciences .ppt
Chapter 7 Final business management sciences .pptChapter 7 Final business management sciences .ppt
Chapter 7 Final business management sciences .ppt
ssuser567e2d
 
Authentically Social Presented by Corey Perlman
Authentically Social Presented by Corey PerlmanAuthentically Social Presented by Corey Perlman
Authentically Social Presented by Corey Perlman
Corey Perlman, Social Media Speaker and Consultant
 
Exploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social DreamingExploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social Dreaming
Nicola Wreford-Howard
 
Creative Web Design Company in Singapore
Creative Web Design Company in SingaporeCreative Web Design Company in Singapore
Creative Web Design Company in Singapore
techboxsqauremedia
 
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challengesEvent Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Holger Mueller
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
agatadrynko
 
Recruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media MasterclassRecruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media Masterclass
LuanWise
 
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdfThe 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
thesiliconleaders
 
Project File Report BBA 6th semester.pdf
Project File Report BBA 6th semester.pdfProject File Report BBA 6th semester.pdf
Project File Report BBA 6th semester.pdf
RajPriye
 
Digital Transformation and IT Strategy Toolkit and Templates
Digital Transformation and IT Strategy Toolkit and TemplatesDigital Transformation and IT Strategy Toolkit and Templates
Digital Transformation and IT Strategy Toolkit and Templates
Aurelien Domont, MBA
 

Recently uploaded (20)

buy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accountsbuy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accounts
 
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s DholeraTata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
 
LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024
 
Observation Lab PowerPoint Assignment for TEM 431
Observation Lab PowerPoint Assignment for TEM 431Observation Lab PowerPoint Assignment for TEM 431
Observation Lab PowerPoint Assignment for TEM 431
 
Building Your Employer Brand with Social Media
Building Your Employer Brand with Social MediaBuilding Your Employer Brand with Social Media
Building Your Employer Brand with Social Media
 
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
 
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
 
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdfMeas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
 
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdfModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
ModelingMarketingStrategiesMKS.CollumbiaUniversitypdf
 
Premium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern BusinessesPremium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern Businesses
 
Chapter 7 Final business management sciences .ppt
Chapter 7 Final business management sciences .pptChapter 7 Final business management sciences .ppt
Chapter 7 Final business management sciences .ppt
 
Authentically Social Presented by Corey Perlman
Authentically Social Presented by Corey PerlmanAuthentically Social Presented by Corey Perlman
Authentically Social Presented by Corey Perlman
 
Exploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social DreamingExploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social Dreaming
 
Creative Web Design Company in Singapore
Creative Web Design Company in SingaporeCreative Web Design Company in Singapore
Creative Web Design Company in Singapore
 
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challengesEvent Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
Event Report - SAP Sapphire 2024 Orlando - lots of innovation and old challenges
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
 
Recruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media MasterclassRecruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media Masterclass
 
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdfThe 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
 
Project File Report BBA 6th semester.pdf
Project File Report BBA 6th semester.pdfProject File Report BBA 6th semester.pdf
Project File Report BBA 6th semester.pdf
 
Digital Transformation and IT Strategy Toolkit and Templates
Digital Transformation and IT Strategy Toolkit and TemplatesDigital Transformation and IT Strategy Toolkit and Templates
Digital Transformation and IT Strategy Toolkit and Templates
 

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).