Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

S&P 500 Analyzer

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).


Overview

Point the controls at any span from 1928 to 2023 and the app recomputes everything on the fly.

S&P 500 Timeline

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

Multi-Year Returns

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.

Summary Table

A statistics panel for the returns in the selected window: mean, median, standard deviation, IQR, min/max, and the 10th/25th/75th/90th percentiles.

Tech stack

Purpose Package
App framework shiny
Financial data tidyquant (Yahoo Finance)
Data wrangling tidyverse, lubridate
Interactive charts ggplot2, plotly

Data

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.

Running locally

R -e "install.packages(c('shiny','tidyverse','lubridate','tidyquant','plotly'))"
R -e "shiny::runApp('app.R')"

Notes

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.

Author

Andreas Jackson

About

Interactive R Shiny app analyzing the S&P 500: log/linear price timeline, rolling multi-year returns, and summary stats. Fetches data live from Yahoo Finance.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages