library("quantmod")
###retrieve historical price data for General Electric Co. from Yahoo Finance
getSymbols('GE',src='yahoo', from="2000-01-01", to="2009-12-30")
[1] "GE"
##to see headers of file (OHLCV type)
names(GE)
[1] "GE.Open" "GE.High" "GE.Low" "GE.Close"
[5] "GE.Volume" "GE.Adjusted"
##insert Adjusted Close
geAdj = GE$GE.Adjusted["2000-01-01/2000-01-20"]
###compute the max, min and mean values
max(geAdj); min(geAdj); mean(geAdj)
[1] 28.06313
[1] 26.23787
[1] 27.1946
###draw a chart
chartSeries(GE)
###to save data on your disk use
saveRDS(GE,file="GE.rds")
library("quantmod")
symbols=c('^VLIC','AMZN','TWTR','MCD','NFLX')
getSymbols(symbols,src='yahoo',from="2017-11-12",to="2018-11-12")
[1] "VLIC" "AMZN" "TWTR" "MCD" "NFLX"
#obtain adjusted closed
VLICad = VLIC$VLIC.Adjusted; AMZNad= AMZN$AMZN.Adjusted;
TWTRad=TWTR$TWTR.Adjusted; MCDad = MCD$MCD.Adjusted;
NFLXad = NFLX$NFLX.Adjusted
##compute cumulative sum (cumsum) of daily returns (Delt)
##Remove first term of the series, with [-1,],since cumsum is not defined for it.
VLIC = cumsum((Delt(VLICad)*100)[-1,])
AMZN = cumsum((Delt(AMZNad)*100)[-1,])
TWTR = cumsum((Delt(TWTRad)*100)[-1,])
MCD = cumsum((Delt(MCDad)*100)[-1,])
NFLX = cumsum((Delt(NFLXad)*100)[-1,])
##range of values of the plot
lim = c(min(VLIC,AMZN,TWTR,MCD,NFLX),max(VLIC,AMZN,TWTR,MCD,NFLX))
##the plot
plot(VLIC,main="",ylim=lim,xlab="dates",ylab="% benefits")
lines(AMZN,col="green"); lines(TWTR,col="red")
lines(MCD,col="violet"); lines(NFLX,col="yellow")
legend(x="topleft",cex=0.4,c("VLIC","AMZN","TWTR","MCD","NFLX"),
lty = 1, col=c("black","green","red","violet","yellow"))
TASK 2C
The cumulative price (thats is percentage change) for VLIC has little variance as % change from previous month when I calculated for over a year. AMZN, TWTR and NFLX are going up however; MCD is really dropping even below VLIC as I calculated using the formula P1-P0/P0, which is basically the change over the previous month. There is lot of variation for AMZN but there is very less variation for VLIC and MCD seems to be struggling a lot.
TASK 3
Problem 1.3.8
Problem 1.3.9