Skip to content

Commit 49203ee

Browse files
committed
first commit
0 parents  commit 49203ee

30 files changed

+3327
-0
lines changed

.Rbuildignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData

DESCRIPTION

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Package: rollcorr
2+
Type: OpenCPU Application
3+
Title: Rollcorr Demo application for OpenCPU
4+
Version: 1.0
5+
Date: 2013-07-07
6+
Author: Eran Raviv, Jeroen Ooms
7+
Maintainer: Jeroen <[email protected]>
8+
Description: OpenCPU
9+
License: Apache2
10+
Depends:
11+
quantmod
12+
Collate:
13+
'rollcorr.R'

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export(rollcorr)

R/rollcorr.R

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#' rollcorr
2+
#'
3+
#' Live Rolling Correlation Plot by Eran Raviv
4+
#' See http://eranraviv.com/blog/live-rolling-correlation-plot/
5+
#'
6+
#' @return null
7+
#' @author Eran Raviv
8+
#' @export
9+
rollcorr <- function(){
10+
symetf <- c('XLY','XLP','XLE','XLF','XLV','XLI','XLB','XLK','XLU','SPY')
11+
end <- format(Sys.Date(),"%Y-%m-%d")
12+
start <-format(Sys.Date() - 365,"%Y-%m-%d")
13+
dat0 <- getSymbols(symetf[1], src="google", from=start, to=end, auto.assign = F, warnings = FALSE,symbol.lookup = F)
14+
n <- NROW(dat0)
15+
l <- length(symetf)
16+
dat <- array(dim = c(n,NCOL(dat0),l)) ; ret = matrix(nrow = n, ncol = l)
17+
for (i in 1:l){
18+
dat0 <- getSymbols(symetf[i], src="google", from=start, to=end, auto.assign = F,warnings = FALSE,symbol.lookup = F)
19+
dat[1:n,,i] <- dat0
20+
ret[2:n,i] <- dat[2:n,4,i]/dat[1:(n-1),4,i] - 1
21+
}
22+
rolcor = NULL
23+
h = 10 # 10 bussiness days is two weeks
24+
for (i in 2:(n-h)){
25+
rolcor[i+h] <- mean(cor(ret[i:(i+h),])[lower.tri(cor(ret[i:(i+h),]))]) # just the rolling average correlation
26+
}
27+
par( mfrow = c(2,1), bg = "white", bty ="n", fg = gray(0.3) ,font.lab = 6, font.axis = 6, #xaxp = c(x1, x2, n = 2)
28+
font.main = 6, col.axis = gray(0.3) , col.lab = gray(0.3) , pch = 21, tck = -0.02, #tck is the length of the axis spikes
29+
xaxs = "r") # Graph parameters
30+
lwd1 <- 2.5
31+
plot(rolcor~index(dat0), ty = "l",lwd = lwd1, xlab = "Time",ylab = "Average Correlation", main = "Two Weeks Rolling Correlation")
32+
plot(dat[1:n,4,10]~index(dat0), ty = "l", lwd = lwd1, xlab = "Time", ylab = "SPY Price Level",main ="SPY Price Level")
33+
invisible();
34+
}

inst/icon.png

8.55 KB
Loading

inst/www/index.html

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Rollcorr OpenCPU app</title>
5+
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8+
9+
<!-- ocpu library -->
10+
<script src="jquery-1.10.1.min.js"> </script>
11+
<script src="opencpu.js"> </script>
12+
13+
<!-- optional stuff for the resizable widget -->
14+
<link href="jqueryui/css/ui-lightness/jquery-ui-1.10.3.custom.css" rel="stylesheet" media="screen">
15+
<script src="jqueryui/jquery-ui-1.10.3.custom.js"> </script>
16+
17+
<script>
18+
//on page ready:
19+
$(function() {
20+
var req = $("#plotdiv").r_fun_plot("rollcorr").fail(function(){
21+
alert(req.responseText);
22+
});
23+
24+
//optional, requires jquery-ui.
25+
$("#plotdiv").resizable()
26+
});
27+
</script>
28+
29+
<style>
30+
#plotdiv {
31+
margin-left: 10px;
32+
margin-top: 10px;
33+
width: 900px;
34+
height: 600px;
35+
border: solid gray 1px;
36+
}
37+
</style>
38+
</head>
39+
40+
<body>
41+
42+
<h1>Rollcorr OpenCPU App</h1>
43+
44+
<div id="plotdiv"></div>
45+
46+
</body>
47+
</html>

inst/www/jquery-1.10.1.min.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)