2024-09-21
aapl_data <- getSymbols("AAPL", src = "yahoo", auto.assign = FALSE)
aapl_df <- data.frame(Date = index(aapl_data), coredata(aapl_data))
ggplot(aapl_df, aes(x = Date, y = AAPL.Close)) +
geom_point(color = "blue", alpha = 0.5) +
geom_smooth(method = "lm", color = "red", se = FALSE) +
labs(title = "AAPL Closing Price", x = "Year", y = "Closing Price") +
theme_minimal()
aapl_data <- getSymbols("AAPL", src = "yahoo", auto.assign = FALSE)
aapl_df <- data.frame(Date = index(aapl_data), coredata(aapl_data))
ggplot(aapl_df, aes(x = AAPL.Volume)) +
geom_histogram(binwidth = 50000000, fill = "lightgreen", color = "white", alpha = 0.7) +
labs(title = "Distribution of AAPL Trading Volume Per Day 2007 Onward", x = "Volume", y = "Frequency") +
theme_minimal()
\[ \hat{y} = \beta_0 + \beta_1 x \] - \(\hat{y}\) is the predicted closing price. \(x\) is the time variable. \(\beta_0\) is the intercept, representing the closing price at \(x = 0\). \(\beta_1\) is the slope, representing the rate of change of the closing price with respect to time.
The formula for percentage change between two days is:
\[ \% \Delta P = \frac{P_t - P_{t-1}}{P_{t-1}} \times 100 \]
\(P_t\) is the closing price at day \(t\). \(P_{t-1}\) is the closing price at the previous day.