Stock Price Analyzer - A Shiny App

C. Zhang
08/06/2016

Overview

Stock price analyzer is a Shiny app to display stock price history and forecast future prices for a given stock symbol.

Inputs and Outputs

Inputs
  • Stock symbol: E.g. AAPL
  • From date, To date, Year range: The overlap between date range and year range will be applied
  • Aggregation level: Aggregate data to daily/weekly/monthly
  • Add TA to historical data chart?
  • Number of days (weeks, months) to forecast
Outputs
  • Historical Chart: Candlestick chart of historical data
  • Historical Data: Historical price data
  • Forecast Chart: Forecast chart of both historical and forecasted data with 80% and 95% CI
  • Forecast Data: Forecasted closing price data

Sample Forecast Chart with R Code

forecasted<- function(stockobj, numforecast){     
    stockts <- Cl(stockobj)
    fit.e <- ets(stockts)
    fit.a <- auto.arima(stockts)      
    if(accuracy(fit.e)[3] < accuracy(fit.a)[3]) forecast(fit.e, as.numeric(numforecast))
    else forecast(fit.a, as.numeric(numforecast))}
plot(forecasted(stockobj, 90), main = "AAPL forecasted stock price based on closing price") 

plot of chunk unnamed-chunk-3

Miscellaneous

Notes:

  • Stock data is pulled from Yahoo finance.
  • All stock prices have been adjusted on stock splits, such that the values are comparable over time.
  • Forecasting model is built using closing price. An exponential model and an ARIMA model are built, and the better performing model is being applied. Comparison is based on MAE (mean absolute error).

References:

R package quantmod