Beruflich Dokumente
Kultur Dokumente
High-Frequency
Financial Data Analysis
Guy Yollin
Principal Consultant, r-programming.org
Scott Payseur
Quantitative Analyst, UBS Global Asset Management
Yollin/Payseur (Copyright
2011)
R/Finance 2011
1 / 100
Guy Yollin
Professional Experience
Software Engineering
r-programming.org
Insightful Corporation
Electro Scientific Industries, Vision Products Division
Hedge Fund
Rotella Capital Management
J.E. Moody, LLC
Academic
University of Washington
Oregon Health & Science University
Education
Oregon Health & Science University, MS Computational Finance
Drexel University, BS Electrical Engineering
Yollin/Payseur (Copyright
2011)
R/Finance 2011
2 / 100
Scott Payseur
Professional Experience
Finance Industry
UBS Global Asset Management
Insightful Corporation
Software Engineering
ESPN.COM
ShareBuilder.com
Academic
PhD, Financial Ecomometrics, University of Washington
Author of Realized R Package (available on CRAN)
Education
University of Washington, PhD Economics
University of Colorado, BS Computer Science
Yollin/Payseur (Copyright
2011)
R/Finance 2011
3 / 100
Outline
Wrap-Up
Yollin/Payseur (Copyright
2011)
R/Finance 2011
4 / 100
Legal Disclaimer
This presentation is for informational purposes
This presentation should not be construed as a solicitation or offering
of investment services
The presentation does not intend to provide investment advice
The information in this presentation should not be construed as an
offer to buy or sell, or the solicitation of an offer to buy or sell any
security, or as a recommendation or advice about the purchase or sale
of any security
The presenter(s) shall not shall be liable for any errors or inaccuracies
in the information presented
There are no warranties, expressed or implied, as to accuracy,
completeness, or results obtained from any information presented
INVESTING ALWAYS INVOLVES RISK
Yollin/Payseur (Copyright
2011)
R/Finance 2011
5 / 100
Outline
Wrap-Up
Yollin/Payseur (Copyright
2011)
R/Finance 2011
6 / 100
class
ts
mts
timeSeries
zoo
xts
Yollin/Payseur (Copyright
package
base
base
rmetrics
zoo
xts
2011)
overview
regularly spaced time series
multiple regularly spaced time series
default for Rmetrics packages
reg/irreg and arbitrary time stamp classes
an extension of the zoo class
R/Finance 2011
7 / 100
What is high-frequency?
High-frequency begins when indexing by date alone is not enough
beyond the capabilities of zoo objects with Date indexes
intra-day bars
tick data
Yollin/Payseur (Copyright
2011)
Low frequency
zoo
Date
High Frequency
xts
POSIXlt
R/Finance 2011
8 / 100
2011)
R/Finance 2011
9 / 100
Date-time classes
POSIXct represents time and date as the number of seconds since
1970-01-01
POSIXlt represents time and date as 9 calendar and time components
R Code:
> d <- Sys.time()
> class(d)
[1] "POSIXct" "POSIXt"
> unclass(d)
[1] 1304350062
> sapply(unclass(as.POSIXlt(d)), function(x) x)
sec
41.71847
isdst
0.00000
min
27.00000
Yollin/Payseur (Copyright
hour
15.00000
2011)
mday
2.00000
mon
year
4.00000 111.00000
wday
yday
1.00000 121.00000
R/Finance 2011
10 / 100
Arguments:
x vector of character strings to be converted to POSIXlt
objects
format date-time format specification
tz timezone to use for conversion
Return value:
POSIXlt object(s)
Yollin/Payseur (Copyright
2011)
R/Finance 2011
11 / 100
Arguments:
x data matrix (or vector) with time series data
order.by vector of unique times/dates (POSIXct is recommended)
Return value:
xts object
Yollin/Payseur (Copyright
2011)
R/Finance 2011
12 / 100
Outline
Wrap-Up
Yollin/Payseur (Copyright
2011)
R/Finance 2011
13 / 100
IBrokers
IB TWS
R session
Description
Provides native R access to Interactive Brokers Trader Workstation
Key features
real-time market data feed: reqMktData, reqRealTimeBars
live order execution: placeOrder, cancelOrder, reqAccountUpdates
historic data: reqHistoricalData
software comes with NO WARRANTY
Authors
Jeffrey Ryan
Yollin/Payseur (Copyright
2011)
R/Finance 2011
14 / 100
Connecting to IB
R Code: Get real-time market data from IB
>
>
>
>
library(IBrokers)
tws <- twsConnect()
reqMktData(tws, twsFuture("GC","NYMEX","201106"))
twsDisconnect(tws)
Yollin/Payseur (Copyright
2011)
R/Finance 2011
15 / 100
reqMktData events
Yollin/Payseur (Copyright
2011)
R/Finance 2011
16 / 100
Logging IB data
R Code: Log IB data to a file (default settings)
> reqMktData(tws, future1, file = "QM3.dat")
Yollin/Payseur (Copyright
2011)
R/Finance 2011
17 / 100
Logging IB data
R Code: Log individual IB messages
> reqMktData(tws, future1, CALLBACK = NULL, file = "QM2.dat")
Yollin/Payseur (Copyright
2011)
R/Finance 2011
18 / 100
reqMktData messaging
tick price (message = 1)
last price (tick type = 4)
Yollin/Payseur (Copyright
2011)
R/Finance 2011
19 / 100
volume
stamp
size
last
Mar 30 09:23:34
Yollin/Payseur (Copyright
2011)
Mar 30 09:33:15
Mar 30 09:37:10
R/Finance 2011
20 / 100
Logging IB data
R Code: Log IB updates in csv format
> reqMktData(tws, future1, eventWrapper=eWrapper.MktData.CSV(1), file=qm.csv)
Yollin/Payseur (Copyright
2011)
R/Finance 2011
21 / 100
>
>
>
>
options(digits.secs = 3)
options(digits=12)
library(xts)
dat <- read.table(file=paste(data.path,"QM.csv",sep=""),sep=",",
header=F,as.is=T)
> colnames(dat) <- c("TimeStamp","BidSize","Bid","Ask","AskSize","Last",
"LastSize","Volume")
> head(dat,4)
1
2
3
4
20110417
20110417
20110417
20110417
TimeStamp BidSize
Bid
Ask AskSize Last LastSize Volume
21:37:53.437000
NA
NA
NA
NA
NA
NA
343
21:37:53.623000
4 109.7
NA
NA
NA
NA
NA
21:37:53.623000
4
NA
NA
NA
NA
NA
NA
21:37:53.624000
NA
NA 109.75
12
NA
NA
NA
Yollin/Payseur (Copyright
2011)
R/Finance 2011
22 / 100
21:37:53.437
21:37:53.623
21:37:53.623
21:37:53.624
21:37:53.624
21:37:53.718
Yollin/Payseur (Copyright
2011)
BidSize
Bid
Ask AskSize Last LastSize Volume
NA
NA
NA
NA
NA
NA
343
4 109.7
NA
NA
NA
NA
NA
4
NA
NA
NA
NA
NA
NA
NA
NA 109.75
12
NA
NA
NA
NA
NA
NA
12
NA
NA
NA
9
NA
NA
NA
NA
NA
NA
High-Frequency Financial Data Analysis
R/Finance 2011
23 / 100
Fill in NAs
R Code: Fill in NAs with na.locf
> x <- na.locf(x.raw)
> x['2011-04-17 21:45',]
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
21:45:05.668
21:45:06.668
21:45:07.168
21:45:09.418
21:45:09.419
21:45:10.418
21:45:10.419
21:45:24.764
21:45:40.669
21:45:45.673
21:45:46.673
BidSize
1
1
1
1
1
1
1
1
1
1
1
Bid
109.7
109.7
109.7
109.7
109.7
109.7
109.7
109.7
109.7
109.7
109.7
Ask AskSize
Last LastSize Volume
109.725
3 109.75
1
354
109.725
5 109.75
1
354
109.725
1 109.75
1
354
109.750
18 109.75
1
354
109.750
18 109.75
1
354
109.725
6 109.75
1
354
109.725
6 109.75
1
354
109.725
4 109.75
1
354
109.725
6 109.75
1
354
109.725
8 109.75
1
354
109.725
10 109.75
1
354
2011)
R/Finance 2011
24 / 100
dx <- diff(x)
trade.idx <- dx[,"Volume"]>0
trades <- x[trade.idx,]
trades[,"LastSize"] <- coredata(dx[trade.idx,"Volume"])
head(trades)
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
2011-04-17
21:39:26.885
21:41:09.146
21:41:38.648
21:41:44.491
21:41:49.401
21:42:12.403
BidSize
16
2
6
8
1
1
Bid
109.650
109.700
109.700
109.700
109.750
109.725
Ask AskSize
Last LastSize Volume
109.725
3 109.700
1
344
109.750
12 109.750
1
345
109.750
14 109.750
1
346
109.750
6 109.750
1
347
109.775
8 109.775
2
349
109.775
20 109.775
1
350
Yollin/Payseur (Copyright
2011)
R/Finance 2011
25 / 100
107.5
108.0
108.5
109.0
109.5
Emini Crude
Apr 17
21:39:26
Apr 18
00:01:13
Yollin/Payseur (Copyright
2011)
Apr 18
02:00:29
Apr 18
04:00:15
Apr 18
06:00:02
Apr 18
08:00:08
Apr 18
10:00:01
Apr 18
12:00:04
Apr 18
14:05:44
R/Finance 2011
26 / 100
107.5
108.0
108.5
Apr 18
05:00:01
Yollin/Payseur (Copyright
2011)
Apr 18
06:30:41
Apr 18
08:00:08
Apr 18
09:30:02
Apr 18
11:00:00
Apr 18
12:31:22
R/Finance 2011
27 / 100
21:40:00
21:45:00
21:45:00
21:45:00
21:45:00
21:45:00
BidSize
16
2
6
8
1
1
Bid
109.650
109.700
109.700
109.700
109.750
109.725
Ask AskSize
Last LastSize Volume
109.725
3 109.700
1
344
109.750
12 109.750
1
345
109.750
14 109.750
1
346
109.750
6 109.750
1
347
109.775
8 109.775
2
349
109.775
20 109.775
1
350
21:40:00
21:45:00
21:50:00
22:00:00
22:05:00
22:10:00
Yollin/Payseur (Copyright
Open
109.700
109.750
109.700
109.675
109.650
109.700
High
109.700
109.775
109.700
109.675
109.650
109.700
Low
109.700
109.750
109.700
109.675
109.650
109.650
Close Volume
109.700
344
109.750
3147
109.700
355
109.675
356
109.650
357
109.650
1079
2011)
R/Finance 2011
28 / 100
21:40:00
21:45:00
21:50:00
21:55:00
22:00:00
22:05:00
22:10:00
22:15:00
22:20:00
22:25:00
Yollin/Payseur (Copyright
Open
109.700
109.750
109.700
NA
109.675
109.650
109.700
NA
109.625
109.650
High
109.700
109.775
109.700
NA
109.675
109.650
109.700
NA
109.625
109.650
Low
109.700
109.750
109.700
NA
109.675
109.650
109.650
NA
109.625
109.650
Close Volume
109.700
344
109.750
3147
109.700
355
NA
NA
109.675
356
109.650
357
109.650
1079
NA
NA
109.625
362
109.650
1458
2011)
R/Finance 2011
29 / 100
21:40:00
21:45:00
21:50:00
21:55:00
22:00:00
22:05:00
Yollin/Payseur (Copyright
Open
109.700
109.750
109.700
109.700
109.675
109.650
High
109.700
109.775
109.700
109.700
109.675
109.650
Low
109.700
109.750
109.700
109.700
109.675
109.650
Close Volume
109.700
344
109.750
3147
109.700
355
109.700
0
109.675
356
109.650
357
2011)
R/Finance 2011
30 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
31 / 100
Last 107.925
108.5
108.0
107.5
40
30
Volume (10,000s):
99,328
20
10
0
Apr 18
05:00
Apr 18
06:00
Yollin/Payseur (Copyright
Apr 18
07:00
2011)
Apr 18
08:00
Apr 18
09:00
Apr 18
10:00
Apr 18
11:00
Apr 18
12:00
Apr 18
13:00
R/Finance 2011
32 / 100
Outline
Wrap-Up
Yollin/Payseur (Copyright
2011)
R/Finance 2011
33 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
34 / 100
2011)
R/Finance 2011
35 / 100
2011)
R/Finance 2011
36 / 100
library(RTAQ)
ticker <- "SBUX"
TAQ.path <- "TAQRdata"
sbux.t <- TAQLoad(tickers=ticker,from="2010-07-01",to="2010-07-01",
trades=T,quotes=F,datasource=TAQ.path)
> class(sbux.t)
[1] "xts" "zoo"
> dim(sbux.t)
[1] 77956
> head(sbux.t,3)
SYMBOL EX
2010-07-01 08:04:28 "SBUX" "Q"
2010-07-01 08:04:28 "SBUX" "Q"
2010-07-01 08:04:28 "SBUX" "Q"
PRICE
"24.9500"
"24.9500"
"24.9600"
SIZE
"
100"
"
100"
"
300"
COND
"T"
"T"
"T"
CORR
"0"
"0"
"0"
G127
"0"
"0"
"0"
> plot(sbux.t[,3],main=paste(ticker,"Trades:",as.Date(start(sbux.t))),type="p",
cex.axis=0.25,cex.main=0.75,cex.lab=0.25,major.tick="hours",pch=18,cex=0.5,
col="seagreen")
Yollin/Payseur (Copyright
2011)
R/Finance 2011
37 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
38 / 100
2011)
R/Finance 2011
39 / 100
> head(sbux.q,4)
2010-07-01
2010-07-01
2010-07-01
2010-07-01
04:15:00
04:15:00
04:15:00
04:28:27
SYMBOL
"SBUX"
"SBUX"
"SBUX"
"SBUX"
EX
"P"
"P"
"P"
"P"
BID
"23.7200"
"23.7200"
"23.7200"
"23.7300"
BIDSIZ
"
3"
"
3"
"
3"
"
5"
OFR
"
"
"
"
0.00"
27.99"
25.08"
25.08"
OFRSIZ
" 0"
" 1"
" 2"
" 2"
MODE
"12"
"12"
"12"
"12"
> plot(sbux.q[,3],main=paste(ticker,"Quotes:",as.Date(start(sbux.t))),
major.tick="hours",minor.ticks=F,type="p",pch=18,cex=0.5,col=2,
cex.main=0.75)
> points(x=index(sbux.q),y=sbux.q[,5],pch=18,cex=0.5,col=4)
> legend(x="left",legend=c("bid","ask"),pch=18,col=c(2,4),bty="n")
Yollin/Payseur (Copyright
2011)
R/Finance 2011
40 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
41 / 100
function
exchangeHoursOnly
selectExchange
tradesCleanup
noZeroPrices
salesCondition
mergeTradesSameTimestamp
rmTradeOutliers
tradesCleanupFinal
noZeroQuotes
rmLargeSpread
mergeQuotesSameTimestamp
rmOutliers
Yollin/Payseur (Copyright
2011)
Description
all data
retain data for exchange hours only
retain only data from a single stock exchange
trade data
cleans trade data
delete the observations where the price is zero
delete entries with abnormal sale condition
merge multiple transactions with the same time stamp
delete transactions with unlikely transaction prices
perform a final cleaning procedure on trade data
quote data
delete the observations where the bid or ask is zero
delete entries for which the spread is more than threshold
merge multiple quote entries with the same time stamp
delete entries for which the mid-quote is outlying
R/Finance 2011
42 / 100
[1] 4023
> op <- par(mar=c(11,7,4,2))
> barplot(tdata.c$report,las=2,col=4,
main=paste(ticker,"trade cleaning summary"))
> mtext("data points",side=2,line=4)
> par(op)
Yollin/Payseur (Copyright
2011)
R/Finance 2011
43 / 100
data points
60000
40000
20000
Yollin/Payseur (Copyright
2011)
sales condition
select exchange
no zero prices
initial number
R/Finance 2011
44 / 100
Clean trades
R Code: Plot time series of clean trades
> plot(tdata[,3],main=paste(ticker,"Cleaned trades:",as.Date(start(sbux.t))),
major.tick="hours", minor.ticks=F,type="p",pch=18,cex=0.5,col="seagreen")
23.8
24.0
24.2
24.4
24.6
Jul 01
09:30:00
Yollin/Payseur (Copyright
2011)
Jul 01
11:00:00
Jul 01
12:00:09
Jul 01
13:00:09
Jul 01
14:00:04
Jul 01
15:00:00
Jul 01
16:00:00
R/Finance 2011
45 / 100
[1] 19994
> op <- par(mar=c(11,7,4,2))
> barplot(qdata.c$report,las=2,col=4,
main=paste(ticker,"quote cleaning summary"))
> mtext("data points",side=2,line=4)
> par(op)
Yollin/Payseur (Copyright
2011)
R/Finance 2011
46 / 100
data points
8e+05
6e+05
4e+05
2e+05
Yollin/Payseur (Copyright
2011)
remove outliers
select exchange
no zero quotes
initial number
0e+00
R/Finance 2011
47 / 100
Clean trades
R Code: Plot time series of clean quotes
> plot(qdata[,3],main=paste(ticker,"Cleaned quotes:",as.Date(start(sbux.t))),
major.tick="hours", minor.ticks=F,type="p",pch=24,cex=0.25,col=2)
> points(x=index(qdata),y=qdata[,5],pch=25,cex=0.25,col=4)
> legend(x="bottomright",legend=c("bid","ask"),pch=18,col=c(2,4),bty="n")
23.8
24.0
24.2
24.4
24.6
bid
ask
Jul 01
09:30:00
Yollin/Payseur (Copyright
2011)
Jul 01
11:00:00
Jul 01
12:00:02
Jul 01
13:00:00
Jul 01
14:00:00
Jul 01
15:00:00
Jul 01
16:00:00
R/Finance 2011
48 / 100
1 -1 -1 -1 -1 -1
1 -1 -1
1 -1 -1 -1 -1 -1
> plot(accDist,main="Accumulation/Distribution",col=4,major.ticks="hours")
Yollin/Payseur (Copyright
2011)
R/Finance 2011
49 / 100
50
50
100
150
Jul 01
09:30:00
Yollin/Payseur (Copyright
Jul 01
11:00:00
2011)
Jul 01
12:00:09
Jul 01
13:00:09
Jul 01
14:00:04
Jul 01
15:00:00
Jul 01
16:00:00
R/Finance 2011
50 / 100
4e+05
3e+05
2e+05
1e+05
0e+00
Accumulation/Distribution
Jul 01
09:30:00
Yollin/Payseur (Copyright
Jul 01
11:00:00
2011)
Jul 01
12:00:09
Jul 01
13:00:09
Jul 01
14:00:04
Jul 01
15:00:00
Jul 01
16:00:00
R/Finance 2011
51 / 100
500000
1500000
2500000
> barplot(c(sum(tdvx[tdvx>0]),-sum(tdvx[tdvx<0])),col=c(3,2),
names.arg=c("accumulation","distribution"))
Yollin/Payseur (Copyright
accumulation
2011)
distribution
R/Finance 2011
52 / 100
Outline
Wrap-Up
Yollin/Payseur (Copyright
2011)
R/Finance 2011
53 / 100
Realized Variance
NOTE: I have left out citations, however, let me know if you want to be
pointed to papers.
Yollin/Payseur (Copyright
2011)
R/Finance 2011
54 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
55 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
56 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
57 / 100
Sampling Frequency
Define
Yollin/Payseur (Copyright
2011)
R/Finance 2011
58 / 100
(m)
RV
M
X
2
ri,m
i=1
450
X
2
ri,mins
,
i=1
Yollin/Payseur (Copyright
2011)
(30secs)
RV
900
X
2
ri,30secs
i=1
High-Frequency Financial Data Analysis
R/Finance 2011
59 / 100
24.2
23.8
24.0
Price
24.4
24.6
Jul 01
09:30:00
Jul 01
10:15:00
Yollin/Payseur (Copyright
Jul 01
11:00:00
2011)
Jul 01
11:45:13
Jul 01
12:30:00
Jul 01
13:15:02
Jul 01
14:00:00
Jul 01
14:45:03
Jul 01
15:30:00
R/Finance 2011
60 / 100
Realized Package
Realized Variance Package (Available on CRAN)
Author: Scott Payseur
Calculation of realized variance, covariance and correlation
Naive, sub-sampling, kernel, Hayashi-Yoshida
Graphical tools
R Code: Load Realized Library
> library(realized)
Realized Library: Realized Variance, Covariance, Correlation Estimation and Tools.
R: http://cran.r-project.org
Copyright (C) 2010 Scott W. Payseur <scott.payseur@gmail.com>
Please report any bugs or feature requests to the author.
in the 'realized' library directory.
User's manual
2011)
R/Finance 2011
61 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
62 / 100
2011)
R/Finance 2011
63 / 100
> Sys.setenv(TZ="GMT")
> plot(sbux.20110701.xts["2010-07-01 10:15:00::2010-07-01 10:30:00",3],pch=18,col=4,
main="Starbucks (SBUX) Trades", ylab="Price", type="b", cex=.7)
24.00
23.96
Price
24.04
Jul 01
10:15:00
Jul 01
10:17:02
Yollin/Payseur (Copyright
2011)
Jul 01
10:19:00
Jul 01
10:21:01
Jul 01
10:23:00
Jul 01
10:25:01
Jul 01
10:27:00
Jul 01
10:29:01
R/Finance 2011
64 / 100
0.002
0.002
0.006
Return
0.006
Jul 01
09:30:00
Jul 01
10:15:00
Yollin/Payseur (Copyright
Jul 01
11:00:00
2011)
Jul 01
11:45:13
Jul 01
12:30:00
Jul 01
13:15:02
Jul 01
14:00:00
Jul 01
14:45:03
Jul 01
15:30:00
R/Finance 2011
65 / 100
0.4
0.2 0.0
0.2
ACF
0.6
0.8
1.0
Yollin/Payseur (Copyright
10
20
30
40
Lag
20100701
2011)
R/Finance 2011
66 / 100
ri,m
ei,m
ri,m
i = 1, 2, ..., m
RV
(m)
M
X
M
X
2
ri,m
i=1
Yollin/Payseur (Copyright
2011)
2
ri,m
|i=1{z }
(m)
RV
M
X
2
ei,m
|i=1{z }
(m)
RVu
2
+
M
X
ri,m
ei,m
i=1
{z
}
(m)
2RC,u
R/Finance 2011
67 / 100
RV
(m)
M
X
M
X
2
ri,m
i=1
M
X
2
ri,m
|i=1{z }
(m)
RV
2
ei,m
|i=1{z }
(m)
RVu
2
+
M
X
ri,m
ei,m
i=1
{z
}
(m)
2RC,u
(m)
(m)
is greater than RV
and RV (m) is
Yollin/Payseur (Copyright
2011)
R/Finance 2011
68 / 100
2011)
R/Finance 2011
69 / 100
42
40
38
36
34
32
2011)
R/Finance 2011
70 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
71 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
72 / 100
Signature Plot
R Code: rSignature
> args(rSignature)
function (range, x, y = NULL, type = "naive", cor = FALSE, rvargs = list(),
align.by = "seconds", align.period = 1, xscale = 1, plotit = FALSE,
cts = TRUE, makeReturns = FALSE, iteration.funct = NULL,
iterations = NULL, lags = NULL)
NULL
Yollin/Payseur (Copyright
2011)
R/Finance 2011
73 / 100
34
36
38
40
42
32
2011)
R/Finance 2011
74 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
75 / 100
Timing:
Choose an optimal sampling frequency, using an ASP (we chose 2
mins for our data)
Kernel:
Similar to long run variance
Eliminates auto-correlation
Other:
Two-Timescale
Average RV
Yollin/Payseur (Copyright
2011)
R/Finance 2011
76 / 100
50
45
40
35
Yollin/Payseur (Copyright
10
R/Finance 2011
77 / 100
10
2011)
R/Finance 2011
78 / 100
Yollin/Payseur (Copyright
2011)
R/Finance 2011
79 / 100
Kernel Estimators
RVKernel
H
h 1 n
o
X
= 0 +
k
h + h
H
h=1
m
X
ri,m ri+h,m
i=1
Yollin/Payseur (Copyright
2011)
R/Finance 2011
80 / 100
Kernel Estimators
RVKernel = 0 +
H
m
h 1 n
o
X
X
k
h + h
, h
ri,m ri+h,m
H
i=1
3
1
lags
h=1
Time
Yollin/Payseur (Copyright
2011)
R/Finance 2011
81 / 100
Kernel Estimators
RVKernel = 0 +
H
m
o
h 1 n
X
X
h + h
, h
ri,m ri+h,m
k
H
h=1
Yollin/Payseur (Copyright
2011)
i=1
R/Finance 2011
82 / 100
rKernel, rKernel.available
R Code: rKernel
> args(rKernel)
function (x, type = 0)
NULL
"Rectangular"
"Epanechnikov"
"Sixth"
"Parzen"
Yollin/Payseur (Copyright
"Bartlett"
"Cubic"
"Seventh"
"TukeyHanning"
2011)
"Second"
"Fifth"
"Eighth"
"ModifiedTukeyHanning"
R/Finance 2011
83 / 100
realized Kernels
0.0
0.8
0.8
0.8
Yollin/Payseur (Copyright
2011)
0.4
0.8
0.6
0.0
0.8
0.6
0.0
0.6
0.0
0.8
0.0
0.6
0.4
0.4
TukeyHanning
0.0
0.0
0.0
0.0
Parzen
0.6
Eighth
0.4
0.4
Seventh
0.6
0.0
0.0
0.0
0.4
0.8
ModifiedTukeyHanning
0.6
0.8
0.8
0.0
0.6
0.4
0.4
Sixth
0.0
0.0
0.0
0.0
Fifth
0.6
Cubic
0.4
0.0
0.4
0.8
0.0
0.4
R/Finance 2011
0.8
0.8
0.0
0.4
0.0
0.0
0.0
0.0
Epanechnikov
0.6
Second
0.6
Bartlett
0.6
Rectangular
84 / 100
realized Kernels
Yollin/Payseur (Copyright
2011)
R/Finance 2011
85 / 100
2011)
R/Finance 2011
86 / 100
Kernel Points
R Code: One Day Signature Plot + Kernel Esimates
> plot(sig.naive$x, sig.naive$y, xlab="Sampling Frequency (Minutes)",
ylab="Realized Vol (% per anum)", cex=.7, pch=18, col="blue",
main="SBUX One Day Signature Plot")
> kern.bart.10.av <- sqrt(bart.10)*sqrt(250)*100
> kern.th.10.av <- sqrt(th.10)*sqrt(250)*100
> lines(sig.naive$x, rep(kern.bart.10.av, 600), col='green', lty=2)
> lines(sig.naive$x, rep(kern.th.10.av, 600), col='red', lty=2)
50
45
40
35
Yollin/Payseur (Copyright
10
R/Finance 2011
87 / 100
46
44
42
40
0
Yollin/Payseur (Copyright
20
2011)
40
60
Kernel Lag
80
100
R/Finance 2011
88 / 100
42
44
46
Bartlett
TukeyHanning
40
Yollin/Payseur (Copyright
20
40
60
80
100
Kernel Lag
2011)
R/Finance 2011
89 / 100
60
80
50
20
100
40
45
Naive
Bartlett
TukeyHanning
35
lags:
Yollin/Payseur (Copyright
10
R/Finance 2011
90 / 100
Implied Volatility
R Code: SBUX Volatility Graph
> load(paste(shared.dir,"data/bloomberg.ivol.xts.rda", sep="/"))
> plot(as.zoo(bloomberg.ivol.xts), plot.type="single", col=c(2,3),
main="SBUX Volatility 2010", xlab="", ylab="Annualized Vol %")
> legend("topright", c("Bloomberg Vol", "Implied Vol"), col=c(2,3), lwd=c(1,1))
30
35
40
Bloomberg Vol
Implied Vol
25
Annualized Vol %
May
Yollin/Payseur (Copyright
Jun
2011)
Jul
Aug
Sep
Oct
R/Finance 2011
Nov
91 / 100
2011)
R/Finance 2011
92 / 100
40
60
Bloomberg Vol
Implied Vol
Realized Vol
20
Annualized Vol %
80
May
Yollin/Payseur (Copyright
Jun
2011)
Jul
Aug
Sep
Oct
R/Finance 2011
Nov
93 / 100
Starbucks 2010-05-07
R Code: Plotting Starbucks 2010-05-07
> load(paste(shared.dir,"data/sbux.20100507.prices.xts.rda", sep="/"))
> plot(sbux.20100507.prices.xts[,"PRICE"], main="Starbucks 2010-05-07",
xlab="",ylab="")
24.8
25.2
25.6
26.0
Starbucks 20100507
May 07
09:30:00
May 07
10:15:00
May 07
11:00:00
May 07
11:45:03
May 07
12:30:00
May 07
13:15:01
May 07
14:00:00
May 07
14:45:00
May 07
15:30:00
2011)
R/Finance 2011
94 / 100
Realized Variance:
(m)
As M , RV
Yollin/Payseur (Copyright
2011)
R/Finance 2011
95 / 100
Outline
Wrap-Up
Yollin/Payseur (Copyright
2011)
R/Finance 2011
96 / 100
Summary
Yollin/Payseur (Copyright
2011)
R/Finance 2011
97 / 100
Going Further
Course
Dates
Time
Instructor
Where
Info
Topics
financial markets, exchanges, and the electronic trading process
trading system development, optimization, and backtesting
paper trading with Interactive Brokers Student Trading Lab
Yollin/Payseur (Copyright
2011)
R/Finance 2011
98 / 100
2011)
R/Finance 2011
99 / 100
Wrap up
Scott Payseur
http://uk.linkedin.com/in/spayseur
scott.payseur@gmail.com
Yollin/Payseur (Copyright
2011)
R/Finance 2011
100 / 100