File size: 2,571 Bytes
20336d2
f39d4f5
007eead
 
 
 
f39d4f5
007eead
20336d2
 
 
f39d4f5
007eead
f39d4f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: Forex + Crypto Trading Prediction
emoji: πŸ“ˆ
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 4.44.1
app_file: app.py
pinned: false
---

# Forex + Crypto Trading Prediction App

Single-file, self-contained prediction & backtesting app for Forex and Crypto
markets, built with **Gradio + CatBoost**. Prediction/backtesting only β€”
**no live trade execution**.

## Features

- **Data ingestion** β€” live via `yfinance` β†’ Twelve Data (optional API key) β†’
  CSV upload/cache fallback, with flexible column mapping and canonicalization.
- **Timezone & calendar handling** β€” fixed operational timezone (Asia/Kolkata),
  gap classification (weekend/holiday/outage), holiday calendar versioning.
- **Feature engineering** β€” core technical indicator set (EMA, MACD, RSI,
  Stochastic, ADX, Bollinger Bands, ATR, VWAP, OBV, Donchian, etc.),
  fractional differencing, leak-safe rolling windows.
- **Labeling** β€” triple-barrier labeling (with fixed-threshold fallback).
- **Model training** β€” CatBoost with HistGB fallback, walk-forward
  cross-validation, hyperparameter search, fold-stability rejection rule,
  deterministic seeding (SEED=42).
- **Calibration & confidence** β€” bootstrap-averaged isotonic / Platt
  calibration plus a time-weighted split-conformal layer for confidence bands.
- **Drift & auto-retrain** β€” PSI/F1/confidence drift monitors, scheduled and
  volume-triggered retraining with acceptance gating and rollback.
- **Backtesting & forward test** β€” out-of-sample backtest with commissions,
  slippage, spread, and a strictly separate paper-trading forward test.
- **Observability** β€” sequential operational event log and an append-only
  JSONL audit trail.
- **Developer self-test** β€” `--selftest` runs an end-to-end acceptance check
  on synthetic Forex & Crypto fixtures (fast HPO).

## Run locally

```bash
pip install -r requirements.txt
python app.py
```

The Gradio UI launches on `http://localhost:7860`.

## Developer acceptance check

```bash
python app.py --selftest
```

## Deploy on Hugging Face Spaces

1. Create a new Space with SDK = **Gradio**.
2. Upload `app.py`, `requirements.txt`, and this `README.md`.
3. The Space will build and launch automatically (`app_file: app.py`).

## Notes

- All timestamps are shown in IST (UTC+5:30).
- Historical backtests are never evidence of future performance.
- A Twelve Data API key is optional and, if provided, is kept for the
  session only β€” never logged or persisted to source.
- Target runtime: Python 3.10+, 2 CPU / 16 GB RAM (Docker-based Spaces).