tidyQuant

tidyquant

Automates a lot of equity research and calculation using tidy concepts.

library(tidyquant)
ticker <- "GS"
GS <- ticker %>% tq_get(from="2017/02/01", to="2020/03/01")
GS.Returns <- GS %>% tq_transmute(close, periodReturn, period="monthly")
GSPC <- "^GSPC" %>% tq_get(from="2017/02/01", to="2020/03/01")
GSPC.Returns <- GSPC %>% tq_transmute(close, periodReturn, period="monthly")
My.data <- left_join(GSPC.Returns,GS.Returns,by="date")
summary(lm(monthly.returns.y~monthly.returns.x, data=My.data))
## 
## Call:
## lm(formula = monthly.returns.y ~ monthly.returns.x, data = My.data)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.166658 -0.028234  0.003572  0.036443  0.112258 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       -0.01178    0.00867  -1.359    0.183    
## monthly.returns.x  1.37512    0.22759   6.042  6.8e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.05164 on 35 degrees of freedom
## Multiple R-squared:  0.5105, Adjusted R-squared:  0.4965 
## F-statistic: 36.51 on 1 and 35 DF,  p-value: 6.798e-07

A Plot

Avatar
Robert W. Walker
Associate Professor of Quantitative Methods

My research interests include causal inference, statistical computation and data visualization.

Next