CGS Notebooks
Organized layout for backtest notebooks and CSV data.
Directory structure
notebooks/
├── paths.py # Shared path constants (import from any notebook)
├── backtest/
│ ├── vbt/ # VectorBT backtests (BTC, stocks, RL)
│ ├── xydts/ # xyDTS strategy + parameter optimization (incl. `xyDTS_cgs_base_KR.ipynb`)
│ ├── xfilter/ # xFilter analysis and optimization
│ ├── params/ # Generic parameter optimization
│ ├── seed_price/ # Seed price yearly charts
│ └── misc/
├── data/
│ ├── csv_input/ # Read-only inputs
│ │ ├── prices/us|jp|kr|indices/
│ │ ├── trades/ # Canonical trade-state logs
│ │ └── seed/ # BTC/ETH consolidated price data
│ └── csv_output/ # Generated outputs
│ ├── trades/
│ ├── optimization/
│ ├── lp_trades/
│ └── metrics/
├── models/ # RL model artifacts (.pth, .pkl)
└── archive/ # Superseded notebooks and duplicate CSVs
Using paths in notebooks
Each notebook that reads/writes CSVs includes this setup (added automatically):
import sys
from pathlib import Path
_nb_root = None
for _p in [Path.cwd(), *Path.cwd().parents]:
if (_p / "paths.py").exists() and (_p / "data" / "csv_input").exists():
_nb_root = _p
break
if (_p / "notebooks" / "paths.py").exists():
_nb_root = _p / "notebooks"
break
else:
raise RuntimeError(
"Could not find notebooks/paths.py — start Jupyter from cgs_tech/ or notebooks/"
)
if str(_nb_root) not in sys.path:
sys.path.insert(0, str(_nb_root))
from paths import (
PRICES_US, PRICES_JP, PRICES_KR, PRICES_INDICES,
TRADES_INPUT, TRADES_OUTPUT, SEED_INPUT,
OPTIMIZATION_OUTPUT, LP_TRADES_OUTPUT, METRICS_OUTPUT,
ensure_on_sys_path,
)
ensure_on_sys_path()
Reads: pd.read_csv(TRADES_INPUT / "cgs_trades_log_....csv")
Writes: df.to_csv(TRADES_OUTPUT / "cgs_trades_log_....csv")
Imports: from indicators... and from data_sources... resolve via ensure_on_sys_path() → cgs_tech/src/
Works whether Jupyter’s working directory is cgs_tech/, notebooks/, or a notebook subfolder.
Canonical trade logs (csv_input/trades)
| File | Use case |
|---|---|
cgs_trades_log_20200101_to_20250728_15m.csv |
BTC 15m |
cgs_trades_log_long_only_20200101_to_20250728_15m.csv |
BTC 15m long-only |
cgs_trades_log_long_only_19900104_to_20250825_1d.csv |
Nikkei 1d |
cgs_trades_log_long_only_20100104_to_20250825_1d.csv |
Softbank 1d |
cgs_trades_log_long_only_19991001_to_20250825_1d.csv |
Toyota 1d |
cgs_trades_log_19991101_to_20250825_1d.csv |
Sony 1d |
Nikkei_cgs_trades_log_19900104_to_20250815_1d.csv |
Nikkei (xFilter) |
Older date-variant logs are in archive/data/trades/.
Archived notebooks
Superseded variants moved to archive/notebooks/:
xyDTS_cgs_base_v0.ipynbVBT_TSLP_cgs_base_b.ipynbVBT_TSLP_cgs_base copy.ipynb
Running notebooks
Open Jupyter with repo root (cgs_tech) or notebooks/ as the working directory. The paths.py lookup walks up to 6 parent directories to find notebooks/paths.py.