Update README.md
Browse files
README.md
CHANGED
|
@@ -8,12 +8,64 @@ This repository contains models for forecasting Apple stock prices using ARIMA a
|
|
| 8 |
|
| 9 |
## Inference Instructions
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 8 |
|
| 9 |
## Inference Instructions
|
| 10 |
|
| 11 |
+
You can either navigate to the specific model folder and open the provided notebook, or run the inference code directly below.
|
| 12 |
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
<details>
|
| 16 |
+
<summary>ARIMA Model Inference</summary>
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
# Install required packages
|
| 20 |
+
!pip install --quiet yfinance joblib pmdarima huggingface_hub
|
| 21 |
+
|
| 22 |
+
# Import Libraries
|
| 23 |
+
from huggingface_hub import hf_hub_download
|
| 24 |
+
import joblib
|
| 25 |
+
import numpy as np
|
| 26 |
+
import pandas as pd
|
| 27 |
+
import yfinance as yf
|
| 28 |
+
|
| 29 |
+
HF_TOKEN = "your_own_hf_token"
|
| 30 |
+
|
| 31 |
+
# Load ARIMA model and Box-Cox transformer
|
| 32 |
+
arima_model_path = hf_hub_download(
|
| 33 |
+
repo_id="EsferSami/DataSynthis_ML_JobTask",
|
| 34 |
+
filename="Apple-Stock-Price-Forecasting-ARIMA-Model/apple_stock_arima.pkl",
|
| 35 |
+
token=HF_TOKEN
|
| 36 |
+
)
|
| 37 |
+
bct_path = hf_hub_download(
|
| 38 |
+
repo_id="EsferSami/DataSynthis_ML_JobTask",
|
| 39 |
+
filename="Apple-Stock-Price-Forecasting-ARIMA-Model/boxcox_transformer.pkl",
|
| 40 |
+
token=HF_TOKEN
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
arima_model = joblib.load(arima_model_path)
|
| 44 |
+
bct = joblib.load(bct_path)
|
| 45 |
+
|
| 46 |
+
# Download recent data
|
| 47 |
+
data = yf.download("AAPL", period="3mo", auto_adjust=False)
|
| 48 |
+
recent_prices = data['Adj Close'].values.astype(float)
|
| 49 |
+
|
| 50 |
+
# Transform and forecast
|
| 51 |
+
y_trans, _ = bct.transform(recent_prices)
|
| 52 |
+
resid_std = np.std(arima_model.resid()) if hasattr(arima_model, "resid") else np.std(y_trans - np.mean(y_trans))
|
| 53 |
+
|
| 54 |
+
predictions_trans = []
|
| 55 |
+
current_series = y_trans.copy()
|
| 56 |
+
for day in range(7):
|
| 57 |
+
try:
|
| 58 |
+
pred = arima_model.predict(n_periods=1)[0]
|
| 59 |
+
except Exception:
|
| 60 |
+
pred = current_series[-1]
|
| 61 |
+
pred = current_series[-1] + np.random.normal(0.0, resid_std*0.3)
|
| 62 |
+
predictions_trans.append(pred)
|
| 63 |
+
current_series = np.append(current_series, pred)
|
| 64 |
+
|
| 65 |
+
predictions_price, _ = bct.inverse_transform(np.array(predictions_trans))
|
| 66 |
+
prediction_dates = pd.date_range(start=data.index[-1] + pd.Timedelta(days=1), periods=7)
|
| 67 |
+
arima_results_df = pd.DataFrame({'Date': prediction_dates, 'Predicted_Price': predictions_price})
|
| 68 |
|
| 69 |
+
print("\nARIMA - 7-Day Forecast")
|
| 70 |
+
print("="*60)
|
| 71 |
+
print(arima_results_df.to_string(index=False))
|