Skip to content

Instantly share code, notes, and snippets.

@ericnovik
Created August 20, 2025 17:55
Show Gist options
  • Select an option

  • Save ericnovik/9ac7feb95ed89928faf3fa71b45eecdb to your computer and use it in GitHub Desktop.

Select an option

Save ericnovik/9ac7feb95ed89928faf3fa71b45eecdb to your computer and use it in GitHub Desktop.
library(tidyverse)
# Parameters
rates <- seq(0.05, 0.20, length = 10)
time <- seq(1, 50, length = 50)
P <- 100
# Continuous compounding formula: A(t) = P * exp(r * t)
df <- expand_grid(time = time, rate = rates) |>
mutate(value = P * exp(rate * time),
rate = round(rate, 2) |> as.character())
# Plot
ggplot(df, aes(x = time, y = value, color = factor(rate))) +
geom_line(size = 0.3) +
scale_y_continuous(labels = scales::dollar_format()) +
labs(
title = "Growth of $100 at different interest rates",
x = "Time (years)",
y = "Asset value",
color = "rate"
) +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment