# New Microsoft Word Document

advertisement
```data<-read.csv("C:/Users/onatt/OneDrive/Desktop/EPFL/New
folder/Macrofinance/Assignment7/chapt26.csv")
data<-data[-c(122:nrow(data)),]
##### Question 1 #####
######## Part b ########
NAPCCG<-data[-1,9]/data[-nrow(data),9]-1
standard.deviation.NAPCCG<-sd(NAPCCG)
######## Part c ########
return<-data[-nrow(data),16]
average.return<-mean(return)
standard.deviation.Return<-sd(return)
####### Part d #######
risk.free<-data[-nrow(data),8]-1
average.rf<-mean(risk.free)
standard.deviation.free<-sd(risk.free)
###### part e ######
average.excess<-average.return-average.rf
##### part f #####
correlation <- cor(NAPCCG[-c(103:length(NAPCCG))],return[c(103:length(return))])
plot(x=NAPCCG[-c(103:length(NAPCCG))], y=return[-c(103:length(return))])
##### part g #####
rho <- average.excess / (correlation*sd(NAPCCG[c(length(NAPCCG))])*sd(return[-c(length(return))]))
#### plot ####
plodat<-as.data.frame(cbind(risk.free,return))
time.series.high<-ts(plodat, start = c(1889), end = c(2008), frequency = 1)
colnames(time.series.high)<-c("RiskFree","Return")
# Plot and Legend
ts.plot(time.series.high,
gpars=list(xlab="Year", ylab="Return", lty=c(1), col=c(1:2),lwd=2))
legend("topright",colnames(time.series.high),col=c(1:3),lty=1,cex=0.5)
```