# Download daily stock prices for IBM (starts far before 1991)df_daily <-tq_get(x ="IBM", get ="stock.prices", from ="1970-01-01")# Aggregate to monthly datastock_data_monthly <- df_daily %>%mutate(month =yearmonth(date)) %>%group_by(month) %>%summarise(adjusted =mean(adjusted)) %>%as_tsibble(index = month)# Save to CSVwrite.csv(x = stock_data_monthly, file ="ibm_monthly_data.csv")# Fit initial modelsfits <- stock_data_monthly %>%model(arima =ARIMA(adjusted),ets =ETS(adjusted),naive =NAIVE(adjusted) )
# Fit forecasting models on training setmodels_stock <-model(.data = train,Drift =RW(adjusted ~drift()),NAIVE =NAIVE(adjusted),SNAIVE =SNAIVE(adjusted))# Forecast across the test horizon lengthh <-nrow(test)fc_stock <-forecast(models_stock, h = h)# Plot forecasts against training dataautoplot(object = fc_stock, data = train) +labs(title ="IBM Stock Forecasts", x ="Time", y ="Adjusted Prices")
# Load datadata("EuStockMarkets")# Extract variablesx <- EuStockMarkets[, "DAX"]y <- EuStockMarkets[, "CAC"]# Method A: Calculate slope using Covariance and Varianceslope_manual <-cov(x, y) /var(x)# Method B: Run standard bivariate OLS regressionmodel_bivariate <-lm(CAC ~ DAX, data = EuStockMarkets)slope_lm <-coef(model_bivariate)["DAX"]# Compare resultscat("Manual slope [cov(x,y)/var(x)]:", slope_manual, "\n")
Manual slope [cov(x,y)/var(x)]: 0.5168872
cat("Regression slope [lm()] :", slope_lm, "\n")
Regression slope [lm()] : 0.5168872
# Run multivariate regressionmodel_multivariate <-lm(CAC ~ DAX + SMI, data = EuStockMarkets)# Extract the multivariate coefficient for DAXbeta1_multivariate <-coef(model_multivariate)["DAX"]cat("Simple Cov/Var slope :", slope_manual, "\n")
The equation \(\frac{\text{Cov}(\text{DAX}, \text{CAC})}{\text{Var}(\text{DAX})}\) does not hold for a multivariate regression. Normally, it works because \(\text{DAX}\) is the only predictor variable in the model, so its slope absorbs all correlation with \(Y\). In multivariate regression, both \(X\) variables (like \(\text{DAX}\) and \(\text{SMI}\)) are usually correlated with each other, meaning that the simple covariance formula fails.
We can see that the IBM stock will most likely follow the drift pattern and continue increasing over time. The Drift model follows the average historical trajectory from the start of the training period to the end. The positive slope best represents the long-term upward trend for IBM. However, in reality, actual market growth can vastly outperform or deviate from these basic baseline models.
I believe we should HOLD the stock because simple baseline models like Naive, SNaive, and Drift fail to reliably capture real-world market dynamics and macroeconomic factors. While the long-term trend shows positive growth, these basic models either assume a flat price, force rigid annual seasonality, or project a simple straight line with high uncertainty. Therefore, buying solely based on these basic forecasts carries unnecessary financial risk, making holding the position the wisest choice.