A notebook to an ML pipelines that predicts stock prices, forex USD/ZMW
readme = """# zambian forex and stock predictor
Predicts whether the Zambian Kwacha (ZMW) will strengthen or weaken
against the USD over the next 7 days, using copper prices and macro indicators.
Built from the Zambian Financial Datasets
project — 117GB of raw data curated into clean CSVs.
---
## 📊 Model Performance
| Model | Accuracy |
|---|---|
| V1 Random Forest (baseline) | 56.26% |
| V2 Random Forest + Macro | **62.62% ✅ winner** |
| V2 + Mining stocks | 61.90% |
| XGBoost | 56.06% |
| 30-day target | 45.83% |
**Best used when model confidence is above 70%.**
---
## 🧠 How It Works
Copper Price (HG=F) ──┐
ZMW History ──────────┤──▶ Random Forest ──▶ ZMW UP or DOWN in 7 days
Zambian Macro Data ───┘ (200 trees, 17 features)
### Key Insight
Copper drives ~70% of Zambia's export earnings. When copper prices
sustain a high level over 30 days, the ZMW tends to strengthen.
The model's top signals are:
1. `zmw_lag1` — yesterday's ZMW rate (momentum)
2. `zmw_ma7` — 7-day ZMW trend
3. `copper_ma30` — 30-day copper average (not daily moves)
4. `copper_lag30` — copper price 30 days ago
---
## 📁 Project Structure
zamstockpredict/
├── zambian-financial-datasets-main/ # Raw CSVs
│ ├── afae-dataset/
│ │ ├── global_markets.csv # Copper, indices, ETFs
│ │ ├── zmw_forex_rates.csv # ZMW forex pairs
│ │ └── zambia_macroeconomic_data.csv
│ └── ziaa-dataset/
│ └── ml_features.csv
├── zmw_FINAL_model.pkl # Trained model
├── zmw_FINAL_features.pkl # Feature list
├── app.py # Streamlit web app
├── copper_vs_zmw_fixed.png # Copper vs ZMW chart
├── feature_importance.png # Feature importance chart
└── backtest_2024.png # 2024 backtest results
---
## 🚀 Run the App
### Requirements
```bash
pip install streamlit scikit-learn pandas numpy yfinance joblib
```
### Launch
```bash
streamlit run app.py
```
Make sure `zmw_FINAL_model.pkl` …