## # A tibble: 1 × 3
## Positive Negative Zero
## <int> <int> <int>
## 1 648 601 1
## # A tibble: 2 × 2
## Direction n
## <fct> <int>
## 1 Down 602
## 2 Up 648
## # A tibble: 1 × 1
## Median_Today
## <dbl>
## 1 0.0385
## # A tibble: 5 × 2
## Year n
## <dbl> <int>
## 1 2001 242
## 2 2002 252
## 3 2003 252
## 4 2004 252
## 5 2005 252
library(ggplot2)
data %>%
ggplot(aes(x = Lag1)) +
geom_histogram(binwidth = 0.1, fill = "blue", alpha = 0.7) +
ggtitle("Distribution of Lag1")data %>%
ggplot(aes(x = Lag3)) +
geom_histogram(binwidth = 0.1, fill = "green", alpha = 0.7) +
ggtitle("Distribution of Lag3")data %>%
ggplot(aes(x = Lag5)) +
geom_histogram(binwidth = 0.1, fill = "red", alpha = 0.7) +
ggtitle("Distribution of Lag5")data %>%
ggplot(aes(x = Today, fill = Direction)) +
geom_density(alpha = 0.5) +
ggtitle("Distribution of Percentage Return for Today Based on Market Direction")## # A tibble: 5 × 2
## Year Mean_Volume
## <dbl> <dbl>
## 1 2001 1.23
## 2 2002 1.43
## 3 2003 1.38
## 4 2004 1.42
## 5 2005 1.92
data %>%
group_by(Year) %>%
summarise(
`10%` = quantile(Today, 0.1, na.rm = TRUE),
`30%` = quantile(Today, 0.3, na.rm = TRUE),
`50%` = quantile(Today, 0.5, na.rm = TRUE),
`70%` = quantile(Today, 0.7, na.rm = TRUE),
`90%` = quantile(Today, 0.9, na.rm = TRUE)
)## # A tibble: 5 × 6
## Year `10%` `30%` `50%` `70%` `90%`
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2001 -1.72 -0.560 -0.0425 0.587 1.48
## 2 2002 -2.14 -0.935 -0.178 0.626 1.85
## 3 2003 -1.27 -0.438 0.128 0.58 1.38
## 4 2004 -0.967 -0.257 0.0635 0.390 0.911
## 5 2005 -0.834 -0.313 0.056 0.350 0.843
median_lag1_up <- median(data$Lag1[data$Direction == "Up"], na.rm = TRUE)
data <- data %>%
filter(Direction == "Up") %>%
mutate(
Lag1_Median_Category = ifelse(Lag1 > median_lag1_up, "Above Median", "Below Median")
)
head(data$Lag1_Median_Category)## [1] "Above Median" "Above Median" "Below Median" "Above Median" "Above Median"
## [6] "Below Median"
##
## Above Median Below Median
## 322 326
## # A tibble: 1 × 1
## Mean_Today
## <dbl>
## 1 0.803
## # A tibble: 1 × 1
## Median_Today
## <dbl>
## 1 0.582