Upload 49 files
Browse files- ADA_sample_7d.csv +0 -0
- ADA_sample_7d.parquet +3 -0
- APT_sample_7d.csv +0 -0
- APT_sample_7d.parquet +3 -0
- ARB_sample_7d.csv +0 -0
- ARB_sample_7d.parquet +3 -0
- ATOM_sample_7d.csv +0 -0
- ATOM_sample_7d.parquet +3 -0
- AVAX_sample_7d.csv +0 -0
- AVAX_sample_7d.parquet +3 -0
- BNB_sample_7d.csv +0 -0
- BNB_sample_7d.parquet +3 -0
- BTC_sample_7d.csv +0 -0
- BTC_sample_7d.parquet +3 -0
- DOGE_sample_7d.csv +0 -0
- DOGE_sample_7d.parquet +3 -0
- DOT_sample_7d.csv +0 -0
- DOT_sample_7d.parquet +3 -0
- ETC_sample_7d.csv +0 -0
- ETC_sample_7d.parquet +3 -0
- ETH_sample_7d.csv +0 -0
- ETH_sample_7d.parquet +3 -0
- FIL_sample_7d.csv +0 -0
- FIL_sample_7d.parquet +3 -0
- INJ_sample_7d.csv +0 -0
- INJ_sample_7d.parquet +3 -0
- LINK_sample_7d.csv +0 -0
- LINK_sample_7d.parquet +3 -0
- LTC_sample_7d.csv +0 -0
- LTC_sample_7d.parquet +3 -0
- NEAR_sample_7d.csv +0 -0
- NEAR_sample_7d.parquet +3 -0
- OP_sample_7d.csv +0 -0
- OP_sample_7d.parquet +3 -0
- SEI_sample_7d.csv +0 -0
- SEI_sample_7d.parquet +3 -0
- SOL_sample_7d.csv +0 -0
- SOL_sample_7d.parquet +3 -0
- SUI_sample_7d.csv +0 -0
- SUI_sample_7d.parquet +3 -0
- TIA_sample_7d.csv +0 -0
- TIA_sample_7d.parquet +3 -0
- WIF_sample_7d.csv +0 -0
- WIF_sample_7d.parquet +3 -0
- XLM_sample_7d.csv +0 -0
- XLM_sample_7d.parquet +3 -0
- XRP_sample_7d.csv +0 -0
- XRP_sample_7d.parquet +3 -0
- imbalance_labs_eda_starter.ipynb +313 -0
ADA_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ADA_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d8da4c283fcdc958be0de2ad578ce39304a8702455e1cd5cbefeaf66433e6577
|
| 3 |
+
size 651636
|
APT_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
APT_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2ee59677be1fad8881bed53fe59f47832cb1c8bc74171248c2d2fde2bbaf63d2
|
| 3 |
+
size 662669
|
ARB_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ARB_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1c9edd185a0744552e5342ab0058f5dffd4c23e9cac627c849995c1cde6ebb5b
|
| 3 |
+
size 663904
|
ATOM_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ATOM_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c9e91ec95941404575dd56fa8555913c90e4d2a7b88bd600abca9c45d1cf1959
|
| 3 |
+
size 679264
|
AVAX_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
AVAX_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f957a4d7fc2a8238219a21d3eeb638b231c1db17d8b85c43526c1967482da953
|
| 3 |
+
size 657228
|
BNB_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
BNB_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:390c6a576b090f6a2a398cd25aa867b74141d764edbbe6dbc5648560daf0b05c
|
| 3 |
+
size 622035
|
BTC_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
BTC_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:88ac5d30a8edc4ceb3f1c4218caca9022e3bca99fe6a708efdb71701cc93bcf8
|
| 3 |
+
size 631398
|
DOGE_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
DOGE_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e48cb5d2be6c1d35f0efcee4ba10eba9ce8015ecffa5a855ac77b88b724994ea
|
| 3 |
+
size 623069
|
DOT_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
DOT_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:765167791985ebd9f981854e3fdda0d20552a3c1cfefdddaede1c4977251c999
|
| 3 |
+
size 637978
|
ETC_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ETC_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:63bc43b1e627130ec37af409a6d16ba3dd4e15eab83eec20cab0e421fc673d37
|
| 3 |
+
size 659962
|
ETH_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ETH_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5fe572cd0d84a61b6ea4239748bc9064d059224046197ce2450db9b9ca1824ed
|
| 3 |
+
size 601889
|
FIL_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
FIL_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8789217d187888c6c83909492001101de7cedea52227822d96bcbc8eaaa2719e
|
| 3 |
+
size 689707
|
INJ_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
INJ_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f3f0c2ba1aa855173ce6c22a497dcc3f9021d098171039aea45bc7b9e18ca300
|
| 3 |
+
size 654992
|
LINK_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
LINK_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a8245e332ab7e038e54095a46b7d43957c13306755a6959d1fa43d41aeff59f
|
| 3 |
+
size 642559
|
LTC_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
LTC_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6339525176ea84335f29e74a021cf7f5738a4ad19a695990dacb2f4cfe52ae84
|
| 3 |
+
size 627743
|
NEAR_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
NEAR_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fa5d7918409b14e52cf547dd008abf5da14eb4ee023c991c68353986a146dbf3
|
| 3 |
+
size 633057
|
OP_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
OP_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:30e277b49634df7e5d97f962f3ee63b7f9eff766cdc5162130e04c56a303cf3b
|
| 3 |
+
size 687502
|
SEI_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
SEI_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bf272039ea9d397e6ac73058d107f4ca81bf0792640c0d5d601e2627e629f1ba
|
| 3 |
+
size 666769
|
SOL_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
SOL_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a8a6f2b85e1582fd4309020cd6eb609e5d39fb0b1ba01fbdf23f5b3965c7bc9
|
| 3 |
+
size 599349
|
SUI_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
SUI_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c905c71f55d0cbed9547fcaa6b4ca3639a5ef022b54a205eea788ab04f2e0d78
|
| 3 |
+
size 672079
|
TIA_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
TIA_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d353f6baec5e40fa083e41058a4fe328f18193dc28b0e3394a3d81bc1e0b6206
|
| 3 |
+
size 686490
|
WIF_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
WIF_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:50c3119b538df16a97caec86618e2734267ca91ed3ee328e765febb3408a0efc
|
| 3 |
+
size 650579
|
XLM_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
XLM_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:28b9968a81f92008a9abd57e8dc346007d3b4d3b7a2334915548fb4a8935cb27
|
| 3 |
+
size 648731
|
XRP_sample_7d.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
XRP_sample_7d.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:113ef3290f5aa7ced94566329726710d1213adcc2a77f0ada528c77a08153e95
|
| 3 |
+
size 554758
|
imbalance_labs_eda_starter.ipynb
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# 📊 Imbalance Labs — EDA Starter Kit\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"This notebook walks you through loading, exploring, and visualizing the Imbalance Labs orderbook dataset.\n",
|
| 10 |
+
"\n",
|
| 11 |
+
"**Dataset specs:**\n",
|
| 12 |
+
"- 24 crypto instruments (BTC, ETH, SOL, etc.)\n",
|
| 13 |
+
"- 5-minute aggregated bars, 12+ months history\n",
|
| 14 |
+
"- 47 columns per row: OHLC + 10-level depth (bid/ask volumes + distances)\n",
|
| 15 |
+
"\n",
|
| 16 |
+
"---"
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"cell_type": "markdown",
|
| 21 |
+
"metadata": {},
|
| 22 |
+
"source": [
|
| 23 |
+
"## 1. Setup & Load Data"
|
| 24 |
+
]
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"cell_type": "code",
|
| 28 |
+
"execution_count": null,
|
| 29 |
+
"metadata": {},
|
| 30 |
+
"outputs": [],
|
| 31 |
+
"source": [
|
| 32 |
+
"import pandas as pd\n",
|
| 33 |
+
"import numpy as np\n",
|
| 34 |
+
"import matplotlib.pyplot as plt\n",
|
| 35 |
+
"import matplotlib.dates as mdates\n",
|
| 36 |
+
"\n",
|
| 37 |
+
"plt.style.use('dark_background')\n",
|
| 38 |
+
"plt.rcParams['figure.figsize'] = (14, 6)\n",
|
| 39 |
+
"plt.rcParams['font.size'] = 11\n",
|
| 40 |
+
"\n",
|
| 41 |
+
"ACCENT = '#00FF88'\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"# ── Load a single instrument ──\n",
|
| 44 |
+
"# Replace with your file path\n",
|
| 45 |
+
"df = pd.read_csv('BTC_5m_depth10_derived.csv.gz')\n",
|
| 46 |
+
"df['timestamp_utc'] = pd.to_datetime(df['timestamp_utc'])\n",
|
| 47 |
+
"df = df.set_index('timestamp_utc').sort_index()\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"print(f'Instrument: {df[\"instrument_symbol\"].iloc[0]}')\n",
|
| 50 |
+
"print(f'Rows: {len(df):,}')\n",
|
| 51 |
+
"print(f'Date range: {df.index.min()} → {df.index.max()}')\n",
|
| 52 |
+
"print(f'Columns: {len(df.columns)}')\n",
|
| 53 |
+
"df.head()"
|
| 54 |
+
]
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"cell_type": "markdown",
|
| 58 |
+
"metadata": {},
|
| 59 |
+
"source": [
|
| 60 |
+
"## 2. Price Overview"
|
| 61 |
+
]
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"cell_type": "code",
|
| 65 |
+
"execution_count": null,
|
| 66 |
+
"metadata": {},
|
| 67 |
+
"outputs": [],
|
| 68 |
+
"source": [
|
| 69 |
+
"fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(14, 8), gridspec_kw={'height_ratios': [3, 1]}, sharex=True)\n",
|
| 70 |
+
"\n",
|
| 71 |
+
"ax1.plot(df.index, df['close_price'], color=ACCENT, linewidth=0.7, alpha=0.9)\n",
|
| 72 |
+
"ax1.fill_between(df.index, df['low_price'], df['high_price'], alpha=0.1, color=ACCENT)\n",
|
| 73 |
+
"ax1.set_ylabel('Price (USDT)')\n",
|
| 74 |
+
"ax1.set_title(f'{df[\"instrument_symbol\"].iloc[0]} — Close Price', fontweight='bold')\n",
|
| 75 |
+
"ax1.grid(alpha=0.15)\n",
|
| 76 |
+
"\n",
|
| 77 |
+
"ax2.bar(df.index, df['interval_traded_volume'], width=0.003, color=ACCENT, alpha=0.5)\n",
|
| 78 |
+
"ax2.set_ylabel('Volume')\n",
|
| 79 |
+
"ax2.set_xlabel('Date')\n",
|
| 80 |
+
"ax2.grid(alpha=0.15)\n",
|
| 81 |
+
"\n",
|
| 82 |
+
"ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))\n",
|
| 83 |
+
"plt.tight_layout()\n",
|
| 84 |
+
"plt.show()"
|
| 85 |
+
]
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"cell_type": "markdown",
|
| 89 |
+
"metadata": {},
|
| 90 |
+
"source": [
|
| 91 |
+
"## 3. Orderbook Depth Profile\n",
|
| 92 |
+
"\n",
|
| 93 |
+
"Visualize how liquidity is distributed across the 10 depth levels."
|
| 94 |
+
]
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"cell_type": "code",
|
| 98 |
+
"execution_count": null,
|
| 99 |
+
"metadata": {},
|
| 100 |
+
"outputs": [],
|
| 101 |
+
"source": [
|
| 102 |
+
"# Average depth profile across entire dataset\n",
|
| 103 |
+
"bid_cols = [f'bid_volume_level_{i}' for i in range(1, 11)]\n",
|
| 104 |
+
"ask_cols = [f'ask_volume_level_{i}' for i in range(1, 11)]\n",
|
| 105 |
+
"\n",
|
| 106 |
+
"avg_bid = df[bid_cols].mean().values\n",
|
| 107 |
+
"avg_ask = df[ask_cols].mean().values\n",
|
| 108 |
+
"\n",
|
| 109 |
+
"levels = np.arange(1, 11)\n",
|
| 110 |
+
"\n",
|
| 111 |
+
"fig, ax = plt.subplots(figsize=(10, 6))\n",
|
| 112 |
+
"ax.barh(levels - 0.2, avg_bid, height=0.35, color='#00FF88', alpha=0.8, label='Bid (Buy Wall)')\n",
|
| 113 |
+
"ax.barh(levels + 0.2, avg_ask, height=0.35, color='#FF4444', alpha=0.8, label='Ask (Sell Wall)')\n",
|
| 114 |
+
"ax.set_ylabel('Depth Level')\n",
|
| 115 |
+
"ax.set_xlabel('Average Cumulative Volume')\n",
|
| 116 |
+
"ax.set_title('Orderbook Depth Profile — Average Liquidity by Level', fontweight='bold')\n",
|
| 117 |
+
"ax.set_yticks(levels)\n",
|
| 118 |
+
"ax.legend()\n",
|
| 119 |
+
"ax.grid(alpha=0.15, axis='x')\n",
|
| 120 |
+
"ax.invert_yaxis()\n",
|
| 121 |
+
"plt.tight_layout()\n",
|
| 122 |
+
"plt.show()"
|
| 123 |
+
]
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"cell_type": "markdown",
|
| 127 |
+
"metadata": {},
|
| 128 |
+
"source": [
|
| 129 |
+
"## 4. Bid-Ask Imbalance\n",
|
| 130 |
+
"\n",
|
| 131 |
+
"The **imbalance ratio** measures the relative pressure between buyers and sellers at each level.\n",
|
| 132 |
+
"\n",
|
| 133 |
+
"$$\\text{Imbalance}_k = \\frac{\\text{Bid}_k - \\text{Ask}_k}{\\text{Bid}_k + \\text{Ask}_k}$$\n",
|
| 134 |
+
"\n",
|
| 135 |
+
"A value close to **+1** means heavy buy-side pressure; **−1** means sell-side dominance."
|
| 136 |
+
]
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"cell_type": "code",
|
| 140 |
+
"execution_count": null,
|
| 141 |
+
"metadata": {},
|
| 142 |
+
"outputs": [],
|
| 143 |
+
"source": [
|
| 144 |
+
"# Compute imbalance for level 1 (tightest)\n",
|
| 145 |
+
"df['imbalance_L1'] = (\n",
|
| 146 |
+
" (df['bid_volume_level_1'] - df['ask_volume_level_1']) /\n",
|
| 147 |
+
" (df['bid_volume_level_1'] + df['ask_volume_level_1'])\n",
|
| 148 |
+
")\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"# Rolling smoothed version\n",
|
| 151 |
+
"df['imbalance_L1_smooth'] = df['imbalance_L1'].rolling(60).mean() # 5h rolling avg\n",
|
| 152 |
+
"\n",
|
| 153 |
+
"# ── Plot ──\n",
|
| 154 |
+
"fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(14, 8), sharex=True)\n",
|
| 155 |
+
"\n",
|
| 156 |
+
"ax1.plot(df.index, df['close_price'], color=ACCENT, linewidth=0.6)\n",
|
| 157 |
+
"ax1.set_ylabel('Price')\n",
|
| 158 |
+
"ax1.set_title('Price vs Level-1 Bid-Ask Imbalance', fontweight='bold')\n",
|
| 159 |
+
"ax1.grid(alpha=0.15)\n",
|
| 160 |
+
"\n",
|
| 161 |
+
"ax2.fill_between(df.index, df['imbalance_L1_smooth'],\n",
|
| 162 |
+
" where=df['imbalance_L1_smooth'] > 0, color='#00FF88', alpha=0.5, label='Buy pressure')\n",
|
| 163 |
+
"ax2.fill_between(df.index, df['imbalance_L1_smooth'],\n",
|
| 164 |
+
" where=df['imbalance_L1_smooth'] < 0, color='#FF4444', alpha=0.5, label='Sell pressure')\n",
|
| 165 |
+
"ax2.axhline(0, color='white', linewidth=0.5, alpha=0.3)\n",
|
| 166 |
+
"ax2.set_ylabel('Imbalance (L1)')\n",
|
| 167 |
+
"ax2.set_ylim(-0.5, 0.5)\n",
|
| 168 |
+
"ax2.legend(loc='upper right')\n",
|
| 169 |
+
"ax2.grid(alpha=0.15)\n",
|
| 170 |
+
"\n",
|
| 171 |
+
"plt.tight_layout()\n",
|
| 172 |
+
"plt.show()"
|
| 173 |
+
]
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"cell_type": "markdown",
|
| 177 |
+
"metadata": {},
|
| 178 |
+
"source": [
|
| 179 |
+
"## 5. Depth Distance Heatmap\n",
|
| 180 |
+
"\n",
|
| 181 |
+
"How far is the liquidity from mid-price at each level? Tighter spread = more liquid market."
|
| 182 |
+
]
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"cell_type": "code",
|
| 186 |
+
"execution_count": null,
|
| 187 |
+
"metadata": {},
|
| 188 |
+
"outputs": [],
|
| 189 |
+
"source": [
|
| 190 |
+
"bid_dist_cols = [f'bid_distance_level_{i}' for i in range(1, 11)]\n",
|
| 191 |
+
"ask_dist_cols = [f'ask_distance_level_{i}' for i in range(1, 11)]\n",
|
| 192 |
+
"\n",
|
| 193 |
+
"# Resample to daily for cleaner heatmap\n",
|
| 194 |
+
"daily_bid_dist = df[bid_dist_cols].resample('1D').mean()\n",
|
| 195 |
+
"daily_ask_dist = df[ask_dist_cols].resample('1D').mean()\n",
|
| 196 |
+
"\n",
|
| 197 |
+
"fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 8))\n",
|
| 198 |
+
"\n",
|
| 199 |
+
"im1 = ax1.imshow(daily_bid_dist.T, aspect='auto', cmap='YlGn', interpolation='nearest')\n",
|
| 200 |
+
"ax1.set_title('Bid Distance from Mid-Price (bps)', fontweight='bold')\n",
|
| 201 |
+
"ax1.set_ylabel('Depth Level')\n",
|
| 202 |
+
"ax1.set_yticks(range(10))\n",
|
| 203 |
+
"ax1.set_yticklabels([f'L{i}' for i in range(1, 11)])\n",
|
| 204 |
+
"ax1.set_xlabel('Day')\n",
|
| 205 |
+
"plt.colorbar(im1, ax=ax1, label='bps')\n",
|
| 206 |
+
"\n",
|
| 207 |
+
"im2 = ax2.imshow(daily_ask_dist.T, aspect='auto', cmap='YlOrRd', interpolation='nearest')\n",
|
| 208 |
+
"ax2.set_title('Ask Distance from Mid-Price (bps)', fontweight='bold')\n",
|
| 209 |
+
"ax2.set_ylabel('Depth Level')\n",
|
| 210 |
+
"ax2.set_yticks(range(10))\n",
|
| 211 |
+
"ax2.set_yticklabels([f'L{i}' for i in range(1, 11)])\n",
|
| 212 |
+
"ax2.set_xlabel('Day')\n",
|
| 213 |
+
"plt.colorbar(im2, ax=ax2, label='bps')\n",
|
| 214 |
+
"\n",
|
| 215 |
+
"plt.tight_layout()\n",
|
| 216 |
+
"plt.show()"
|
| 217 |
+
]
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
"cell_type": "markdown",
|
| 221 |
+
"metadata": {},
|
| 222 |
+
"source": [
|
| 223 |
+
"## 6. Multi-Instrument Comparison\n",
|
| 224 |
+
"\n",
|
| 225 |
+
"Load all instruments and compare their average imbalance."
|
| 226 |
+
]
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"cell_type": "code",
|
| 230 |
+
"execution_count": null,
|
| 231 |
+
"metadata": {},
|
| 232 |
+
"outputs": [],
|
| 233 |
+
"source": [
|
| 234 |
+
"import glob\n",
|
| 235 |
+
"\n",
|
| 236 |
+
"files = sorted(glob.glob('*_5m_depth10_derived.csv.gz'))\n",
|
| 237 |
+
"print(f'Found {len(files)} instruments')\n",
|
| 238 |
+
"\n",
|
| 239 |
+
"stats = []\n",
|
| 240 |
+
"for f in files:\n",
|
| 241 |
+
" d = pd.read_csv(f)\n",
|
| 242 |
+
" sym = d['instrument_symbol'].iloc[0]\n",
|
| 243 |
+
" imb = (d['bid_volume_level_1'] - d['ask_volume_level_1']) / (d['bid_volume_level_1'] + d['ask_volume_level_1'])\n",
|
| 244 |
+
" total_vol = d['interval_traded_volume'].sum()\n",
|
| 245 |
+
" stats.append({\n",
|
| 246 |
+
" 'instrument': sym,\n",
|
| 247 |
+
" 'rows': len(d),\n",
|
| 248 |
+
" 'avg_imbalance_L1': imb.mean(),\n",
|
| 249 |
+
" 'std_imbalance_L1': imb.std(),\n",
|
| 250 |
+
" 'total_volume': total_vol,\n",
|
| 251 |
+
" 'avg_spread_L1_bps': (d['ask_distance_level_1'] + d['bid_distance_level_1']).mean(),\n",
|
| 252 |
+
" })\n",
|
| 253 |
+
"\n",
|
| 254 |
+
"comparison = pd.DataFrame(stats).set_index('instrument').sort_values('total_volume', ascending=False)\n",
|
| 255 |
+
"comparison"
|
| 256 |
+
]
|
| 257 |
+
},
|
| 258 |
+
{
|
| 259 |
+
"cell_type": "code",
|
| 260 |
+
"execution_count": null,
|
| 261 |
+
"metadata": {},
|
| 262 |
+
"outputs": [],
|
| 263 |
+
"source": [
|
| 264 |
+
"fig, ax = plt.subplots(figsize=(14, 6))\n",
|
| 265 |
+
"colors = [ACCENT if v > 0 else '#FF4444' for v in comparison['avg_imbalance_L1']]\n",
|
| 266 |
+
"ax.bar(comparison.index, comparison['avg_imbalance_L1'], color=colors, alpha=0.8)\n",
|
| 267 |
+
"ax.axhline(0, color='white', linewidth=0.5, alpha=0.3)\n",
|
| 268 |
+
"ax.set_ylabel('Average L1 Bid-Ask Imbalance')\n",
|
| 269 |
+
"ax.set_title('Cross-Instrument Imbalance Comparison', fontweight='bold')\n",
|
| 270 |
+
"ax.grid(alpha=0.15, axis='y')\n",
|
| 271 |
+
"plt.xticks(rotation=45)\n",
|
| 272 |
+
"plt.tight_layout()\n",
|
| 273 |
+
"plt.show()"
|
| 274 |
+
]
|
| 275 |
+
},
|
| 276 |
+
{
|
| 277 |
+
"cell_type": "markdown",
|
| 278 |
+
"metadata": {},
|
| 279 |
+
"source": [
|
| 280 |
+
"## 7. Feature Engineering Ideas\n",
|
| 281 |
+
"\n",
|
| 282 |
+
"Here are some features you can derive from this dataset for ML models:\n",
|
| 283 |
+
"\n",
|
| 284 |
+
"| Feature | Formula | Use Case |\n",
|
| 285 |
+
"|---|---|---|\n",
|
| 286 |
+
"| **Imbalance Ratio (L1-L10)** | `(bid_vol - ask_vol) / (bid_vol + ask_vol)` | Directional signal |\n",
|
| 287 |
+
"| **Depth-Weighted Imbalance** | Σ `imbalance_k × (1/k)` for k=1..10 | Weighted signal favoring top-of-book |\n",
|
| 288 |
+
"| **Total Depth** | Σ `bid_vol + ask_vol` for k=1..10 | Liquidity regime detection |\n",
|
| 289 |
+
"| **Depth Slope** | Linear regression slope of volume vs level | Wall detection |\n",
|
| 290 |
+
"| **Spread Momentum** | `diff(bid_distance_L1 + ask_distance_L1)` | Spread widening/tightening |\n",
|
| 291 |
+
"| **Volume-Distance Ratio** | `volume_Lk / distance_Lk` | Concentration score |\n",
|
| 292 |
+
"| **Cross-Level Divergence** | `imbalance_L1 - imbalance_L5` | Near vs far pressure gap |\n",
|
| 293 |
+
"\n",
|
| 294 |
+
"---\n",
|
| 295 |
+
"\n",
|
| 296 |
+
"🔗 **imbalancelabs.com** — Full dataset: 24 instruments, 12+ months, 47 columns/row."
|
| 297 |
+
]
|
| 298 |
+
}
|
| 299 |
+
],
|
| 300 |
+
"metadata": {
|
| 301 |
+
"kernelspec": {
|
| 302 |
+
"display_name": "Python 3",
|
| 303 |
+
"language": "python",
|
| 304 |
+
"name": "python3"
|
| 305 |
+
},
|
| 306 |
+
"language_info": {
|
| 307 |
+
"name": "python",
|
| 308 |
+
"version": "3.11.0"
|
| 309 |
+
}
|
| 310 |
+
},
|
| 311 |
+
"nbformat": 4,
|
| 312 |
+
"nbformat_minor": 4
|
| 313 |
+
}
|