rRealizedVariance: Calculate realized variance, covariance, or correlation.

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Calculate realized variance, covariance, correlation, covariance matrix, or correlation matrix.

Usage

1
rRealizedVariance(x, y = NULL, type = "naive", period = 1,align.by="seconds", align.period = 1, cor = FALSE, rvargs = list(), cts = TRUE, makeReturns = FALSE, lags=NULL)

Arguments

x

Tick data in xts object.

y

Tick data in xts object.

period

Sampling period

align.by

Align the tick data to seconds|minutes|hours

align.period

Align the tick data to this many [seconds|minutes|hours]

type

Type of realized estimator to use, a rv. or rc. is appended to this value and that function is called

cor

T for correlation

rvargs

List of extra parameters to pass into rv.* or rc.*

cts

Create calendar time sampling if a non realizedObject is passed

makeReturns

Prices are passed make them into log returns

lags

Deprecated

Details

Calculate realized variance, covariance, correlation, covariance matrix, or correlation matrix.

Value

A single numeric value or a matrix if x is multicolumn matrix.

Author(s)

Scott Payseur <scott.payseur@gmail.com>

See Also

rc.avg, rc.kernel, rc.naive, rc.timescale, rv.avg, rv.kernel, rv.naive, rv.timescale

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
data(sbux.xts)
data(lltc.xts)

#
#  VARIANCE
#

# Traditional Estimate at highest frequency
rRealizedVariance(x=sbux.xts, type="naive", period=1, align.by="seconds", align.period=1)

# Traditional Estimate at one minute frequency 
rRealizedVariance(x=sbux.xts, type="naive", period=1, align.by="seconds", align.period=60) 
rRealizedVariance(x=sbux.xts, type="naive", period=1, align.by="mins", align.period=1) 

# Traditional Estimate at 10 minute frequency 
rRealizedVariance(x=sbux.xts, type="naive", period=1, align.by="mins", align.period=10) 

# Bartlett Kernel Estimate with minute aligned data at 20 lags 
rRealizedVariance(x=sbux.xts, type="kernel", align.by="mins", align.period=1, rvargs=list(kernel.param=20,kernel.type="Bartlett"))

# Cubic Kernel Estimate with second aligned data at 400 lags 
rRealizedVariance(x=sbux.xts, type="kernel", align.by="seconds", align.period=1, rvargs=list(kernel.param=400, kernel.type="Cubic"))
 
# Subsample Average Estimate with second aligned data at 600 subgrids 
rRealizedVariance(x=sbux.xts, type="avg", period=600) 

# Timescale Average Estimate with second aligned data at 600 subgrids 
rRealizedVariance(x=sbux.xts, type="timescale", period=600, rvargs=list(adj.type="aa")) 


#
# COVARIANCE
# 

# Traditional Estimate at highest frequency
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="naive", period=1, align.by="seconds", align.period=1)

# Traditional Estimate at one minute frequency 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="naive", period=1, align.by="seconds", align.period=60) 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="naive", period=1, align.by="mins", align.period=1) 

# Traditional Estimate at 10 minute frequency 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="naive", period=1, align.by="mins", align.period=10) 

# Bartlett Kernel Estimate with minute aligned data at 20 lags 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="kernel", align.by="mins", align.period=1, rvargs=list(kernel.param=20,kernel.type="Bartlett"))

# Cubic Kernel Estimate with second aligned data at 400 lags 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="kernel", align.by="seconds", align.period=1, rvargs=list(kernel.param=400, kernel.type="Cubic"))
 
# Subsample Average Estimate with second aligned data at 600 subgrids 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="avg", period=600) 

# Timescale Estimate with second aligned data at 600 subgrids 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="timescale", period=600, rvargs=list(adj.type="aa")) 


#
# CORRELATION
#
 
# Traditional Estimate at highest frequency
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="naive", period=1, align.by="seconds", align.period=1, cor=TRUE)

# Traditional Estimate at one minute frequency 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="naive", period=1, align.by="seconds", align.period=60, cor=TRUE) 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="naive", period=1, align.by="mins", align.period=1, cor=TRUE) 

# Traditional Estimate at 10 minute frequency 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="naive", period=1, align.by="mins", align.period=10, cor=TRUE) 

# Bartlett Kernel Estimate with minute aligned data at 20 lags 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="kernel", align.by="mins", align.period=1, rvargs=list(kernel.param=20,kernel.type="Bartlett"), cor=TRUE)

# Cubic Kernel Estimate with second aligned data at 400 lags 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="kernel", align.by="seconds", align.period=1, rvargs=list(kernel.param=400, kernel.type="Cubic"), cor=TRUE)
 
# Subsample Average Estimate with second aligned data at 600 subgrids 
rRealizedVariance(x=sbux.xts, y=lltc.xts, type="avg", period=600, cor=TRUE) 

# Timescale Estimate with second aligned data at 600 subgrids 
rRealizedVariance(x=sbux.xts, y=lltc.xts,type="timescale", period=600, rvargs=list(adj.type="aa"), cor=TRUE) 
  

#
# COVARIANCE MATRIX
#
rRealizedVariance(x=merge(sbux.xts,lltc.xts, fill=0),type="timescale", period=600, rvargs=list(adj.type="aa"), cor=FALSE) 

#
# CORRELATION MATRIX
#
rRealizedVariance(x=merge(sbux.xts,lltc.xts, lltc.xts, fill=0), type="naive", period=1, align.by="mins", align.period=10, cor=TRUE) 
 

realized documentation built on May 2, 2019, 6:47 p.m.