Skip to content

Instantly share code, notes, and snippets.

@jkr216
Created November 14, 2021 17:21
Show Gist options
  • Save jkr216/ace414e4002f3fc53d6a05770e3f1b07 to your computer and use it in GitHub Desktop.
Save jkr216/ace414e4002f3fc53d6a05770e3f1b07 to your computer and use it in GitHub Desktop.
Misesian Index
library(tidyverse)
library(tidyquant)
library(timetk)
library(readxl)
library(plotly)
library(scales)
library(fredr)
ms_index_symbols_names <-
tibble (
symbol = c("TNWMVBSNNCB", "NCBEILQ027S"),
names = c("Corporate Net Worth", "Corporate Equity")
)
ms_index_symbols_names %>%
pull(symbol) %>%
tq_get(get = "economic.data", from = "1979-01-01") %>%
left_join(ms_index_symbols_names, by = "symbol") %>%
select(date, value = price, names) %>%
pivot_wider(names_from = "names", values_from = "value") %>%
mutate(ms_ratio = `Corporate Equity`/(`Corporate Net Worth`),
geom_mean_ms_index = rollapplyr(ms_ratio, 1:n(),
mean.geometric, fill = NA),
ms_index = ms_ratio/geom_mean_ms_index) %>%
ggplot(aes(x = date, y = ms_index)) +
geom_line(color = "steelblue") +
scale_x_date(labels = function(x) zoo::format.yearqtr(x, "Q%q %Y"),
breaks = pretty_breaks(n = 10)) +
theme_minimal() +
labs(title = "Misesian Index", x = "", y = "", caption = "Source: Dao of Capital, FRED data")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment