CoolFace
Apppublic

mirzafathir/usd-idr-forecasting

sourceHugging Facemitupdated 3mo agoView on Hugging Face
0likes
App README

<div align="center">

๐Ÿ“ˆ USD/IDR Exchange Rate Forecasting

XGBoost + BiLSTM Ensemble Pipeline โ€” Prediksi kurs USD/IDR dengan akurasi tinggi

![Python](https://www.python.org/) ![XGBoost](https://xgboost.ai/) ![Streamlit](https://streamlit.io/) ![FastAPI](https://fastapi.tiangolo.com/) ![License](LICENSE)

MetricValue
๐Ÿ“‰ MAE37.9 IDR
๐Ÿ“Š MAPE0.224%
๐Ÿ“ˆ Rยฒ0.9842
๐ŸŽฏ Directional Accuracy32.66%
โšก Inference< 1ms

</div>


๐Ÿ—‚๏ธ Daftar Isi


๐ŸŽฎ Demo

Live Dashboard: Jalankan aplikasi Streamlit di atas untuk melihat forecast interaktif, analisis SHAP, dan prediksi 14-hari ke depan dengan confidence interval.

[image]


๐Ÿ” Overview

Proyek ini merupakan Final Project Big Data โ€” Semester 6, TC ITS yang membangun pipeline forecasting kurs USD/IDR secara end-to-end:

  • โ€”Data: Harga harian USD/IDR + makroekonomi (BI Rate, inflasi, emas, minyak) dari 2000โ€“2026
  • โ€”Target: Log-return USD/IDR (bukan level harga langsung) โ†’ menghindari extrapolation cap pada tree-based model
  • โ€”Forecasting: Rekursif multi-step dengan back-transform: level[t+1] = level[t] ร— exp(predicted_return)
  • โ€”Live Data: Harga USD/IDR real-time via Yahoo Finance (cache 5 menit)

๐Ÿ—๏ธ Arsitektur Pipeline

Raw Data (yfinance / CSV)
        โ”‚
        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Feature Eng.    โ”‚  27 fitur: lag, rolling, RSI, BI-Fed spread,
โ”‚  (src/features)  โ”‚  commodity returns, kalender
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                           โ”‚
    โ–ผ                           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ XGBoost โ”‚              โ”‚  BiLSTM  โ”‚  (opsional, butuh GPU/Linux)
โ”‚ + Q10   โ”‚              โ”‚  2-layer โ”‚
โ”‚ + Q90   โ”‚              โ”‚  Huber   โ”‚
โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜              โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
     โ”‚                        โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ–ผ
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚    Ridge     โ”‚  Meta-learner ensemble
        โ”‚  Ensemble    โ”‚  stacking XGBoost + LSTM
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ–ผ
    Recursive Multi-Step Forecast
    + Quantile CI (Q10 / Q90)

Walk-Forward Validation:

Expanding Window:              Blocked (purge_gap=5):
[====Train====|Val]            [=Train=|gap|=Val=|gap|...]
[======Train======|Val]        [==Train==|gap|=Val=|gap|...]
[========Train========|Val]    [===Train===|gap|=Val=|gap|...]

๐Ÿ“Š Features (27 Variabel)

KategoriFitur
LagUSD_IDR_Lag_1, _Lag_3, _Lag_5, _Lag_7, _Lag_14, _Lag_30
Rolling StatsRolling_Mean_7, Rolling_Mean_30, Rolling_STD_7, Rolling_STD_30
MomentumReturn_5d, Return_10d, Return_20d, USD_IDR_Diff_1, Volatility_10
TechnicalRSI_14
MakroBI_Rate, Inflation, BI_Fed_Spread
KomoditasGold_Price, Oil_Price, Gold_Return, Oil_Return
KalenderDayOfWeek, Month, Quarter, IsMonthEnd

๐Ÿ“ˆ Model Performance

XGBoost (Test Set: Jan 2020 โ€“ Jun 2026)

[image]

MetricXGBoostBaseline (Naive)Improvement
MAE (IDR)37.9~280-86%
MAPE0.224%~1.6%-86%
Rยฒ0.984~0.0โ€”
RMSE51.4~395-87%

Walk-Forward Validation

[image]

14-Day Forecast dengan Confidence Interval

[image]

Feature Importance (SHAP-based)

[image]


๐Ÿš€ Cara Penggunaan

1. Clone & Install

bash
git clone https://huggingface.co/spaces/YOUR_USERNAME/usd-idr-forecasting
cd usd-idr-forecasting
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt

2. Jalankan Dashboard

bash
streamlit run app.py
# โ†’ http://localhost:8501

3. Jalankan API

bash
uvicorn api:app --reload --port 8000
# โ†’ Swagger: http://localhost:8000/docs

4. Generate Artifacts (tanpa training ulang)

bash
python generate_artifacts.py
# ~10 detik, menghasilkan semua CSV/PNG di output/ dan figure/

5. Training Ulang (opsional)

bash
# Fast mode (~15-20 menit)
python train_fp.py --fast

# Full GridSearchCV (~60-90 menit)
python train_fp.py

๐Ÿ”Œ API Endpoint

bash
# Health check
curl http://localhost:8000/

# 14-day forecast
curl -X POST http://localhost:8000/forecast/multistep \
  -H "Content-Type: application/json" \
  -d '{"n_steps": 14}'

# Metrics
curl http://localhost:8000/metrics

Swagger docs: http://localhost:8000/docs


๐Ÿณ Deployment

Docker Compose (Streamlit + FastAPI)

bash
docker-compose up --build -d
# Dashboard  โ†’ http://localhost:8501
# API        โ†’ http://localhost:8000

Streamlit Cloud / HF Spaces

Push repo ke GitHub/HF โ†’ auto-deploy via app.py + requirements.txt.

GitHub Actions CI

yaml
# .github/workflows/ci.yml sudah tersedia:
# - Syntax check semua file Python
# - Import check (pastikan semua dep tersedia)
# - Dataset integrity check
# - Docker build

๐Ÿ“ Struktur Proyek

.
โ”œโ”€โ”€ app.py                    # Streamlit dashboard v3.0
โ”œโ”€โ”€ api.py                    # FastAPI inference server v3.0
โ”œโ”€โ”€ train_fp.py               # Pipeline training XGBoost + BiLSTM
โ”œโ”€โ”€ generate_artifacts.py     # Generate semua output/ tanpa training ulang
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ .streamlit/config.toml
โ”œโ”€โ”€ .github/workflows/ci.yml
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ config.py             # Konfigurasi global (dataclass)
โ”‚   โ”œโ”€โ”€ features.py           # Feature engineering pipeline
โ”‚   โ”œโ”€โ”€ evaluation.py         # Metrics + walk-forward CV
โ”‚   โ””โ”€โ”€ inference.py          # Multi-step forecast functions
โ”‚
โ”œโ”€โ”€ output/                   # Model artifacts + CSV results
โ”‚   โ”œโ”€โ”€ xgboost_model.pkl
โ”‚   โ”œโ”€โ”€ xgboost_q10.pkl       # Quantile 10% (lower CI)
โ”‚   โ”œโ”€โ”€ xgboost_q90.pkl       # Quantile 90% (upper CI)
โ”‚   โ”œโ”€โ”€ model_config.json
โ”‚   โ”œโ”€โ”€ evaluation_results.csv
โ”‚   โ””โ”€โ”€ multistep_forecast_14d.csv
โ”‚
โ””โ”€โ”€ figure/                   # 16 visualisasi PNG
    โ”œโ”€โ”€ summary_dashboard.png
    โ”œโ”€โ”€ actual_vs_pred_xgboost.png
    โ”œโ”€โ”€ feature_importance_xgboost.png
    โ”œโ”€โ”€ walk_forward_validation.png
    โ””โ”€โ”€ ...

๐Ÿ“š Tech Stack

LayerTools
Datapandas, numpy, yfinance
Featuresscikit-learn, statsmodels
ModelXGBoost 3.2, TensorFlow/Keras (BiLSTM)
ExplainabilitySHAP TreeExplainer
VisualizationPlotly, Matplotlib, Seaborn
APIFastAPI + Pydantic
DashboardStreamlit
DevOpsDocker, GitHub Actions

๐Ÿ‘ค Author

Mirza Fathir R. โ€” Teknik Komputer, Institut Teknologi Sepuluh Nopember (ITS) Final Project Big Data, Semester 6, 2025/2026


<div align="center"> <sub>Built with โค๏ธ for Big Data Final Project โ€” TC ITS 2025/2026</sub> </div>