Stock prices and returns



Stock prices and returns

0 0


DevelopingDataProducts_slides


On Github KirrinTreasureIsland / DevelopingDataProducts_slides

Stock prices and returns

Project for Coursera course Developing Data Products

Presents the application https://kirrintreasureisland.shinyapps.io/stockreturns/

Application

  • Normal distribution of stock returns is an assumption in some financial models.
  • The application allows the user to test this assumption for selected stock prices

  • The user chooses

    • the stock from a drop down menu
    • time interval from a pop up calendar
  • The application displays

    • time evolution of stock price and daily returns
    • histogram and normal QQ plot for the returns
  • Check it here: https://kirrintreasureisland.shinyapps.io/stockreturns/

Stock prices from quantmod

  • Data are obtained through quantmod library (do not worry about the warning):
library(quantmod)
StockPrices <- getSymbols("AMZN", 
                          from = "2014/01/01", to = "2014/12/31", 
                          auto.assign = FALSE)         
## Warning in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=",
## from.m, : downloaded length 13657 != reported length 200
  • We use the adjusted prices from the end of the day to compute the returns:
PriceAdjusted <- StockPrices$AMZN.Adjusted
DailyReturns <- diff(log(PriceAdjusted)) # definition of returns
DailyReturns <- as.numeric(DailyReturns)[-1] # the first value is NA

Sample plot: stock prices

chartSeries(StockPrices, theme = chartTheme("white"))

Sample plot: Histogram of returns

hist(DailyReturns, prob=TRUE)
x <- seq(from=min(DailyReturns),to=max(DailyReturns),length.out=500)
curve(dnorm(x, mean=mean(DailyReturns), sd=sd(DailyReturns)), 
      add=TRUE, col=4) # added normal density curve