-
Notifications
You must be signed in to change notification settings - Fork 0
/
modelgraphs.R
67 lines (58 loc) · 2.32 KB
/
modelgraphs.R
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
library(readxl)
library(ggplot2)
library(xts)
library(forecast)
library(ggplot2)
library(tidyr)
library(dplyr)
library(tidyverse)
library(tidyquant)
library(recipes)
library(timetk)
library(magrittr)
Model <- read_excel("Model Data.xlsx")
single_timeseries_plot = function(data,value, Date,ylabel) {
ggplot(data, aes(x=Date)) +
geom_line(aes(y = value), color = "darkred")+
xlab("Year")+
ylab(ylabel)
}
single_timeseries_plot(Model,Model$`Mkt-RF (KF)`,Model$Year,"`Mkt-RF (KF)`")
single_timeseries_plot(Model,Model$`HML (KF)`, Model$Year,"`HML (KF)`")
single_timeseries_plot(Model,Model$`SMB (KF)`, Model$Year,"SMB (KF)`")
single_timeseries_plot(Model,Model$RMRF, Model$Year,"RMRF")
single_timeseries_plot(Model,Model$SMB, Model$Year,"SMB")
single_timeseries_plot(Model,Model$HML, Model$Year,"HML")
Multiple_timeseries_plot = function(dataset,Year) {
# Multiple line plot
# name<- colnames(dataset)[2:7]
ggplot(dataset, aes(x=Year)) +
geom_line(aes(y = MktRfKF), color = "darkred") +
geom_line(aes(y = HMLKF), color = "red") +
geom_line(aes(y = SMBKF), color = "blue") +
geom_line(aes(y = RMRF), color = "green") +
geom_line(aes(y = SMB), color="steelblue", linetype="twodash") +
geom_line(aes(y = HML), color = "orange") +
scale_colour_hue(l=25)+
scale_linetype_manual(values = c('Mkt-RF (KF)' = 1,'HML (KF)' = 2,'SMB (KF)'=3,'RMRF'=4,'SMB'=5,'HML'=6)) #+
#geom_point(aes(group=variable, color=variable, size=6))
}
colnames(Model)[2] <- "MktRfKF"
colnames(Model)[3] <- "HMLKF"
colnames(Model)[4]<- "SMBKF"
Model
#variable<- c("`Mkt-RF (KF)`", "`HML (KF)`", "`SMB (KF)`","RMRF","SMB","HML")
Multiple_timeseries_plot(Model,Model$Year)
#Model$Year<-as.character(Model$Year)
a<-sprintf("%s-01-01",Model$Year)
Model$Date<-as.Date(a)
Model_data <-as.data.frame(Model)
MktRfKF <- xts(Model_data$MktRfKF,Model_data$Date)
HMLKF <- xts(Model_data$HMLKF,Model_data$Date)
SMBKF <- xts(Model_data$SMBKF,Model_data$Date)
RMRF<- xts(Model_data$RMRF,Model_data$Date)
SMB <- xts(Model_data$SMB,Model_data$Date)
HML <- xts(Model_data$HML,Model_data$Date)
Model_ts <- merge(MktRfKF,HMLKF,SMBKF,RMRF,SMB,HML)
colnames(Model_ts ) <- c("MktRfKF","HMLKF","SMBKF","RMRF","SMB","HML")
charts.PerformanceSummary(Model_ts, main = 'Portfolio Performance Summary')