Created
August 20, 2025 17:55
-
-
Save ericnovik/9ac7feb95ed89928faf3fa71b45eecdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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