Created
March 23, 2020 15:48
-
-
Save olynch/743aae9eee3a55e1d0f5d96cb7fb9651 to your computer and use it in GitHub Desktop.
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
--- | |
title: Moving the Stock Market Backwards in Time | |
--- | |
```{r, echo=FALSE,warning=FALSE,message=FALSE} | |
library('tidyverse') | |
library('tidyquant') | |
library('tsibble') | |
library('dygraphs') | |
spy <- tq_get('SPY') %>% as_tsibble() | |
rawcpi <- tq_get('RATEINF/CPI_USA',get="quandl") %>% | |
as_tsibble() | |
cpi <- rawcpi %>% | |
filter(date >= ymd("2000-01-01")) %>% | |
append_row(n=30) %>% | |
fill_gaps() %>% | |
tidyr::fill(value, .direction = "down") | |
adj_spy <- left_join(spy,cpi,by='date') %>% | |
transmute(adj_close = close / value,adj_high = high / value, adj_low = low / value) | |
mostrecent <- adj_spy %>% | |
pull(adj_close) %>% | |
last() | |
inhistory <- adj_spy %>% | |
filter(date <= ymd("2020-02-01")) %>% | |
filter(adj_close <= mostrecent) %>% | |
pull(date) %>% | |
last() | |
risefall <- adj_spy %>% | |
filter(date >= inhistory) %>% | |
ggplot(aes(x = date, y = adj_close)) + | |
geom_line() + | |
geom_bbands(aes(high = adj_high, low = adj_low,close=adj_close),ma_fun=EMA,n=50) | |
## dygraph(xts(pull(risefall,adj_close),order.by=pull(risefall,date))) | |
risefall | |
``` | |
The last time the inflation-adjusted S&P500 was this low was `r I(inhistory)`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment