An interactive R Shiny app for exploring the S&P 500's full daily history — a zoomable price timeline, rolling multi-year total returns, and summary statistics, all driven by user-selected time windows.
🔗 Live demo: https://andreasjackson.shinyapps.io/sp500/
Runs out of the box — no data files to download. The app fetches the index history live from Yahoo Finance on startup (internet connection required).
Point the controls at any span from 1928 to 2023 and the app recomputes everything on the fly.
A daily closing-price line chart for the selected window, with:
- Linear or logarithmic y-axis — log scale makes early-century moves and modern ones comparable on one chart
- Adaptive date breaks — axis tick spacing widens automatically (1 → 2 → 5 → 10 years) as the window grows, so labels never overcrowd
A bar chart of rolling N-year total returns, where N is adjustable (1–30 years). Each bar is one overlapping interval (e.g. 1990–1995, 1991–1996, …), colored green for gains and red for losses. Bar-label density thins automatically as intervals multiply.
Optional overlays — mean, median, and standard deviation of returns — draw as annotated reference lines when toggled on.
A statistics panel for the returns in the selected window: mean, median, standard deviation, IQR, min/max, and the 10th/25th/75th/90th percentiles.
| Purpose | Package |
|---|---|
| App framework | shiny |
| Financial data | tidyquant (Yahoo Finance) |
| Data wrangling | tidyverse, lubridate |
| Interactive charts | ggplot2, plotly |
No dataset is bundled and none is needed. On startup the app calls:
sp500 = tq_get("^GSPC", from = "1928-01-03", to = "2023-12-29")which pulls the S&P 500 (^GSPC) daily series from Yahoo Finance via tidyquant. The only requirement to run it is an internet connection. Yahoo occasionally rate-limits or briefly interrupts this endpoint; if a fetch fails, simply restart the app.
R -e "install.packages(c('shiny','tidyverse','lubridate','tidyquant','plotly'))"R -e "shiny::runApp('app.R')"Built as an exercise in interactive financial visualization — particularly rolling-window return analysis, where the same index looks like a very different investment depending on the holding period you choose.
Andreas Jackson