Skip to content

Instantly share code, notes, and snippets.

@mgei
Created January 17, 2020 10:43
Show Gist options
  • Save mgei/48fabcbf7c82e4bec8674aed6c702238 to your computer and use it in GitHub Desktop.
Save mgei/48fabcbf7c82e4bec8674aed6c702238 to your computer and use it in GitHub Desktop.
leveraged etf compounding performance lag
library(tidyverse)
library(ggplot2)
periods <- 10
trend <- 0
vola <- 0.1
leverage <- 2
ret <- rnorm(10, 0, vola)
return.df <- data.frame(ret) %>%
mutate(period = row_number(),
etf = cumprod(ret+1)-1,
letf = cumprod(ret*leverage+1)-1,
expected = etf*leverage) %>%
pivot_longer(cols = c(etf, letf, expected), names_to = "series")
return.df %>%
ggplot(aes(x = period, y = value, color = series)) +
geom_line()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment