View inflation.R
This file contains 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) | |
# CPI | |
# https://data.bls.gov/timeseries/CUSR0000SA0&output_view=pct_1mth | |
readxl::read_xlsx("~/Downloads/SeriesReport-20220817182003_bb0f80.xlsx", skip = 10) %>% | |
mutate(date = seq.POSIXt(as.POSIXct("1957-02-01"), by = "month", length.out = n())) %>% | |
select(date, cpi = Value) %>% | |
inner_join( | |
# Short-term Interest Rates - https://fred.stlouisfed.org/series/DGS1MO | |
read_csv("~/Downloads/DGS1MO (1).csv", col_types = cols( |
View gist:55a29e2a8792b6f2d6833d376d4754da
This file contains 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) | |
# CPI | |
# https://data.bls.gov/timeseries/CUSR0000SA0&output_view=pct_1mth | |
readxl::read_xlsx("~/Downloads/SeriesReport-20220807120638_733b06.xlsx", skip = 10) %>% | |
mutate(date = seq.POSIXt(as.POSIXct("1947-02-01"), by = "month", length.out = n())) %>% | |
select(date, cpi = Value) -> cpi | |
cpi %>% | |
filter(date >= as.POSIXct("1949-01-01")) %>% |
View inflation.R
This file contains 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) | |
library(forecast) | |
library(urca) | |
library(dynlm) | |
library(lmtest) | |
library(sandwich) | |
# https://data.bls.gov/timeseries/CUSR0000SA0&output_view=pct_1mth | |
read_csv("~/Downloads/inflation.csv", skip = 11) %>% | |
janitor::clean_names() %>% |
View stock_prices.R
This file contains 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) | |
library(gamlss); select <- dplyr::select | |
library(fmpapi) | |
library(Quandl) | |
fmp_daily_prices("ASAN") -> d | |
fmp_daily_prices("TEAM") -> team | |
Quandl("USTREASURY/YIELD") -> yc | |
yc %>% |
View clustering.R
This file contains 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) | |
library(lmtest) | |
library(sandwich) | |
5e2 -> students | |
20 -> schools | |
tibble(student_id = 1:students) %>% | |
mutate(school_id = rep(1:schools, max(student_id) / schools)) %>% | |
left_join(tibble(school_id = 1:schools, school_effect = rnorm(schools)), |
View beta_interval_data.R
This file contains 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) | |
library(fitdistrplus) | |
dplyr::select -> select | |
.Machine$double.eps -> eps | |
1975 -> N # number of responses | |
tibble(lower = c(0, 0.25, 0.5, 0.75), # lower bins | |
upper = c(0.25 + eps, 0.5 + eps, 0.75 + eps, 1), # upper bins | |
pct = c(0.32, 0.51, 0.15, 1 - sum(0.32, 0.51, 0.15)), # response shares | |
n = floor(pct * N)) %>% # implied responses + eps |
View mktcap.R
This file contains 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) | |
library(rvest) | |
library(gamlss) | |
library(brms) | |
library(tidybayes) | |
select <- dplyr::select | |
#################################################################################### | |
# Model the market capitalizations of members of the S&P 500. | |
#################################################################################### |
View gist:6283c5b01e5896b94c46edfdd9ff490a
This file contains 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) | |
library(rvest) | |
library(gamlss) | |
library(brms) | |
library(tidybayes) | |
select <- dplyr::select | |
#################################################################################### | |
# Model the market capitalizations of members of the S&P 500. | |
#################################################################################### |
View fattails.R
This file contains 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) | |
library(quantmod) | |
library(gamlss) | |
select <- dplyr::select | |
posix <- function(x) { as.POSIXct(x, origin = "1970-01-01") } | |
## "Fat tails" | |
## Here we compare the residuals from the normal and t distributional models. | |
## Notice standardized error is worse in the normal model. This happens | |
## because returns are leptokurtic (large surprises should be expected, there's risk in stock returns), |
View risk_adds_up2.R
This file contains 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) | |
library(ggthemes) | |
expand.grid( | |
risk = seq(0.1/5e3, 1/5e3, 1e-05), # average daily risk e.g. - 1,000 infected per day in Alabama / 5,000,000 AL population | |
units_of_exposure = seq_len(31) # days of exposure (up to 31 days) | |
) %>% as_tibble() %>% | |
mutate(total_risk = map2_dbl(risk, units_of_exposure, ~ 1 - (1 - .x)^(.y)), | |
total_odds = 1/total_risk, | |
risk_threshold = case_when(total_odds <= 5e2 ~ "Worse than 1 in 500", | |
total_odds <= 1e3 ~ "Worse than 1 in 1k chance", |
NewerOlder