Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data<-read.csv("FTSESF.csv") | |
head(data) | |
str(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getwd() # get working directory | |
setwd('') # set working directory | |
install.packages("PerformanceAnalytics") | |
library (PerformanceAnalytics) # load the package | |
ms<-read.csv("Microsoft.csv", header=TRUE) #load Microsoft daily prices | |
head(ms) | |
sp<-read.csv("SP.csv", header=TRUE) # load S and P 500 daily prices | |
head(sp) | |
class(ms) | |
class(sp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(zoo) | |
#Microsoft | |
ms$Dates <- as.Date(ms$Dates, "%d/%m/%Y") | |
class(ms$Dates) | |
ms.z = zoo(x=ms$Close, order.by=ms$Dates) | |
#S and P 500 | |
sp$Dates <- as.Date(sp$Dates, "%d/%m/%Y") | |
class(sp$Dates) | |
sp.z = zoo(x=sp$Close, order.by=sp$Dates) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ms.monthly<-to.monthly(ms.z,OHLC = FALSE) | |
head(ms.monthly) | |
sp.monthly<-to.monthly(sp.z,OHLC = FALSE) | |
head(sp.monthly) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#combine Microsoft and SP daily data | |
ms.sp.dp<-merge(ms.z, sp.z) | |
head(ms.sp.dp) | |
#combine Microsoft and sP monthly data | |
ms.sp.dm<-merge(ms.monthly, sp.monthly) | |
head(ms.sp.dm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Microsoft montly and daily log returns | |
ms.monthly.r<-Return.calculate(ms.monthly, method = "log") | |
ms.daily.r<-Return.calculate(ms.z, method = "log") | |
head(ms.monthly.r) | |
head(ms.daily.r) | |
#S and P montly and daily log returns | |
sp.monthly.r<-Return.calculate(sp.monthly, method = "log") | |
sp.daily.r<-Return.calculate(sp.z, method = "log") | |
head(sp.monthly.r) | |
head(sp.daily.r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ms.monthly.r<-ms.monthly.r[-1] | |
ms.daily.r<-ms.daily.r[-1] | |
sp.monthly.r<-sp.monthly.r[-1] | |
sp.daily.r<-sp.daily.r[-1] | |
ms.sp.dp.r<-ms.sp.dp.r[-1] | |
ms.sp.dm.r<-ms.sp.dm.r[-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Daily prices line plot for Microsoft | |
plot.zoo(ms.z, main = "Microsoft Daily Prices", xlab = | |
"Time", ylab = "Daily Prices", lwd = 2, col = "blue") | |
#Monthly prices line plot for Microsoft | |
plot.zoo(ms.monthly, main = "Microsoft Monthly Prices Plot",xlab = | |
"Time", ylab = "Monthly Prices", lwd = 2, col = "red") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#plot for merged daily data | |
plot.zoo(ms.sp.dp, main = "Microsoft and S&P Daily Prices Plot", lwd = 2, col = "red") |
OlderNewer