Created
March 22, 2017 14:47
-
-
Save dodger487/39db8573df775f1adbd04783d0808b9f to your computer and use it in GitHub Desktop.
A brief look at election's effect on S&P 500
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
# Chris Riederer | |
# 2017-03-21 | |
# Look at election's impact on stock market | |
library("MASS") | |
library(quantmod) | |
library(dplyr) | |
library(ggplot2) | |
# Pull in S&P data from Yahoo Finance | |
getSymbols("^GSPC", src="yahoo") | |
# Convert to friendly dataframe | |
df <- as.data.frame(GSPC) %>% | |
mutate(date = rownames(.), | |
raw_change = GSPC.Close - GSPC.Open, | |
change = raw_change / GSPC.Open) | |
# What do interesting days look like? | |
df %>% filter(date == "2016-11-07") | |
df %>% filter(date == "2016-11-08") | |
df %>% filter(date == "2016-11-09") | |
df %>% filter(date == "2017-03-21") | |
df %>% | |
filter(date > "2015") %>% | |
ggplot(aes(x=change, fill = date > "2016-11-08")) + | |
geom_histogram(bins=200) + | |
geom_vline(xintercept=0.01487, color="red") + | |
geom_vline(xintercept=-0.01483619, color="blue") + | |
scale_x_continuous("Percent Change") + | |
ggtitle("S&P 500 Performance (Red is Nov 9 2017)") | |
df %>% | |
ggplot(aes(x=change)) + | |
geom_histogram(bins=200) + | |
geom_vline(xintercept=0.01487, color="green") + | |
geom_vline(xintercept=0.0147244, color="red") + | |
geom_vline(xintercept=-0.01483619, color="blue") + | |
scale_x_continuous("Percent Change") + | |
ggtitle("S&P 500 Movements Since 2007") | |
fitdistr(df$change, "normal") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment