-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path415inprocess.Rmd
38 lines (30 loc) · 1.33 KB
/
415inprocess.Rmd
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
---
title: "415inprocess"
output: pdf_document
---
```{r}
library(dplyr)
df= read.csv("https://raw.githubusercontent.com/xinyexu/Data-Mining-Project/master/interest_data.csv")
df_return = na.omit(df) # ignore NA
df_return[,2:16] = as.data.frame(apply(na.omit(df[,2:16]), 2, function(x) {c(NaN, diff(x)/x[-length(x)])})) # cal returns
# changeDirection is 1 wehn df_return$SP500 > 0
df_return$SP500Direction = as.numeric(df_return$SP500 > 0)
df_return$USBondDirection = as.numeric(df_return$BAMLCC0A1AAATRIV > 0)
# variable changed, then upload
colnames(df_return) = c('Date', 'Treasury', 'USBondAAA', 'SP500', 'CHNUS', 'VixIndex', 'EMBond', 'EURUS', 'USBondHY', 'OilWTI', 'VixOil', 'DJIA', 'NASDAQ', 'EMBondBB', 'MarketCap', 'Vixgold', 'SP500Dir', 'USBondAAADir')
write.csv(df_return, file = "df_return.csv",row.names=FALSE)
```
```{r}
cor_cal = cor(df_return[2:nrow(df_return),2:ncol(df_return)])
require("corrplot")
corrplot(cor_cal, type = "upper")
```
Test the true value of vix vs stock direction: not
```{r}
df_VIXvalue = as.data.frame(cbind(df_return$DATE, na.omit(df)[c(6, 11, 16)], df_return[-c(1, 6, 11, 16)]))
cor_cal2 = cor(df_VIXvalue[2:nrow(df_VIXvalue), 2:ncol(df_VIXvalue)])
corrplot(cor_cal2, type = "upper")
```
```{r}
returns = read.csv('https://raw.githubusercontent.com/xinyexu/Data-Mining-Project/master/df_return.csv')
```