-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.R
More file actions
37 lines (25 loc) · 957 Bytes
/
script.R
File metadata and controls
37 lines (25 loc) · 957 Bytes
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
library(zoo)
library(xts)
library(copula)
# Set the path
setwd("/home/docker/host/")
# Data Wrangle ------------------------------------------------------------
# Retrieve the processed daily data from csv
allClose <- read.zoo("data/allClose.csv",
format="%Y-%m-%d",header=TRUE)
# Get log daily returns
allLog <- diff(log(allClose))
# Sum to log weekly returns
allLogWk <- apply.weekly(allLog, colSums)
# Plot of the time series -------------------------------------------------
pdf("results/ts.pdf")
plot(allLogWk, main="Weekly Log Returns")
dev.off()
# Make a plot of empirical copulas ----------------------------------------
pdf("results/pairsCop.pdf")
pairs(pobs(allLogWk), main="Empirical Copulas")
dev.off()
# Correlation matrix ------------------------------------------------------
corMat <- cor(allLogWk, use="pairwise.complete.obs")
# Write out the correlation matrix
write.csv(corMat, "results/correlation.csv")