quantjourney-bidask 0.9.4__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/PKG-INFO +94 -35
  2. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/README.md +90 -33
  3. quantjourney_bidask-1.0.1/data/fetch.py +399 -0
  4. quantjourney_bidask-1.0.1/examples/animated_spread_monitor.py +528 -0
  5. quantjourney_bidask-1.0.1/examples/basic_spread_estimation.py +193 -0
  6. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/examples/crypto_spread_comparison.py +256 -193
  7. quantjourney_bidask-1.0.1/examples/liquidity_risk_monitor.py +105 -0
  8. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/examples/simple_data_example.py +81 -46
  9. quantjourney_bidask-1.0.1/examples/threshold_alert_monitor.py +269 -0
  10. quantjourney_bidask-0.9.4/examples/realtime_spread_monitor.py → quantjourney_bidask-1.0.1/examples/websocket_realtime_demo.py +292 -188
  11. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/pyproject.toml +6 -4
  12. quantjourney_bidask-1.0.1/quantjourney_bidask/__init__.py +34 -0
  13. quantjourney_bidask-1.0.1/quantjourney_bidask/_compare_edge.py +152 -0
  14. quantjourney_bidask-1.0.1/quantjourney_bidask/edge.py +174 -0
  15. quantjourney_bidask-1.0.1/quantjourney_bidask/edge_expanding.py +53 -0
  16. quantjourney_bidask-1.0.1/quantjourney_bidask/edge_hft.py +126 -0
  17. quantjourney_bidask-1.0.1/quantjourney_bidask/edge_rolling.py +64 -0
  18. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/quantjourney_bidask.egg-info/SOURCES.txt +6 -8
  19. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/requirements.txt +1 -0
  20. quantjourney_bidask-0.9.4/data/fetch.py +0 -258
  21. quantjourney_bidask-0.9.4/examples/animated_spread_monitor.py +0 -301
  22. quantjourney_bidask-0.9.4/examples/liquidity_risk_monitor.py +0 -72
  23. quantjourney_bidask-0.9.4/examples/spread_estimator.py +0 -153
  24. quantjourney_bidask-0.9.4/examples/spread_monitor.py +0 -208
  25. quantjourney_bidask-0.9.4/examples/stock_liquidity_risk.py +0 -47
  26. quantjourney_bidask-0.9.4/examples/visualization.py +0 -142
  27. quantjourney_bidask-0.9.4/quantjourney_bidask/__init__.py +0 -7
  28. quantjourney_bidask-0.9.4/quantjourney_bidask/_version.py +0 -7
  29. quantjourney_bidask-0.9.4/quantjourney_bidask/edge.py +0 -152
  30. quantjourney_bidask-0.9.4/quantjourney_bidask/edge_expanding.py +0 -65
  31. quantjourney_bidask-0.9.4/quantjourney_bidask/edge_rolling.py +0 -208
  32. quantjourney_bidask-0.9.4/quantjourney_bidask/websocket_fetcher.py +0 -308
  33. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/CHANGELOG.md +0 -0
  34. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/LICENSE +0 -0
  35. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/MANIFEST.in +0 -0
  36. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/docs/usage_examples.ipynb +0 -0
  37. {quantjourney_bidask-0.9.4 → quantjourney_bidask-1.0.1}/setup.cfg +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantjourney-bidask
3
- Version: 0.9.4
3
+ Version: 1.0.1
4
4
  Summary: Efficient bid-ask spread estimator from OHLC prices
5
5
  Author-email: Jakub Polec <jakub@quantjourney.pro>
6
- License-Expression: MIT
6
+ License: MIT
7
7
  Project-URL: Homepage, https://github.com/QuantJourneyOrg/qj_bidask
8
8
  Project-URL: Repository, https://github.com/QuantJourneyOrg/qj_bidask
9
9
  Project-URL: Bug Tracker, https://github.com/QuantJourneyOrg/qj_bidask/issues
@@ -26,6 +26,7 @@ Requires-Dist: yfinance>=0.2
26
26
  Requires-Dist: matplotlib>=3.5
27
27
  Requires-Dist: plotly>=5.0
28
28
  Requires-Dist: websocket-client>=1.0
29
+ Requires-Dist: numba
29
30
  Provides-Extra: dev
30
31
  Requires-Dist: pytest>=7.0; extra == "dev"
31
32
  Requires-Dist: pytest-mock>=3.10; extra == "dev"
@@ -34,6 +35,7 @@ Requires-Dist: ruff>=0.1; extra == "dev"
34
35
  Requires-Dist: mypy>=1.0; extra == "dev"
35
36
  Requires-Dist: black>=22.0; extra == "dev"
36
37
  Requires-Dist: isort>=5.0; extra == "dev"
38
+ Requires-Dist: numba; extra == "dev"
37
39
  Provides-Extra: examples
38
40
  Requires-Dist: jupyter>=1.0; extra == "examples"
39
41
  Requires-Dist: ipywidgets>=7.0; extra == "examples"
@@ -41,9 +43,13 @@ Dynamic: license-file
41
43
 
42
44
  # QuantJourney Bid-Ask Spread Estimator
43
45
 
44
- ![PyPI](https://img.shields.io/pypi/v/quantjourney-bidask)
45
- ![License](https://img.shields.io/github/license/quantjourney/bidask)
46
- ![Tests](https://img.shields.io/github/workflow/status/quantjourney/bidask/Test)
46
+ ![Build Status](https://github.com/QuantJourneyOrg/qj_bidask/actions/workflows/test.yml/badge.svg)
47
+ [![PyPi Version](https://img.shields.io/pypi/v/quantjourney-bidask.svg)](https://pypi.org/project/quantjourney-bidask/)
48
+ [![Python Versions](https://img.shields.io/pypi/pyversions/quantjourney-bidask.svg)](https://pypi.org/project/quantjourney-bidask/)
49
+ [![Downloads](https://pepy.tech/badge/quantjourney-bidask)](https://pepy.tech/project/quantjourney-bidask)
50
+ [![License](https://img.shields.io/github/license/QuantJourneyOrg/qj_bidask.svg)](https://github.com/QuantJourneyOrg/qj_bidask/blob/main/LICENSE)
51
+ [![GitHub Stars](https://img.shields.io/github/stars/QuantJourneyOrg/qj_bidask?style=social)](https://github.com/QuantJourneyOrg/qj_bidask)
52
+
47
53
 
48
54
  The `quantjourney-bidask` library provides an efficient estimator for calculating bid-ask spreads from open, high, low, and close (OHLC) prices, based on the methodology described in:
49
55
 
@@ -51,6 +57,8 @@ The `quantjourney-bidask` library provides an efficient estimator for calculatin
51
57
 
52
58
  This library is designed for quantitative finance professionals, researchers, and traders who need accurate and computationally efficient spread estimates for equities, cryptocurrencies, and other assets.
53
59
 
60
+ 🚀 **Part of the [QuantJourney](https://quantjourney.substack.com/) ecosystem** - The framework with advanced quantitative finance tools and insights!
61
+
54
62
  ## Features
55
63
 
56
64
  - **Efficient Spread Estimation**: Implements the EDGE estimator for single, rolling, and expanding windows.
@@ -62,6 +70,61 @@ This library is designed for quantitative finance professionals, researchers, an
62
70
  - **Comprehensive Tests**: Extensive unit tests with known test cases from the original paper.
63
71
  - **Clear Documentation**: Detailed docstrings and usage examples.
64
72
 
73
+ ## Examples and Visualizations
74
+
75
+ The package includes comprehensive examples with beautiful visualizations:
76
+
77
+ ### Spread Monitor Results
78
+ ![Spread Monitor](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/refs/heads/main/_output/spread_monitor_results.png)
79
+
80
+ ### Basic Data Analysis
81
+ ![Crypto Spread Analysis](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/ad49bd78c82ab1c44561d0f2e707ae304575a147/_output/crypto_spread_comprehensive_analysis.png)
82
+
83
+ ### Crypto Spread Comparison
84
+ ![Crypto Spread Comparison](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/refs/heads/main/_output/crypto_spread_comparison.png)
85
+
86
+ ## FAQ
87
+
88
+ ### What exactly does the estimator compute?
89
+ The estimator returns the root mean square effective spread over the sample period. This quantifies the average transaction cost implied by bid-ask spreads, based on open, high, low, and close (OHLC) prices.
90
+
91
+ ### What is unique about this implementation?
92
+ This package provides a highly optimized and robust implementation of the EDGE estimator. Beyond a direct translation of the paper's formula, it features:
93
+
94
+ - A Hybrid, High-Performance Engine: The core logic leverages fast, vectorized NumPy operations for data preparation and calls a specialized, JIT-compiled kernel via Numba for the computationally intensive GMM calculations.
95
+ - HFT-Ready Version (edge_hft.py): An included, hyper-optimized function that uses fastmath compilation for the absolute lowest latency, designed for production HFT pipelines where every microsecond matters.
96
+ - Robust Data Handling: Gracefully manages missing values (NaN) and non-positive prices to prevent crashes.
97
+ - Advanced Windowing Functions: Efficient and correct edge_rolling and edge_expanding functions that are fully compatible with the powerful features of pandas, including custom step sizes.
98
+
99
+ ### What's the difference between the edge functions?
100
+ The library provides a tiered set of functions for different needs:
101
+
102
+ - edge(): The core function. It's fast, robust, and computes a single spread estimate for a given sample of data. This is the building block for all other functions.
103
+ - edge_hft(): A specialized version of edge() for HFT users. It's the fastest possible implementation but requires perfectly clean input data (no NaNs) to achieve its speed.
104
+ - edge_rolling(): Computes the spread on a rolling window over a time series. It's perfect for seeing how the spread evolves over time. It is highly optimized and accepts all arguments from pandas.DataFrame.rolling() (like window and step).
105
+ - edge_expanding(): Computes the spread on an expanding (cumulative) window. This is useful for analyzing how the spread estimate converges or changes as more data becomes available.
106
+
107
+ ### What is the minimum number of observations?
108
+ At least 3 valid observations are required.
109
+
110
+ ### How should I choose the window size or frequency?
111
+ Short windows (e.g. a few days) reflect local spread conditions but may be noisy. Longer windows (e.g. 1 year) reduce variance but smooth over changes. For intraday use, minute-level frequency is recommended if the asset trades frequently.
112
+
113
+ Rule of thumb: ensure on average ≥2 trades per interval.
114
+
115
+ ### Can I use intraday or tick data?
116
+ Yes — the estimator supports intraday OHLC data directly. For tick data, resample into OHLC format first (e.g., using pandas.resample).
117
+
118
+ ### What if I get NaN results?
119
+ The estimator may return NaN if:
120
+
121
+ - Input prices are inconsistent (e.g. high < low)
122
+ - There are too many missing or invalid values
123
+ - Probability thresholds are not met (e.g. insufficient variance in prices)
124
+ - Spread variance is non-positive
125
+
126
+ In these cases, re-examine your input or adjust the sampling frequency.
127
+
65
128
  ## Installation
66
129
 
67
130
  Install the library via pip:
@@ -123,9 +186,9 @@ from quantjourney_bidask import edge_rolling
123
186
  import asyncio
124
187
 
125
188
  # Fetch stock data
126
- stock_df = get_stock_data("AAPL", period="1mo", interval="1d")
189
+ stock_df = get_stock_data("PL", period="1mo", interval="1d")
127
190
  stock_spreads = edge_rolling(stock_df, window=20)
128
- print(f"AAPL average spread: {stock_spreads.mean():.6f}")
191
+ print(f"PL average spread: {stock_spreads.mean():.6f}")
129
192
 
130
193
  # Fetch crypto data (async)
131
194
  async def get_crypto_spreads():
@@ -178,10 +241,13 @@ monitor.start_monitoring("1m")
178
241
 
179
242
  ```python
180
243
  # Run the real-time dashboard
181
- python examples/realtime_spread_monitor.py --mode dashboard
244
+ python examples/websocket_realtime_demo.py --mode dashboard
245
+
246
+ # Or console mode
247
+ python examples/websocket_realtime_demo.py --mode console
182
248
 
183
- # Or console mode
184
- python examples/realtime_spread_monitor.py --mode console
249
+ # Quick 30-second BTC websocket demo
250
+ python examples/animated_spread_monitor.py
185
251
  ```
186
252
 
187
253
  ## Project Structure
@@ -190,42 +256,32 @@ python examples/realtime_spread_monitor.py --mode console
190
256
  quantjourney_bidask/
191
257
  ├── quantjourney_bidask/ # Main library code
192
258
  │ ├── __init__.py
193
- │ ├── edge.py # Core EDGE estimator
259
+ │ ├── edge.py # Core EDGE estimator
260
+ │ ├── edge_hft.py # EDGE estimator optimised HFT-version
194
261
  │ ├── edge_rolling.py # Rolling window estimation
195
262
  │ └── edge_expanding.py # Expanding window estimation
196
263
  ├── data/
197
264
  │ └── fetch.py # Simplified data fetcher for examples
198
265
  ├── examples/ # Comprehensive usage examples
199
266
  │ ├── simple_data_example.py # Basic usage demonstration
200
- │ ├── spread_estimator.py # Spread estimation examples
267
+ │ ├── basic_spread_estimation.py # Core spread estimation examples
201
268
  │ ├── animated_spread_monitor.py # Animated visualizations
202
269
  │ ├── crypto_spread_comparison.py # Crypto spread analysis
203
270
  │ ├── liquidity_risk_monitor.py # Risk monitoring
204
- │ ├── realtime_spread_monitor.py # Live monitoring dashboard
205
- │ └── stock_liquidity_risk.py # Stock liquidity analysis
271
+ │ ├── websocket_realtime_demo.py # Live websocket monitoring demo
272
+ │ └── threshold_alert_monitor.py # Threshold-based spread alerts
206
273
  ├── tests/ # Unit tests (GitHub only)
207
274
  │ ├── test_edge.py
208
275
  │ ├── test_edge_rolling.py
276
+ │ └── test_edge_expanding.py
209
277
  │ └── test_data_fetcher.py
278
+ │ └── test_estimators.py
210
279
  └── _output/ # Example output images
211
280
  ├── simple_data_example.png
212
281
  ├── crypto_spread_comparison.png
213
282
  └── spread_estimator_results.png
214
283
  ```
215
284
 
216
- ## Examples and Visualizations
217
-
218
- The package includes comprehensive examples with beautiful visualizations:
219
-
220
- ### Basic Data Analysis
221
- ![Crypto Spread Analysis](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/ad49bd78c82ab1c44561d0f2e707ae304575a147/_output/crypto_spread_comprehensive_analysis.png)
222
-
223
- ### Crypto Spread Comparison
224
- ![Crypto Spread Comparison](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/refs/heads/main/_output/crypto_spread_comparison.png)
225
-
226
- ### Spread Estimation Results
227
- ![Spread Estimator Results](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/refs/heads/main/_output/spread_estimator_results.png)
228
-
229
285
  ### Running Examples
230
286
 
231
287
  After installing via pip, examples are included in the package:
@@ -250,19 +306,20 @@ Or clone the repository for full access to examples and tests:
250
306
  git clone https://github.com/QuantJourneyOrg/qj_bidask
251
307
  cd qj_bidask
252
308
  python examples/simple_data_example.py
253
- python examples/spread_estimator.py
309
+ python examples/basic_spread_estimation.py
310
+ python examples/animated_spread_monitor.py # 30s real BTC websocket demo
254
311
  python examples/crypto_spread_comparison.py
255
312
  ```
256
313
 
257
314
  ### Available Examples
258
315
 
259
316
  - **`simple_data_example.py`** - Basic usage with stock and crypto data
260
- - **`spread_estimator.py`** - Core spread estimation functionality
261
- - **`animated_spread_monitor.py`** - Real-time animated visualizations
262
- - **`crypto_spread_comparison.py`** - Multi-asset crypto analysis
317
+ - **`basic_spread_estimation.py`** - Core spread estimation functionality
318
+ - **`animated_spread_monitor.py`** - Real-time animated visualizations with 30s websocket demo
319
+ - **`crypto_spread_comparison.py`** - Multi-asset crypto analysis and comparison
263
320
  - **`liquidity_risk_monitor.py`** - Risk monitoring and alerts
264
- - **`realtime_spread_monitor.py`** - Live websocket monitoring dashboard
265
- - **`stock_liquidity_risk.py`** - Stock-specific liquidity analysis
321
+ - **`websocket_realtime_demo.py`** - Live websocket monitoring dashboard
322
+ - **`threshold_alert_monitor.py`** - Threshold-based spread alerts and monitoring
266
323
 
267
324
  ## Testing and Development
268
325
 
@@ -297,7 +354,8 @@ python -m pytest tests/test_data_fetcher.py -v
297
354
 
298
355
  # Run examples
299
356
  python examples/simple_data_example.py
300
- python examples/spread_estimator.py
357
+ python examples/basic_spread_estimation.py
358
+ python examples/animated_spread_monitor.py # Real BTC websocket demo
301
359
  ```
302
360
 
303
361
  ### Package vs Repository
@@ -370,7 +428,8 @@ pip install -e ".[dev]"
370
428
  pytest
371
429
 
372
430
  # Run examples
373
- python examples/realtime_spread_monitor.py
431
+ python examples/animated_spread_monitor.py # 30s real BTC websocket demo
432
+ python examples/websocket_realtime_demo.py # Full dashboard
374
433
  ```
375
434
 
376
435
  ## Support
@@ -1,8 +1,12 @@
1
1
  # QuantJourney Bid-Ask Spread Estimator
2
2
 
3
- ![PyPI](https://img.shields.io/pypi/v/quantjourney-bidask)
4
- ![License](https://img.shields.io/github/license/quantjourney/bidask)
5
- ![Tests](https://img.shields.io/github/workflow/status/quantjourney/bidask/Test)
3
+ ![Build Status](https://github.com/QuantJourneyOrg/qj_bidask/actions/workflows/test.yml/badge.svg)
4
+ [![PyPi Version](https://img.shields.io/pypi/v/quantjourney-bidask.svg)](https://pypi.org/project/quantjourney-bidask/)
5
+ [![Python Versions](https://img.shields.io/pypi/pyversions/quantjourney-bidask.svg)](https://pypi.org/project/quantjourney-bidask/)
6
+ [![Downloads](https://pepy.tech/badge/quantjourney-bidask)](https://pepy.tech/project/quantjourney-bidask)
7
+ [![License](https://img.shields.io/github/license/QuantJourneyOrg/qj_bidask.svg)](https://github.com/QuantJourneyOrg/qj_bidask/blob/main/LICENSE)
8
+ [![GitHub Stars](https://img.shields.io/github/stars/QuantJourneyOrg/qj_bidask?style=social)](https://github.com/QuantJourneyOrg/qj_bidask)
9
+
6
10
 
7
11
  The `quantjourney-bidask` library provides an efficient estimator for calculating bid-ask spreads from open, high, low, and close (OHLC) prices, based on the methodology described in:
8
12
 
@@ -10,6 +14,8 @@ The `quantjourney-bidask` library provides an efficient estimator for calculatin
10
14
 
11
15
  This library is designed for quantitative finance professionals, researchers, and traders who need accurate and computationally efficient spread estimates for equities, cryptocurrencies, and other assets.
12
16
 
17
+ 🚀 **Part of the [QuantJourney](https://quantjourney.substack.com/) ecosystem** - The framework with advanced quantitative finance tools and insights!
18
+
13
19
  ## Features
14
20
 
15
21
  - **Efficient Spread Estimation**: Implements the EDGE estimator for single, rolling, and expanding windows.
@@ -21,6 +27,61 @@ This library is designed for quantitative finance professionals, researchers, an
21
27
  - **Comprehensive Tests**: Extensive unit tests with known test cases from the original paper.
22
28
  - **Clear Documentation**: Detailed docstrings and usage examples.
23
29
 
30
+ ## Examples and Visualizations
31
+
32
+ The package includes comprehensive examples with beautiful visualizations:
33
+
34
+ ### Spread Monitor Results
35
+ ![Spread Monitor](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/refs/heads/main/_output/spread_monitor_results.png)
36
+
37
+ ### Basic Data Analysis
38
+ ![Crypto Spread Analysis](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/ad49bd78c82ab1c44561d0f2e707ae304575a147/_output/crypto_spread_comprehensive_analysis.png)
39
+
40
+ ### Crypto Spread Comparison
41
+ ![Crypto Spread Comparison](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/refs/heads/main/_output/crypto_spread_comparison.png)
42
+
43
+ ## FAQ
44
+
45
+ ### What exactly does the estimator compute?
46
+ The estimator returns the root mean square effective spread over the sample period. This quantifies the average transaction cost implied by bid-ask spreads, based on open, high, low, and close (OHLC) prices.
47
+
48
+ ### What is unique about this implementation?
49
+ This package provides a highly optimized and robust implementation of the EDGE estimator. Beyond a direct translation of the paper's formula, it features:
50
+
51
+ - A Hybrid, High-Performance Engine: The core logic leverages fast, vectorized NumPy operations for data preparation and calls a specialized, JIT-compiled kernel via Numba for the computationally intensive GMM calculations.
52
+ - HFT-Ready Version (edge_hft.py): An included, hyper-optimized function that uses fastmath compilation for the absolute lowest latency, designed for production HFT pipelines where every microsecond matters.
53
+ - Robust Data Handling: Gracefully manages missing values (NaN) and non-positive prices to prevent crashes.
54
+ - Advanced Windowing Functions: Efficient and correct edge_rolling and edge_expanding functions that are fully compatible with the powerful features of pandas, including custom step sizes.
55
+
56
+ ### What's the difference between the edge functions?
57
+ The library provides a tiered set of functions for different needs:
58
+
59
+ - edge(): The core function. It's fast, robust, and computes a single spread estimate for a given sample of data. This is the building block for all other functions.
60
+ - edge_hft(): A specialized version of edge() for HFT users. It's the fastest possible implementation but requires perfectly clean input data (no NaNs) to achieve its speed.
61
+ - edge_rolling(): Computes the spread on a rolling window over a time series. It's perfect for seeing how the spread evolves over time. It is highly optimized and accepts all arguments from pandas.DataFrame.rolling() (like window and step).
62
+ - edge_expanding(): Computes the spread on an expanding (cumulative) window. This is useful for analyzing how the spread estimate converges or changes as more data becomes available.
63
+
64
+ ### What is the minimum number of observations?
65
+ At least 3 valid observations are required.
66
+
67
+ ### How should I choose the window size or frequency?
68
+ Short windows (e.g. a few days) reflect local spread conditions but may be noisy. Longer windows (e.g. 1 year) reduce variance but smooth over changes. For intraday use, minute-level frequency is recommended if the asset trades frequently.
69
+
70
+ Rule of thumb: ensure on average ≥2 trades per interval.
71
+
72
+ ### Can I use intraday or tick data?
73
+ Yes — the estimator supports intraday OHLC data directly. For tick data, resample into OHLC format first (e.g., using pandas.resample).
74
+
75
+ ### What if I get NaN results?
76
+ The estimator may return NaN if:
77
+
78
+ - Input prices are inconsistent (e.g. high < low)
79
+ - There are too many missing or invalid values
80
+ - Probability thresholds are not met (e.g. insufficient variance in prices)
81
+ - Spread variance is non-positive
82
+
83
+ In these cases, re-examine your input or adjust the sampling frequency.
84
+
24
85
  ## Installation
25
86
 
26
87
  Install the library via pip:
@@ -82,9 +143,9 @@ from quantjourney_bidask import edge_rolling
82
143
  import asyncio
83
144
 
84
145
  # Fetch stock data
85
- stock_df = get_stock_data("AAPL", period="1mo", interval="1d")
146
+ stock_df = get_stock_data("PL", period="1mo", interval="1d")
86
147
  stock_spreads = edge_rolling(stock_df, window=20)
87
- print(f"AAPL average spread: {stock_spreads.mean():.6f}")
148
+ print(f"PL average spread: {stock_spreads.mean():.6f}")
88
149
 
89
150
  # Fetch crypto data (async)
90
151
  async def get_crypto_spreads():
@@ -137,10 +198,13 @@ monitor.start_monitoring("1m")
137
198
 
138
199
  ```python
139
200
  # Run the real-time dashboard
140
- python examples/realtime_spread_monitor.py --mode dashboard
201
+ python examples/websocket_realtime_demo.py --mode dashboard
202
+
203
+ # Or console mode
204
+ python examples/websocket_realtime_demo.py --mode console
141
205
 
142
- # Or console mode
143
- python examples/realtime_spread_monitor.py --mode console
206
+ # Quick 30-second BTC websocket demo
207
+ python examples/animated_spread_monitor.py
144
208
  ```
145
209
 
146
210
  ## Project Structure
@@ -149,42 +213,32 @@ python examples/realtime_spread_monitor.py --mode console
149
213
  quantjourney_bidask/
150
214
  ├── quantjourney_bidask/ # Main library code
151
215
  │ ├── __init__.py
152
- │ ├── edge.py # Core EDGE estimator
216
+ │ ├── edge.py # Core EDGE estimator
217
+ │ ├── edge_hft.py # EDGE estimator optimised HFT-version
153
218
  │ ├── edge_rolling.py # Rolling window estimation
154
219
  │ └── edge_expanding.py # Expanding window estimation
155
220
  ├── data/
156
221
  │ └── fetch.py # Simplified data fetcher for examples
157
222
  ├── examples/ # Comprehensive usage examples
158
223
  │ ├── simple_data_example.py # Basic usage demonstration
159
- │ ├── spread_estimator.py # Spread estimation examples
224
+ │ ├── basic_spread_estimation.py # Core spread estimation examples
160
225
  │ ├── animated_spread_monitor.py # Animated visualizations
161
226
  │ ├── crypto_spread_comparison.py # Crypto spread analysis
162
227
  │ ├── liquidity_risk_monitor.py # Risk monitoring
163
- │ ├── realtime_spread_monitor.py # Live monitoring dashboard
164
- │ └── stock_liquidity_risk.py # Stock liquidity analysis
228
+ │ ├── websocket_realtime_demo.py # Live websocket monitoring demo
229
+ │ └── threshold_alert_monitor.py # Threshold-based spread alerts
165
230
  ├── tests/ # Unit tests (GitHub only)
166
231
  │ ├── test_edge.py
167
232
  │ ├── test_edge_rolling.py
233
+ │ └── test_edge_expanding.py
168
234
  │ └── test_data_fetcher.py
235
+ │ └── test_estimators.py
169
236
  └── _output/ # Example output images
170
237
  ├── simple_data_example.png
171
238
  ├── crypto_spread_comparison.png
172
239
  └── spread_estimator_results.png
173
240
  ```
174
241
 
175
- ## Examples and Visualizations
176
-
177
- The package includes comprehensive examples with beautiful visualizations:
178
-
179
- ### Basic Data Analysis
180
- ![Crypto Spread Analysis](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/ad49bd78c82ab1c44561d0f2e707ae304575a147/_output/crypto_spread_comprehensive_analysis.png)
181
-
182
- ### Crypto Spread Comparison
183
- ![Crypto Spread Comparison](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/refs/heads/main/_output/crypto_spread_comparison.png)
184
-
185
- ### Spread Estimation Results
186
- ![Spread Estimator Results](https://raw.githubusercontent.com/QuantJourneyOrg/qj_bidask/refs/heads/main/_output/spread_estimator_results.png)
187
-
188
242
  ### Running Examples
189
243
 
190
244
  After installing via pip, examples are included in the package:
@@ -209,19 +263,20 @@ Or clone the repository for full access to examples and tests:
209
263
  git clone https://github.com/QuantJourneyOrg/qj_bidask
210
264
  cd qj_bidask
211
265
  python examples/simple_data_example.py
212
- python examples/spread_estimator.py
266
+ python examples/basic_spread_estimation.py
267
+ python examples/animated_spread_monitor.py # 30s real BTC websocket demo
213
268
  python examples/crypto_spread_comparison.py
214
269
  ```
215
270
 
216
271
  ### Available Examples
217
272
 
218
273
  - **`simple_data_example.py`** - Basic usage with stock and crypto data
219
- - **`spread_estimator.py`** - Core spread estimation functionality
220
- - **`animated_spread_monitor.py`** - Real-time animated visualizations
221
- - **`crypto_spread_comparison.py`** - Multi-asset crypto analysis
274
+ - **`basic_spread_estimation.py`** - Core spread estimation functionality
275
+ - **`animated_spread_monitor.py`** - Real-time animated visualizations with 30s websocket demo
276
+ - **`crypto_spread_comparison.py`** - Multi-asset crypto analysis and comparison
222
277
  - **`liquidity_risk_monitor.py`** - Risk monitoring and alerts
223
- - **`realtime_spread_monitor.py`** - Live websocket monitoring dashboard
224
- - **`stock_liquidity_risk.py`** - Stock-specific liquidity analysis
278
+ - **`websocket_realtime_demo.py`** - Live websocket monitoring dashboard
279
+ - **`threshold_alert_monitor.py`** - Threshold-based spread alerts and monitoring
225
280
 
226
281
  ## Testing and Development
227
282
 
@@ -256,7 +311,8 @@ python -m pytest tests/test_data_fetcher.py -v
256
311
 
257
312
  # Run examples
258
313
  python examples/simple_data_example.py
259
- python examples/spread_estimator.py
314
+ python examples/basic_spread_estimation.py
315
+ python examples/animated_spread_monitor.py # Real BTC websocket demo
260
316
  ```
261
317
 
262
318
  ### Package vs Repository
@@ -329,7 +385,8 @@ pip install -e ".[dev]"
329
385
  pytest
330
386
 
331
387
  # Run examples
332
- python examples/realtime_spread_monitor.py
388
+ python examples/animated_spread_monitor.py # 30s real BTC websocket demo
389
+ python examples/websocket_realtime_demo.py # Full dashboard
333
390
  ```
334
391
 
335
392
  ## Support