Created
January 9, 2022 18:43
-
-
Save statwonk/24b3d09ac997965221f713121e1af148 to your computer and use it in GitHub Desktop.
Analysis of stock prices as a function of the risk free rate and market risk.
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 %>% | |
as_tibble() %>% | |
janitor::clean_names() %>% | |
select(date, one_yr_treasury_rate = x1_yr) %>% | |
right_join(d %>% select(date, asan = close)) %>% | |
right_join(team %>% select(date, team = close)) %>% | |
arrange(date) %>% | |
mutate(log_asan = log(asan), | |
lag_log_asan = lag(log_asan), | |
log_team = log(team)) %>% | |
filter_all(Negate(is.na)) %>% | |
ungroup() -> d2 | |
gamlss(log_asan ~ one_yr_treasury_rate + | |
log_team + | |
lag_log_asan, | |
sigma.formula = ~ one_yr_treasury_rate, | |
data = d2, | |
family = "SST") -> fit | |
summary(fit) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment