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` β¦