Research Question

Is there a significant relationship between various technical indicators, external factors, and the adjusted closing prices of AAPL stock? Additionally, does the interaction between the categorical variables “Signal” and “Trend” have a significant impact on the adjusted closing prices?

Data Set Description:

The dataset is created using YahooFinance API as the primary resource.

Variables Extracted:

  • Date: The date of the stock observation.
  • Open: The opening stock price on a given date.
  • High: The highest stock price reached on a given date.
  • Low: The lowest stock price reached on a given date.
  • Adj. Close: The adjusted closing stock price, accounting for factors like dividends and stock splits.
  • SMA_50: Simple Moving Average over a 50-day period.
  • RSI: Relative Strength Index, a momentum indicator.
  • MACD: Moving Average Convergence Divergence, a trend-following momentum indicator.
  • Signal Line: A signal line used in conjunction with the MACD for generating trading signals.
  • Volume: The trading volume of AAPL stock on a given date.
  • SPY: A variable representing an external factor (e.g., S&P 500 index).
  • MCRSFT: A variable representing another external factor (e.g., Microsoft stock prices).
  • Signal: A categorical variable indicating trading signals (e.g., Buy, Sell, Hold).
  • Trend: A categorical variable indicating the trend (e.g., Bullish, Bearish).

Visualising Stock data with technical indicators

Linear Regression Model

We will fit a linear regression model taking all the technical indicators - RSI, MACD, Signal.Line, Volume, SPY, MCRSFT

Model: Adj.Close ~ RSI + MACD + Signal.Line + Volume + SPY + MCRSFT

Model Summary

Estimate Std. Error t value Pr(>|t|)
(Intercept) 8.4522732 5.7176177 1.478286 0.1396777
RSI -0.2437401 0.0505509 -4.821677 0.0000017
MACD 2.5900909 0.8387766 3.087939 0.0020767
Signal.Line -1.6628910 0.7230996 -2.299671 0.0216927
Volume -0.0000001 0.0000000 -5.610234 0.0000000
SPY 0.0073792 0.0018751 3.935340 0.0000894
MCRSFT 0.4660238 0.0188240 24.756916 0.0000000

Hypothesis Testing

Null Hypothesis (H0):

  1. Main Effect of Predictors:
    • \(H_{0}:\) The predictors are insignificant to predict Apple’s stock price.

Alternative Hypothesis (H1):

  1. Main Effect of Predictors:
    • \(H_{a}:\) At least one of the predictors is significant to predict Apple’s stock price.

ANOVA for Linear Regression Model

ANOVA Results

Df Sum Sq Mean Sq F value Pr(>F)
RSI 1 471.9744 471.9744 3.958394 0.0469375
MACD 1 29157.6463 29157.6463 244.541767 0.0000000
Signal.Line 1 5789.7432 5789.7432 48.557899 0.0000000
Volume 1 309231.7867 309231.7867 2593.490800 0.0000000
SPY 1 302070.7541 302070.7541 2533.432058 0.0000000
MCRSFT 1 73078.9859 73078.9859 612.904901 0.0000000
Residuals 909 108383.5324 119.2338 NA NA

Checking the Assumptions of the model

Based on the above plots we are majorly in line with the assumptions:

Introducing Categorical Elements

Based on the signal line and market conditions i have introduced two categorical variables:

#Hypothesis # Hypotheses Testing

Main Effect of Signal

Null Hypothesis (H0):

  • \(H_{0}:\) There is no significant difference among the different levels of the “Signal” variable after controlling for the effect of the “Trend” variable.

Alternative Hypothesis (Ha):

  • \(H_{1}:\) There is a significant difference in the mean of the dependent variable among the different levels of the “Signal” variable after controlling for the effect of the “Trend” variable.

Main Effect of Trend

Null Hypothesis (H0):

  • \(H_{0}:\) There is no significant relationship between the “Trend” variable and the dependent variable after accounting for differences in the “Signal” variable.

Alternative Hypothesis (Ha):

  • \(H_{1}:\) There is a significant relationship between the “Trend” variable and the dependent variable after accounting for differences in the “Signal” variable.

ANCOVA Results

Sum Sq Df F value Pr(>F)
(Intercept) 1497.9063 1 12.249087 0.0004881
RSI 1971.4463 1 16.121448 0.0000643
MACD 1277.2086 1 10.444338 0.0012745
SPY 5014.2119 1 41.003581 0.0000000
Signal 201.0213 1 1.643846 0.2001255
Trend 1613.1472 1 13.191467 0.0002970
MCRSFT 72765.1787 1 595.035255 0.0000000
Residuals 111159.0396 909 NA NA

Main Effects Analysis

Main Effect of Signal:

The p-value for Signal is 0.2001, which is greater than the conventional significance level of 0.05. Therefore, we fail to reject the null hypothesis. This suggests that there is no significant difference in the mean of the dependent variable among the different levels of the “Signal” variable.

Main Effect of Trend:

The p-value for Trend is 0.0003, which is less than 0.05. Therefore, we reject the null hypothesis. This suggests that there is a significant relationship between the “Trend” variable and the dependent variable after accounting for differences in the “Signal” variable.

Interaction

Checking whether Buy and Sell signals have some connectivity with market being Bullish or Bearish

Interaction Plot

Conclusion

The analysis indicates that the included technical indicators and external factors have a significant impact on predicting AAPL stock prices. However, the main effect of the “Signal” variable is not statistically significant, suggesting no significant difference in the mean of adjusted closing prices among different signal levels. On the other hand, the main effect of the “Trend” variable is found to be significant, implying a relationship between the trend and adjusted closing prices after considering differences in the signal variable.

In conclusion, this study provides insights into the factors influencing AAPL stock prices, offering valuable information for researchers and investors. Further refinement of the model and exploration of additional factors may enhance predictive accuracy and actionable insights.

Limitations

Limited Time Period:

The analysis covers a specific time period, and the model’s effectiveness may be influenced by market conditions during that timeframe. Results might not generalize well to different market environments.

External Factors:

External factors such as economic events, policy changes, or unforeseen circumstances that occurred during the study period may not be fully captured by the model.

Risk of Overfitting:

Including a large number of predictors in the model increases the risk of overfitting, where the model performs well on the training data but may not generalize effectively to new data.

Market Volatility:

The stock market is inherently volatile, and the model’s predictions may be sensitive to market fluctuations, making it challenging to accurately forecast prices.

Model Updating:

Financial markets evolve over time, and the model might need regular updating to adapt to changing market dynamics. Failure to update the model could impact its relevance.