European Stock Return Calculator

Ayesha Ansari
2026-06-23

Developing Data Products — Week 4 Assignment

The Problem & Our Solution

Why this matters:

  • Investors need to compare index performance over flexible time windows
  • Raw price charts don't show risk-adjusted performance
  • Calculating volatility and drawdown by hand is tedious

What our Shiny app provides:

  • Flexible date range selection via sliders
  • Four European indices: DAX, SMI, CAC, FTSE
  • Cumulative return, annualised return, volatility, max drawdown
  • All computed instantly from a built-in R dataset — no download needed

The Dataset & How Returns Are Calculated

data("EuStockMarkets")
cat("Size:", nrow(EuStockMarkets), "trading days x",
    ncol(EuStockMarkets), "indices\n")
Size: 1860 trading days x 4 indices
cat("Indices:", colnames(EuStockMarkets), "\n")
Indices: DAX SMI CAC FTSE 
prices  <- as.numeric(EuStockMarkets[, "DAX"])
n       <- length(prices)
cum_ret <- (prices[n] / prices[1]) - 1
years   <- n / 260
ann_ret <- (1 + cum_ret)^(1 / years) - 1
daily_r <- diff(prices) / prices[-length(prices)]
vol     <- sd(daily_r) * sqrt(260)
cat(sprintf("Cumulative Return : %+.1f%%", cum_ret * 100), "\n")
Cumulative Return : +236.1% 
cat(sprintf("Annualised Return : %+.1f%%", ann_ret * 100), "\n")
Annualised Return : +18.5% 
cat(sprintf("Volatility        :  %.1f%%", vol * 100), "\n")
Volatility        :  16.6% 

Key App Features & Visualisation

plot of chunk unnamed-chunk-2

Widgets used: radioButtons, sliderInput x2, checkboxInput, selectInput, actionButton

Try the App Now!

Live Application: https://ayeshaansari.shinyapps.io/STOCK_RETURN_CALCULATOR/

What you can do with the app:

  • Pick any of the four European indices
  • Slide the date range to any sub-period between 1991 and 1998
  • See cumulative return, annualised return, volatility, and max draw down update instantly
  • Toggle the 30-day moving average overlay on the price chart
  • Switch between simple and log return calculations
  • Reset everything to defaults with one button

Thank you!