-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTAT_ARB.R
More file actions
58 lines (42 loc) · 1.46 KB
/
Copy pathSTAT_ARB.R
File metadata and controls
58 lines (42 loc) · 1.46 KB
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
library(quantmod)
library(PerformanceAnalytics)
momersion <- function(R, n, returnLag = 1) {
momentum <- sign(R * lag(R, returnLag))
momentum[momentum < 0] <- 0
momersion <- runSum(momentum, n = n)/n * 100
colnames(momersion) <- "momersion"
return(momersion)
}
asset_a <- "XIV"
asset_b <- "VXX"
num_a <- as.name(asset_a)
num_b <- as.name(asset_b)
xiv <- getSymbols(asset_a,src="google")
vxx <- getSymbols(asset_b,src="google")
INT_A <- paste(num_a,"$", num_a,".", "Close", sep = "")
INT_B <- paste(num_b,"$", num_b,".", "Close", sep = "")
ASSET_A <- XIV$XIV.Close
ASSET_B <- VXX$VXX.Close
xivRets <- Return.calculate(Cl(ASSET_A))
vxxRets <- Return.calculate(Cl(ASSET_B))
volSpread <- xivRets + vxxRets
volSpreadMomersion <- momersion(volSpread, n = 252)
plot(volSpreadMomersion)
#both sides
sig <- -lag(sign(volSpread))
longShort <- sig * volSpread
charts.PerformanceSummary(longShort['2011::'], main = 'long and short spread')
#long spread only
sig <- -lag(sign(volSpread))
sig[sig < 0] <- 0
longOnly <- sig * volSpread
charts.PerformanceSummary(longOnly['2011::'], main = 'long spread only')
#short spread only
sig <- -lag(sign(volSpread))
sig[sig > 0] <- 0
shortOnly <- sig * volSpread
charts.PerformanceSummary(shortOnly['2011::'], main = 'short spread only')
threeStrats <- na.omit(cbind(longShort, longOnly, shortOnly))["2011::"]
colnames(threeStrats) <- c("LongShort", "Long", "Short")
#______
rbind(table.AnnualizedReturns(threeStrats), CalmarRatio(threeStrats))