quantjourney-bidask 0.5.0__py3-none-any.whl → 0.9.0__py3-none-any.whl
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.
- quantjourney_bidask/_version.py +3 -3
- quantjourney_bidask-0.9.0.dist-info/METADATA +396 -0
- {quantjourney_bidask-0.5.0.dist-info → quantjourney_bidask-0.9.0.dist-info}/RECORD +6 -6
- {quantjourney_bidask-0.5.0.dist-info → quantjourney_bidask-0.9.0.dist-info}/licenses/LICENSE +1 -1
- quantjourney_bidask-0.5.0.dist-info/METADATA +0 -183
- {quantjourney_bidask-0.5.0.dist-info → quantjourney_bidask-0.9.0.dist-info}/WHEEL +0 -0
- {quantjourney_bidask-0.5.0.dist-info → quantjourney_bidask-0.9.0.dist-info}/top_level.txt +0 -0
quantjourney_bidask/_version.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"""Version information for quantjourney_bidask."""
|
2
2
|
|
3
|
-
__version__ = "0.
|
3
|
+
__version__ = "0.9.0"
|
4
4
|
__author__ = "Jakub Polec"
|
5
5
|
__email__ = "jakub@quantjourney.pro"
|
6
|
-
__license__ = "
|
7
|
-
__copyright__ = "Copyright (c)
|
6
|
+
__license__ = "MIT"
|
7
|
+
__copyright__ = "Copyright (c) 2025 Jakub Polec, QuantJourney"
|
@@ -0,0 +1,396 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: quantjourney-bidask
|
3
|
+
Version: 0.9.0
|
4
|
+
Summary: Efficient bid-ask spread estimator from OHLC prices
|
5
|
+
Author-email: Jakub Polec <jakub@quantjourney.pro>
|
6
|
+
License-Expression: MIT
|
7
|
+
Project-URL: Homepage, https://github.com/QuantJourneyOrg/qj_bidask
|
8
|
+
Project-URL: Repository, https://github.com/QuantJourneyOrg/qj_bidask
|
9
|
+
Project-URL: Bug Tracker, https://github.com/QuantJourneyOrg/qj_bidask/issues
|
10
|
+
Keywords: finance,bid-ask,spread,trading,quantitative,OHLC
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
12
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
13
|
+
Classifier: Operating System :: OS Independent
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
17
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
19
|
+
Requires-Python: <3.15,>=3.11
|
20
|
+
Description-Content-Type: text/markdown
|
21
|
+
License-File: LICENSE
|
22
|
+
Requires-Dist: numpy>=1.20
|
23
|
+
Requires-Dist: pandas>=1.5
|
24
|
+
Requires-Dist: requests>=2.28
|
25
|
+
Requires-Dist: yfinance>=0.2
|
26
|
+
Requires-Dist: matplotlib>=3.5
|
27
|
+
Requires-Dist: plotly>=5.0
|
28
|
+
Requires-Dist: websocket-client>=1.0
|
29
|
+
Provides-Extra: dev
|
30
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
31
|
+
Requires-Dist: pytest-mock>=3.10; extra == "dev"
|
32
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
33
|
+
Requires-Dist: ruff>=0.1; extra == "dev"
|
34
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
35
|
+
Requires-Dist: black>=22.0; extra == "dev"
|
36
|
+
Requires-Dist: isort>=5.0; extra == "dev"
|
37
|
+
Provides-Extra: examples
|
38
|
+
Requires-Dist: jupyter>=1.0; extra == "examples"
|
39
|
+
Requires-Dist: ipywidgets>=7.0; extra == "examples"
|
40
|
+
Dynamic: license-file
|
41
|
+
|
42
|
+
# QuantJourney Bid-Ask Spread Estimator
|
43
|
+
|
44
|
+

|
45
|
+

|
46
|
+

|
47
|
+
|
48
|
+
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
|
+
|
50
|
+
> Ardia, D., Guidotti, E., Kroencke, T.A. (2024). Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices. *Journal of Financial Economics*, 161, 103916. [doi:10.1016/j.jfineco.2024.103916](https://doi.org/10.1016/j.jfineco.2024.103916)
|
51
|
+
|
52
|
+
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
|
+
|
54
|
+
## Features
|
55
|
+
|
56
|
+
- **Efficient Spread Estimation**: Implements the EDGE estimator for single, rolling, and expanding windows.
|
57
|
+
- **Real-Time Data**: Websocket support for live cryptocurrency data from Binance and other exchanges.
|
58
|
+
- **Data Integration**: Fetch OHLC data from Yahoo Finance and generate synthetic data for testing.
|
59
|
+
- **Live Monitoring**: Real-time spread monitoring with animated visualizations.
|
60
|
+
- **Local Development**: Works completely locally without cloud dependencies.
|
61
|
+
- **Robust Handling**: Supports missing values, non-positive prices, and various data frequencies.
|
62
|
+
- **Comprehensive Tests**: Extensive unit tests with known test cases from the original paper.
|
63
|
+
- **Clear Documentation**: Detailed docstrings and usage examples.
|
64
|
+
|
65
|
+
## Installation
|
66
|
+
|
67
|
+
Install the library via pip:
|
68
|
+
|
69
|
+
```bash
|
70
|
+
pip install quantjourney-bidask
|
71
|
+
```
|
72
|
+
|
73
|
+
For development (local setup):
|
74
|
+
|
75
|
+
```bash
|
76
|
+
git clone https://github.com/QuantJourneyOrg/qj_bidask
|
77
|
+
cd qj_bidask
|
78
|
+
pip install -e .
|
79
|
+
```
|
80
|
+
|
81
|
+
## Quick Start
|
82
|
+
|
83
|
+
### Basic Usage
|
84
|
+
|
85
|
+
```python
|
86
|
+
from quantjourney_bidask import edge
|
87
|
+
|
88
|
+
# Example OHLC data (as lists or numpy arrays)
|
89
|
+
open_prices = [100.0, 101.5, 99.8, 102.1, 100.9]
|
90
|
+
high_prices = [102.3, 103.0, 101.2, 103.5, 102.0]
|
91
|
+
low_prices = [99.5, 100.8, 98.9, 101.0, 100.1]
|
92
|
+
close_prices = [101.2, 100.2, 101.8, 100.5, 101.5]
|
93
|
+
|
94
|
+
# Calculate bid-ask spread
|
95
|
+
spread = edge(open_prices, high_prices, low_prices, close_prices)
|
96
|
+
print(f"Estimated bid-ask spread: {spread:.6f}")
|
97
|
+
```
|
98
|
+
|
99
|
+
### Rolling Window Analysis
|
100
|
+
|
101
|
+
```python
|
102
|
+
from quantjourney_bidask import edge_rolling
|
103
|
+
import pandas as pd
|
104
|
+
|
105
|
+
# Create DataFrame with OHLC data
|
106
|
+
df = pd.DataFrame({
|
107
|
+
'open': open_prices,
|
108
|
+
'high': high_prices,
|
109
|
+
'low': low_prices,
|
110
|
+
'close': close_prices
|
111
|
+
})
|
112
|
+
|
113
|
+
# Calculate rolling spreads with a 20-period window
|
114
|
+
rolling_spreads = edge_rolling(df, window=20)
|
115
|
+
print(f"Rolling spreads: {rolling_spreads}")
|
116
|
+
```
|
117
|
+
|
118
|
+
### Data Fetching Integration
|
119
|
+
|
120
|
+
```python
|
121
|
+
from data.fetch import get_stock_data, get_crypto_data
|
122
|
+
from quantjourney_bidask import edge_rolling
|
123
|
+
import asyncio
|
124
|
+
|
125
|
+
# Fetch stock data
|
126
|
+
stock_df = get_stock_data("AAPL", period="1mo", interval="1d")
|
127
|
+
stock_spreads = edge_rolling(stock_df, window=20)
|
128
|
+
print(f"AAPL average spread: {stock_spreads.mean():.6f}")
|
129
|
+
|
130
|
+
# Fetch crypto data (async)
|
131
|
+
async def get_crypto_spreads():
|
132
|
+
crypto_df = await get_crypto_data("BTC/USDT", "binance", "1h", 168)
|
133
|
+
crypto_spreads = edge_rolling(crypto_df, window=24)
|
134
|
+
return crypto_spreads.mean()
|
135
|
+
|
136
|
+
crypto_avg_spread = asyncio.run(get_crypto_spreads())
|
137
|
+
print(f"BTC average spread: {crypto_avg_spread:.6f}")
|
138
|
+
```
|
139
|
+
|
140
|
+
### Real-time Data Streaming
|
141
|
+
|
142
|
+
```python
|
143
|
+
from data.fetch import DataFetcher
|
144
|
+
import asyncio
|
145
|
+
|
146
|
+
async def stream_btc_spreads():
|
147
|
+
fetcher = DataFetcher()
|
148
|
+
# Stream BTC data for 60 seconds
|
149
|
+
btc_stream = await fetcher.get_btc_1m_websocket(duration_seconds=60)
|
150
|
+
|
151
|
+
# Calculate spread from real-time data
|
152
|
+
if not btc_stream.empty:
|
153
|
+
avg_spread_pct = (btc_stream['spread'] / btc_stream['price']).mean() * 100
|
154
|
+
print(f"Real-time BTC average spread: {avg_spread_pct:.4f}%")
|
155
|
+
|
156
|
+
asyncio.run(stream_btc_spreads())
|
157
|
+
```
|
158
|
+
|
159
|
+
### Real-Time Spread Monitoring
|
160
|
+
|
161
|
+
```python
|
162
|
+
from data.fetch import create_spread_monitor
|
163
|
+
|
164
|
+
# Create real-time spread monitor
|
165
|
+
monitor = create_spread_monitor(["BTCUSDT", "ETHUSDT"], window=20)
|
166
|
+
|
167
|
+
# Add callback for spread updates
|
168
|
+
def print_spread_update(spread_data):
|
169
|
+
print(f"{spread_data['symbol']}: {spread_data['spread_bps']:.2f} bps")
|
170
|
+
|
171
|
+
monitor.add_spread_callback(print_spread_update)
|
172
|
+
|
173
|
+
# Start monitoring (uses websockets for live data)
|
174
|
+
monitor.start_monitoring("1m")
|
175
|
+
```
|
176
|
+
|
177
|
+
### Animated Real-Time Dashboard
|
178
|
+
|
179
|
+
```python
|
180
|
+
# Run the real-time dashboard
|
181
|
+
python examples/realtime_spread_monitor.py --mode dashboard
|
182
|
+
|
183
|
+
# Or console mode
|
184
|
+
python examples/realtime_spread_monitor.py --mode console
|
185
|
+
```
|
186
|
+
|
187
|
+
## Project Structure
|
188
|
+
|
189
|
+
```
|
190
|
+
quantjourney_bidask/
|
191
|
+
├── quantjourney_bidask/ # Main library code
|
192
|
+
│ ├── __init__.py
|
193
|
+
│ ├── edge.py # Core EDGE estimator
|
194
|
+
│ ├── edge_rolling.py # Rolling window estimation
|
195
|
+
│ └── edge_expanding.py # Expanding window estimation
|
196
|
+
├── data/
|
197
|
+
│ └── fetch.py # Simplified data fetcher for examples
|
198
|
+
├── examples/ # Comprehensive usage examples
|
199
|
+
│ ├── simple_data_example.py # Basic usage demonstration
|
200
|
+
│ ├── spread_estimator.py # Spread estimation examples
|
201
|
+
│ ├── animated_spread_monitor.py # Animated visualizations
|
202
|
+
│ ├── crypto_spread_comparison.py # Crypto spread analysis
|
203
|
+
│ ├── liquidity_risk_monitor.py # Risk monitoring
|
204
|
+
│ ├── realtime_spread_monitor.py # Live monitoring dashboard
|
205
|
+
│ └── stock_liquidity_risk.py # Stock liquidity analysis
|
206
|
+
├── tests/ # Unit tests (GitHub only)
|
207
|
+
│ ├── test_edge.py
|
208
|
+
│ ├── test_edge_rolling.py
|
209
|
+
│ └── test_data_fetcher.py
|
210
|
+
└── _output/ # Example output images
|
211
|
+
├── simple_data_example.png
|
212
|
+
├── crypto_spread_comparison.png
|
213
|
+
└── spread_estimator_results.png
|
214
|
+
```
|
215
|
+
|
216
|
+
## Examples and Visualizations
|
217
|
+
|
218
|
+
The package includes comprehensive examples with beautiful visualizations:
|
219
|
+
|
220
|
+
### Basic Data Analysis
|
221
|
+

|
222
|
+
|
223
|
+
### Crypto Spread Comparison
|
224
|
+

|
225
|
+
|
226
|
+
### Spread Estimation Results
|
227
|
+

|
228
|
+
|
229
|
+
### Running Examples
|
230
|
+
|
231
|
+
After installing via pip, examples are included in the package:
|
232
|
+
|
233
|
+
```python
|
234
|
+
import quantjourney_bidask
|
235
|
+
from pathlib import Path
|
236
|
+
|
237
|
+
# Find package location
|
238
|
+
pkg_path = Path(quantjourney_bidask.__file__).parent
|
239
|
+
examples_path = pkg_path.parent / 'examples'
|
240
|
+
print(f"Examples located at: {examples_path}")
|
241
|
+
|
242
|
+
# List available examples
|
243
|
+
for example in examples_path.glob('*.py'):
|
244
|
+
print(f"📄 {example.name}")
|
245
|
+
```
|
246
|
+
|
247
|
+
Or clone the repository for full access to examples and tests:
|
248
|
+
|
249
|
+
```bash
|
250
|
+
git clone https://github.com/QuantJourneyOrg/qj_bidask
|
251
|
+
cd qj_bidask
|
252
|
+
python examples/simple_data_example.py
|
253
|
+
python examples/spread_estimator.py
|
254
|
+
python examples/crypto_spread_comparison.py
|
255
|
+
```
|
256
|
+
|
257
|
+
### Available Examples
|
258
|
+
|
259
|
+
- **`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
|
263
|
+
- **`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
|
266
|
+
|
267
|
+
## Testing and Development
|
268
|
+
|
269
|
+
### Unit Tests
|
270
|
+
The package includes comprehensive unit tests (available in the GitHub repository):
|
271
|
+
|
272
|
+
- **`test_edge.py`** - Core EDGE estimator tests with known values from the academic paper
|
273
|
+
- **`test_edge_rolling.py`** - Rolling window estimation tests
|
274
|
+
- **`test_edge_expanding.py`** - Expanding window estimation tests
|
275
|
+
- **`test_data_fetcher.py`** - Data fetching functionality tests
|
276
|
+
- **`test_estimators.py`** - Integration tests for all estimators
|
277
|
+
|
278
|
+
Tests verify accuracy against the original paper's test cases and handle edge cases like missing data, non-positive prices, and various market conditions.
|
279
|
+
|
280
|
+
### Development and Testing
|
281
|
+
For full development access including tests:
|
282
|
+
|
283
|
+
```bash
|
284
|
+
# Clone the repository
|
285
|
+
git clone https://github.com/QuantJourneyOrg/qj_bidask
|
286
|
+
cd qj_bidask
|
287
|
+
|
288
|
+
# Install in development mode
|
289
|
+
pip install -e .
|
290
|
+
|
291
|
+
# Run tests
|
292
|
+
python -m pytest tests/ -v
|
293
|
+
|
294
|
+
# Run specific test files
|
295
|
+
python -m pytest tests/test_edge.py -v
|
296
|
+
python -m pytest tests/test_data_fetcher.py -v
|
297
|
+
|
298
|
+
# Run examples
|
299
|
+
python examples/simple_data_example.py
|
300
|
+
python examples/spread_estimator.py
|
301
|
+
```
|
302
|
+
|
303
|
+
### Package vs Repository
|
304
|
+
- **PyPI Package** (`pip install quantjourney-bidask`): Includes core library, examples, and documentation
|
305
|
+
- **GitHub Repository**: Full development environment with tests, development tools, and additional documentation
|
306
|
+
|
307
|
+
## API Reference
|
308
|
+
|
309
|
+
### Core Functions
|
310
|
+
|
311
|
+
- `edge(open, high, low, close, sign=False)`: Single-period spread estimation
|
312
|
+
- `edge_rolling(df, window, min_periods=None)`: Rolling window estimation
|
313
|
+
- `edge_expanding(df, min_periods=3)`: Expanding window estimation
|
314
|
+
|
315
|
+
### Data Fetching (`data/fetch.py`)
|
316
|
+
|
317
|
+
- `DataFetcher()`: Main data fetcher class
|
318
|
+
- `get_stock_data(ticker, period, interval)`: Fetch stock data from Yahoo Finance
|
319
|
+
- `get_crypto_data(symbol, exchange, timeframe, limit)`: Fetch crypto data via CCXT (async)
|
320
|
+
- `stream_btc_data(duration_seconds)`: Stream BTC data via websocket (async)
|
321
|
+
- `DataFetcher.get_btc_1m_websocket()`: Stream BTC 1-minute data
|
322
|
+
- `DataFetcher.get_historical_crypto_data()`: Get historical crypto OHLCV data
|
323
|
+
- `DataFetcher.save_data()` / `DataFetcher.load_data()`: Save/load data to CSV
|
324
|
+
|
325
|
+
### Real-Time Classes
|
326
|
+
|
327
|
+
- `RealTimeDataStream`: Websocket data streaming for live market data
|
328
|
+
- `RealTimeSpreadMonitor`: Real-time spread calculation and monitoring
|
329
|
+
- `AnimatedSpreadMonitor`: Animated real-time visualization
|
330
|
+
|
331
|
+
## Requirements
|
332
|
+
|
333
|
+
- Python >= 3.11
|
334
|
+
- numpy >= 1.20
|
335
|
+
- pandas >= 1.5
|
336
|
+
- requests >= 2.28
|
337
|
+
- yfinance >= 0.2
|
338
|
+
- matplotlib >= 3.5
|
339
|
+
- websocket-client >= 1.0
|
340
|
+
|
341
|
+
## WebSocket Support
|
342
|
+
|
343
|
+
The library supports real-time data via websockets:
|
344
|
+
|
345
|
+
- **Binance**: `wss://stream.binance.com:9443/ws/` (cryptocurrency data)
|
346
|
+
- **Fallback**: Synthetic data generation for testing when websockets unavailable
|
347
|
+
|
348
|
+
Real-time features:
|
349
|
+
- Live spread calculation
|
350
|
+
- Animated visualizations
|
351
|
+
- Threshold alerts
|
352
|
+
- Multi-symbol monitoring
|
353
|
+
|
354
|
+
## Academic Citation
|
355
|
+
|
356
|
+
If you use this library in academic research, please cite:
|
357
|
+
|
358
|
+
```bibtex
|
359
|
+
@article{ardia2024efficient,
|
360
|
+
title={Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices},
|
361
|
+
author={Ardia, David and Guidotti, Emanuele and Kroencke, Tim A},
|
362
|
+
journal={Journal of Financial Economics},
|
363
|
+
volume={161},
|
364
|
+
pages={103916},
|
365
|
+
year={2024},
|
366
|
+
publisher={Elsevier}
|
367
|
+
}
|
368
|
+
```
|
369
|
+
|
370
|
+
## License
|
371
|
+
|
372
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
373
|
+
|
374
|
+
## Contributing
|
375
|
+
|
376
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
377
|
+
|
378
|
+
### Development Setup
|
379
|
+
|
380
|
+
```bash
|
381
|
+
git clone https://github.com/QuantJourneyOrg/qj_bidask
|
382
|
+
cd qj_bidask
|
383
|
+
pip install -e ".[dev]"
|
384
|
+
|
385
|
+
# Run tests
|
386
|
+
pytest
|
387
|
+
|
388
|
+
# Run examples
|
389
|
+
python examples/realtime_spread_monitor.py
|
390
|
+
```
|
391
|
+
|
392
|
+
## Support
|
393
|
+
|
394
|
+
- **Documentation**: [GitHub Repository](https://github.com/QuantJourneyOrg/qj_bidask)
|
395
|
+
- **Issues**: [Bug Tracker](https://github.com/QuantJourneyOrg/qj_bidask/issues)
|
396
|
+
- **Contact**: jakub@quantjourney.pro
|
@@ -1,12 +1,12 @@
|
|
1
1
|
quantjourney_bidask/__init__.py,sha256=vumoRDEDOTclYapknfSwKpCZi9IdfJbukdp7S1-kphA,409
|
2
|
-
quantjourney_bidask/_version.py,sha256=
|
2
|
+
quantjourney_bidask/_version.py,sha256=PNfYxivWH2RCzGECwhMnGzRhNhiDg7KULZppaKoLiAI,220
|
3
3
|
quantjourney_bidask/data_fetcher.py,sha256=GMVf4wRVwIE2JJ2sYAR_CCo56JQnReNhTWTSrZc0-L0,4931
|
4
4
|
quantjourney_bidask/edge.py,sha256=z-uRUH3Rot6Zw-dPa2pNlQu0hY1YJu6d0c18IyqbiNs,6105
|
5
5
|
quantjourney_bidask/edge_expanding.py,sha256=bN6lBetJdqC2xSdRc1RTjHfSI1XXVKegl0GQaD8eanY,2047
|
6
6
|
quantjourney_bidask/edge_rolling.py,sha256=CAZW_wBF7G6mGLenoEwlq4yB_1x1-PsQ4TgwL-zdM7w,8910
|
7
7
|
quantjourney_bidask/websocket_fetcher.py,sha256=xMS_qLbSW9hCS3RbNKvkn5HTK0XGmAO4wpaAl4_Mxb4,10895
|
8
|
-
quantjourney_bidask-0.
|
9
|
-
quantjourney_bidask-0.
|
10
|
-
quantjourney_bidask-0.
|
11
|
-
quantjourney_bidask-0.
|
12
|
-
quantjourney_bidask-0.
|
8
|
+
quantjourney_bidask-0.9.0.dist-info/licenses/LICENSE,sha256=m8MEOGnpSBtS6m9z4M9m1JksWWPzu1OK3UgY1wuHf04,1081
|
9
|
+
quantjourney_bidask-0.9.0.dist-info/METADATA,sha256=BIMxqvn5Nijih6S43QCAo6RM_Ik1Df5NRV1X8Q-VkWg,13313
|
10
|
+
quantjourney_bidask-0.9.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
+
quantjourney_bidask-0.9.0.dist-info/top_level.txt,sha256=rOBM4GxA87iQv-mR8-WZdu3-Yj5ESyggRICpUhJ-4Dg,20
|
12
|
+
quantjourney_bidask-0.9.0.dist-info/RECORD,,
|
{quantjourney_bidask-0.5.0.dist-info → quantjourney_bidask-0.9.0.dist-info}/licenses/LICENSE
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2025 Jakub Polec, QuantJourney
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -1,183 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: quantjourney-bidask
|
3
|
-
Version: 0.5.0
|
4
|
-
Summary: Efficient bid-ask spread estimator from OHLC prices
|
5
|
-
Author-email: Jakub Polec <jakub@quantjourney.pro>
|
6
|
-
License-Expression: MIT
|
7
|
-
Project-URL: Homepage, https://github.com/QuantJourneyOrg/qj_bidask
|
8
|
-
Project-URL: Repository, https://github.com/QuantJourneyOrg/qj_bidask
|
9
|
-
Project-URL: Bug Tracker, https://github.com/QuantJourneyOrg/qj_bidask/issues
|
10
|
-
Keywords: finance,bid-ask,spread,trading,quantitative,OHLC
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
12
|
-
Classifier: Intended Audience :: Financial and Insurance Industry
|
13
|
-
Classifier: Operating System :: OS Independent
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
15
|
-
Classifier: Programming Language :: Python :: 3.11
|
16
|
-
Classifier: Programming Language :: Python :: 3.12
|
17
|
-
Classifier: Topic :: Office/Business :: Financial :: Investment
|
18
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
19
|
-
Requires-Python: <3.15,>=3.11
|
20
|
-
Description-Content-Type: text/markdown
|
21
|
-
License-File: LICENSE
|
22
|
-
Requires-Dist: numpy>=1.20
|
23
|
-
Requires-Dist: pandas>=1.5
|
24
|
-
Requires-Dist: requests>=2.28
|
25
|
-
Requires-Dist: yfinance>=0.2
|
26
|
-
Requires-Dist: matplotlib>=3.5
|
27
|
-
Requires-Dist: plotly>=5.0
|
28
|
-
Requires-Dist: websocket-client>=1.0
|
29
|
-
Provides-Extra: dev
|
30
|
-
Requires-Dist: pytest>=7.0; extra == "dev"
|
31
|
-
Requires-Dist: pytest-mock>=3.10; extra == "dev"
|
32
|
-
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
33
|
-
Requires-Dist: ruff>=0.1; extra == "dev"
|
34
|
-
Requires-Dist: mypy>=1.0; extra == "dev"
|
35
|
-
Requires-Dist: black>=22.0; extra == "dev"
|
36
|
-
Requires-Dist: isort>=5.0; extra == "dev"
|
37
|
-
Provides-Extra: examples
|
38
|
-
Requires-Dist: jupyter>=1.0; extra == "examples"
|
39
|
-
Requires-Dist: ipywidgets>=7.0; extra == "examples"
|
40
|
-
Dynamic: license-file
|
41
|
-
|
42
|
-
# QuantJourney Bid-Ask Spread Estimator
|
43
|
-
|
44
|
-

|
45
|
-

|
46
|
-

|
47
|
-
|
48
|
-
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
|
-
|
50
|
-
> Ardia, D., Guidotti, E., Kroencke, T.A. (2024). Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices. *Journal of Financial Economics*, 161, 103916. [doi:10.1016/j.jfineco.2024.103916](https://doi.org/10.1016/j.jfineco.2024.103916)
|
51
|
-
|
52
|
-
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
|
-
|
54
|
-
## Features
|
55
|
-
|
56
|
-
- **Efficient Spread Estimation**: Implements the EDGE estimator for single, rolling, and expanding windows.
|
57
|
-
- **Data Integration**: Fetch OHLC data from Binance (via custom FastAPI server) and Yahoo Finance (via yfinance).
|
58
|
-
- **Robust Handling**: Supports missing values, non-positive prices, and various data frequencies.
|
59
|
-
- **Comprehensive Tests**: Extensive unit tests with known test cases from the original paper.
|
60
|
-
- **Clear Documentation**: Detailed docstrings and usage examples.
|
61
|
-
|
62
|
-
## Installation
|
63
|
-
|
64
|
-
Install the library via pip:
|
65
|
-
|
66
|
-
```bash
|
67
|
-
pip install quantjourney-bidask
|
68
|
-
```
|
69
|
-
|
70
|
-
## Quick Start
|
71
|
-
|
72
|
-
### Basic Usage
|
73
|
-
|
74
|
-
```python
|
75
|
-
from quantjourney_bidask import edge
|
76
|
-
|
77
|
-
# Example OHLC data (as lists or numpy arrays)
|
78
|
-
open_prices = [100.0, 101.5, 99.8, 102.1, 100.9]
|
79
|
-
high_prices = [102.3, 103.0, 101.2, 103.5, 102.0]
|
80
|
-
low_prices = [99.5, 100.8, 98.9, 101.0, 100.1]
|
81
|
-
close_prices = [101.2, 100.2, 101.8, 100.5, 101.5]
|
82
|
-
|
83
|
-
# Calculate bid-ask spread
|
84
|
-
spread = edge(open_prices, high_prices, low_prices, close_prices)
|
85
|
-
print(f"Estimated bid-ask spread: {spread:.6f}")
|
86
|
-
```
|
87
|
-
|
88
|
-
### Rolling Window Analysis
|
89
|
-
|
90
|
-
```python
|
91
|
-
from quantjourney_bidask import edge_rolling
|
92
|
-
|
93
|
-
# Calculate rolling spreads with a 20-period window
|
94
|
-
rolling_spreads = edge_rolling(
|
95
|
-
open_prices, high_prices, low_prices, close_prices,
|
96
|
-
window=20
|
97
|
-
)
|
98
|
-
print(f"Rolling spreads: {rolling_spreads}")
|
99
|
-
```
|
100
|
-
|
101
|
-
### Data Fetching Integration
|
102
|
-
|
103
|
-
```python
|
104
|
-
from quantjourney_bidask import fetch_yfinance_data, edge
|
105
|
-
|
106
|
-
# Fetch OHLC data for a stock
|
107
|
-
data = fetch_yfinance_data("AAPL", period="1mo", interval="1h")
|
108
|
-
|
109
|
-
# Calculate spread from fetched data
|
110
|
-
spread = edge(data['Open'], data['High'], data['Low'], data['Close'])
|
111
|
-
print(f"AAPL spread estimate: {spread:.6f}")
|
112
|
-
```
|
113
|
-
|
114
|
-
### Live Monitoring
|
115
|
-
|
116
|
-
```python
|
117
|
-
from quantjourney_bidask import LiveSpreadMonitor
|
118
|
-
|
119
|
-
# Monitor live spreads for cryptocurrency
|
120
|
-
monitor = LiveSpreadMonitor("BTCUSDT", window=100)
|
121
|
-
monitor.start()
|
122
|
-
|
123
|
-
# Get current spread estimate
|
124
|
-
current_spread = monitor.get_current_spread()
|
125
|
-
print(f"Current BTC/USDT spread: {current_spread:.6f}")
|
126
|
-
|
127
|
-
monitor.stop()
|
128
|
-
```
|
129
|
-
|
130
|
-
## API Reference
|
131
|
-
|
132
|
-
### Core Functions
|
133
|
-
|
134
|
-
- `edge(open, high, low, close, sign=False)`: Single-period spread estimation
|
135
|
-
- `edge_rolling(open, high, low, close, window, min_periods=None)`: Rolling window estimation
|
136
|
-
- `edge_expanding(open, high, low, close, min_periods=3)`: Expanding window estimation
|
137
|
-
|
138
|
-
### Data Fetching
|
139
|
-
|
140
|
-
- `fetch_yfinance_data(symbol, period, interval)`: Fetch data from Yahoo Finance
|
141
|
-
- `fetch_binance_data(symbol, interval, limit)`: Fetch data from Binance API
|
142
|
-
|
143
|
-
### Live Monitoring
|
144
|
-
|
145
|
-
- `LiveSpreadMonitor(symbol, window)`: Real-time spread monitoring via WebSocket
|
146
|
-
|
147
|
-
## Requirements
|
148
|
-
|
149
|
-
- Python >= 3.8
|
150
|
-
- numpy >= 1.20
|
151
|
-
- pandas >= 1.5
|
152
|
-
- requests >= 2.28
|
153
|
-
- yfinance >= 0.2
|
154
|
-
|
155
|
-
## Academic Citation
|
156
|
-
|
157
|
-
If you use this library in academic research, please cite:
|
158
|
-
|
159
|
-
```bibtex
|
160
|
-
@article{ardia2024efficient,
|
161
|
-
title={Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices},
|
162
|
-
author={Ardia, David and Guidotti, Emanuele and Kroencke, Tim A},
|
163
|
-
journal={Journal of Financial Economics},
|
164
|
-
volume={161},
|
165
|
-
pages={103916},
|
166
|
-
year={2024},
|
167
|
-
publisher={Elsevier}
|
168
|
-
}
|
169
|
-
```
|
170
|
-
|
171
|
-
## License
|
172
|
-
|
173
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
174
|
-
|
175
|
-
## Contributing
|
176
|
-
|
177
|
-
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
178
|
-
|
179
|
-
## Support
|
180
|
-
|
181
|
-
- **Documentation**: [GitHub Repository](https://github.com/QuantJourneyOrg/qj_bidask)
|
182
|
-
- **Issues**: [Bug Tracker](https://github.com/QuantJourneyOrg/qj_bidask/issues)
|
183
|
-
- **Contact**: jakub@quantjourney.pro
|
File without changes
|
File without changes
|