-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
158 lines (130 loc) · 7.56 KB
/
Copy pathconfig.py
File metadata and controls
158 lines (130 loc) · 7.56 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
config.py — Single source of truth for the project.
This file lives at the root of defi-endogenous-fragility/.
Usage in any notebook:
import sys; sys.path.insert(0, "..") # adjust depth as needed
from config import CFG
CFG.ensure_dirs()
"""
from pathlib import Path
import pandas as pd
# ──────────────────────────────────────────────────────────────
# 1. PROJECT ROOT (this file lives at root)
# ──────────────────────────────────────────────────────────────
PROJECT_ROOT = Path(__file__).resolve().parent
# ──────────────────────────────────────────────────────────────
# 2. TEMPORAL SCOPE
# ──────────────────────────────────────────────────────────────
START_UTC = pd.Timestamp("2021-03-15T00:00:00Z")
END_UTC_EXCL = pd.Timestamp("2025-12-01T00:00:00Z")
FREQ = "1h"
# Convention: [start, end_excl) — timestamp = bucket-start
# ──────────────────────────────────────────────────────────────
# 3. DIRECTORY TREE
# ──────────────────────────────────────────────────────────────
DATA_DIR = PROJECT_ROOT / "data"
# --- Raw (immutable after download) ---
RAW_DIR = DATA_DIR / "raw"
RAW_CEX_BYBIT = RAW_DIR / "cex" / "bybit"
RAW_CEX_BINANCE = RAW_DIR / "cex" / "binance"
RAW_BENCHMARKS = RAW_DIR / "benchmarks" / "coinbase"
RAW_DEFI = RAW_DIR / "defi"
# --- Normalized (cleaned, hourly, parquet) ---
NORM_DIR = DATA_DIR / "normalized"
NORM_CEX_BYBIT = NORM_DIR / "cex" / "bybit"
NORM_CEX_BINANCE = NORM_DIR / "cex" / "binance"
NORM_BENCHMARKS = NORM_DIR / "benchmarks" / "coinbase"
NORM_SPOT = NORM_DIR / "spot"
# (No NORM_DEFI path: the cleaned DeFi liquidations CSV under data/raw/defi/
# is read directly by run_defi_merge.py.)
# --- Analysis (single consolidated output) ---
ANALYSIS_DIR = DATA_DIR / "analysis"
WINDOWS_DIR = ANALYSIS_DIR / "windows"
DATASETS_DIR = ANALYSIS_DIR / "datasets"
REPORTS_DIR = ANALYSIS_DIR / "reports"
# --- Econometric-ready ---
ECON_DIR = DATA_DIR / "econ"
# --- Other ---
NOTEBOOKS_DIR = PROJECT_ROOT / "notebooks"
DUNE_QUERIES_DIR = PROJECT_ROOT / "dune_queries"
PAPER_DIR = PROJECT_ROOT / "paper"
# ──────────────────────────────────────────────────────────────
# 4. FILE PATHS (all normalized inputs)
# ──────────────────────────────────────────────────────────────
class FILES:
# Bybit perp (primary venue)
bybit_klines = NORM_CEX_BYBIT / "klines_1h.parquet"
bybit_funding = NORM_CEX_BYBIT / "funding_1h.parquet"
bybit_oi = NORM_CEX_BYBIT / "open_interest_1h.parquet"
# Binance futures (secondary / diagnostic)
binance_futures = NORM_CEX_BINANCE / "binance_futures_ethusdt_1h_normalized.parquet"
# Spot benchmarks (CCData CCCAGG)
btc_spot = NORM_SPOT / "btc_ccdata_1h.parquet"
eth_spot = NORM_SPOT / "eth_ccdata_1h.parquet"
# Coinbase benchmark
coinbase_candles = NORM_BENCHMARKS / "candles_repaired.parquet"
# DeFi liquidations: the cleaned CSV under data/raw/defi/ is read directly
# by run_defi_merge.py (no normalized path).
# --- Analysis outputs ---
master_calendar = WINDOWS_DIR / "master_calendar_1h.parquet"
window_metadata = WINDOWS_DIR / "window_metadata.json"
cex_diagnostics = DATASETS_DIR / "cex_diagnostics_1h.parquet"
# --- Econometric datasets ---
econ_core_predefi = ECON_DIR / "econ_core_predefi_1h.parquet"
econ_core_full = ECON_DIR / "econ_core_full_1h.parquet"
# ──────────────────────────────────────────────────────────────
# 5. ECONOMETRIC PARAMETERS
# ──────────────────────────────────────────────────────────────
class ECON:
# VAR (linear benchmark)
var_max_lags = 48
var_ordering = ["ret", "log_liq"]
# Quantile local projections (main specification)
quantiles = [0.01, 0.05, 0.10, 0.25, 0.50, 0.75, 0.90, 0.95, 0.99]
lp_horizons = list(range(0, 25)) # h = 0..24 hours
lp_n_boot = 1000
# Regime thresholds
stress_pctile = 95 # liquidation volume
high_oi_pctile = 80 # OI crowding regime
# Transformations
log_offset = 1.0 # ln(1 + L_t)
vol_window = 168 # 7-day rolling vol (hours)
# Inference
nw_lags = 12 # Newey-West HAC lags
block_boot_size = 24 # block bootstrap block length
# ──────────────────────────────────────────────────────────────
# 6. SYMBOLS
# ──────────────────────────────────────────────────────────────
PRIMARY_SYMBOL = "ETHUSDT"
PRIMARY_VENUE = "bybit"
BENCHMARK_ASSET = "BTC"
# ──────────────────────────────────────────────────────────────
# 7. HELPERS
# ──────────────────────────────────────────────────────────────
def ensure_dirs():
"""Create all output directories. Safe to call repeatedly."""
for d in [
RAW_CEX_BYBIT, RAW_CEX_BINANCE, RAW_BENCHMARKS, RAW_DEFI,
NORM_CEX_BYBIT, NORM_CEX_BINANCE, NORM_BENCHMARKS, NORM_SPOT,
WINDOWS_DIR, DATASETS_DIR, REPORTS_DIR, ECON_DIR,
DUNE_QUERIES_DIR, PAPER_DIR,
]:
d.mkdir(parents=True, exist_ok=True)
# ──────────────────────────────────────────────────────────────
# 8. CONVENIENCE OBJECT
# ──────────────────────────────────────────────────────────────
class _Cfg:
ROOT = PROJECT_ROOT
START = START_UTC
END_EXCL = END_UTC_EXCL
FREQ = FREQ
FILES = FILES
ECON = ECON
ensure_dirs = staticmethod(ensure_dirs)
def __repr__(self):
return f"Config(root={self.ROOT}, window=[{self.START}, {self.END_EXCL}))"
CFG = _Cfg()
if __name__ == "__main__":
ensure_dirs()
print(CFG)
print("All directories created.")