quantjourney-bidask 0.5.0__py3-none-any.whl → 0.6.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.
@@ -1,6 +1,6 @@
1
1
  """Version information for quantjourney_bidask."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.6.0"
4
4
  __author__ = "Jakub Polec"
5
5
  __email__ = "jakub@quantjourney.pro"
6
6
  __license__ = "Apache License 2.0"
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantjourney-bidask
3
- Version: 0.5.0
4
- Summary: Efficient bid-ask spread estimator from OHLC prices
3
+ Version: 0.6.0
4
+ Summary: Efficient bid-ask spread estimator from OHLC prices with simplified data fetching for stocks and crypto
5
5
  Author-email: Jakub Polec <jakub@quantjourney.pro>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/QuantJourneyOrg/qj_bidask
@@ -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: ccxt>=4.0
29
30
  Provides-Extra: dev
30
31
  Requires-Dist: pytest>=7.0; extra == "dev"
31
32
  Requires-Dist: pytest-mock>=3.10; extra == "dev"
@@ -54,7 +55,10 @@ This library is designed for quantitative finance professionals, researchers, an
54
55
  ## Features
55
56
 
56
57
  - **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
+ - **Real-Time Data**: Websocket support for live cryptocurrency data from Binance and other exchanges.
59
+ - **Data Integration**: Fetch OHLC data from Yahoo Finance and generate synthetic data for testing.
60
+ - **Live Monitoring**: Real-time spread monitoring with animated visualizations.
61
+ - **Local Development**: Works completely locally without cloud dependencies.
58
62
  - **Robust Handling**: Supports missing values, non-positive prices, and various data frequencies.
59
63
  - **Comprehensive Tests**: Extensive unit tests with known test cases from the original paper.
60
64
  - **Clear Documentation**: Detailed docstrings and usage examples.
@@ -67,6 +71,14 @@ Install the library via pip:
67
71
  pip install quantjourney-bidask
68
72
  ```
69
73
 
74
+ For development (local setup):
75
+
76
+ ```bash
77
+ git clone https://github.com/QuantJourneyOrg/qj_bidask
78
+ cd qj_bidask
79
+ pip install -e .
80
+ ```
81
+
70
82
  ## Quick Start
71
83
 
72
84
  ### Basic Usage
@@ -89,42 +101,106 @@ print(f"Estimated bid-ask spread: {spread:.6f}")
89
101
 
90
102
  ```python
91
103
  from quantjourney_bidask import edge_rolling
104
+ import pandas as pd
105
+
106
+ # Create DataFrame with OHLC data
107
+ df = pd.DataFrame({
108
+ 'open': open_prices,
109
+ 'high': high_prices,
110
+ 'low': low_prices,
111
+ 'close': close_prices
112
+ })
92
113
 
93
114
  # 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
- )
115
+ rolling_spreads = edge_rolling(df, window=20)
98
116
  print(f"Rolling spreads: {rolling_spreads}")
99
117
  ```
100
118
 
101
119
  ### Data Fetching Integration
102
120
 
103
121
  ```python
104
- from quantjourney_bidask import fetch_yfinance_data, edge
122
+ from data.fetch import get_stock_data, get_crypto_data
123
+ from quantjourney_bidask import edge_rolling
124
+ import asyncio
125
+
126
+ # Fetch stock data
127
+ stock_df = get_stock_data("AAPL", period="1mo", interval="1d")
128
+ stock_spreads = edge_rolling(stock_df, window=20)
129
+ print(f"AAPL average spread: {stock_spreads.mean():.6f}")
130
+
131
+ # Fetch crypto data (async)
132
+ async def get_crypto_spreads():
133
+ crypto_df = await get_crypto_data("BTC/USDT", "binance", "1h", 168)
134
+ crypto_spreads = edge_rolling(crypto_df, window=24)
135
+ return crypto_spreads.mean()
136
+
137
+ crypto_avg_spread = asyncio.run(get_crypto_spreads())
138
+ print(f"BTC average spread: {crypto_avg_spread:.6f}")
139
+ ```
140
+
141
+ ### Real-time Data Streaming
142
+
143
+ ```python
144
+ from data.fetch import DataFetcher
145
+ import asyncio
146
+
147
+ async def stream_btc_spreads():
148
+ fetcher = DataFetcher()
149
+ # Stream BTC data for 60 seconds
150
+ btc_stream = await fetcher.get_btc_1m_websocket(duration_seconds=60)
151
+
152
+ # Calculate spread from real-time data
153
+ if not btc_stream.empty:
154
+ avg_spread_pct = (btc_stream['spread'] / btc_stream['price']).mean() * 100
155
+ print(f"Real-time BTC average spread: {avg_spread_pct:.4f}%")
156
+
157
+ asyncio.run(stream_btc_spreads())
158
+ ```
159
+
160
+ ### Real-Time Spread Monitoring
161
+
162
+ ```python
163
+ from data.fetch import create_spread_monitor
105
164
 
106
- # Fetch OHLC data for a stock
107
- data = fetch_yfinance_data("AAPL", period="1mo", interval="1h")
165
+ # Create real-time spread monitor
166
+ monitor = create_spread_monitor(["BTCUSDT", "ETHUSDT"], window=20)
108
167
 
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}")
168
+ # Add callback for spread updates
169
+ def print_spread_update(spread_data):
170
+ print(f"{spread_data['symbol']}: {spread_data['spread_bps']:.2f} bps")
171
+
172
+ monitor.add_spread_callback(print_spread_update)
173
+
174
+ # Start monitoring (uses websockets for live data)
175
+ monitor.start_monitoring("1m")
112
176
  ```
113
177
 
114
- ### Live Monitoring
178
+ ### Animated Real-Time Dashboard
115
179
 
116
180
  ```python
117
- from quantjourney_bidask import LiveSpreadMonitor
181
+ # Run the real-time dashboard
182
+ python examples/realtime_spread_monitor.py --mode dashboard
183
+
184
+ # Or console mode
185
+ python examples/realtime_spread_monitor.py --mode console
186
+ ```
187
+
188
+ ## Examples
118
189
 
119
- # Monitor live spreads for cryptocurrency
120
- monitor = LiveSpreadMonitor("BTCUSDT", window=100)
121
- monitor.start()
190
+ The `examples/` directory contains comprehensive examples:
122
191
 
123
- # Get current spread estimate
124
- current_spread = monitor.get_current_spread()
125
- print(f"Current BTC/USDT spread: {current_spread:.6f}")
192
+ - `spread_estimator.py` - Basic spread estimation examples
193
+ - `spread_monitor.py` - Spread monitoring with threshold alerts
194
+ - `realtime_spread_monitor.py` - Live websocket monitoring with animation
195
+ - `crypto_spread_comparison.py` - Multi-asset spread comparison
196
+ - `liquidity_risk_monitor.py` - Liquidity risk monitoring
197
+ - `stock_liquidity_risk.py` - Stock-specific liquidity analysis
126
198
 
127
- monitor.stop()
199
+ Run any example:
200
+
201
+ ```bash
202
+ python examples/spread_estimator.py
203
+ python examples/realtime_spread_monitor.py
128
204
  ```
129
205
 
130
206
  ## API Reference
@@ -132,25 +208,45 @@ monitor.stop()
132
208
  ### Core Functions
133
209
 
134
210
  - `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
211
+ - `edge_rolling(df, window, min_periods=None)`: Rolling window estimation
212
+ - `edge_expanding(df, min_periods=3)`: Expanding window estimation
137
213
 
138
- ### Data Fetching
214
+ ### Data Fetching (`data/fetch.py`)
139
215
 
140
- - `fetch_yfinance_data(symbol, period, interval)`: Fetch data from Yahoo Finance
141
- - `fetch_binance_data(symbol, interval, limit)`: Fetch data from Binance API
216
+ - `fetch_yfinance_data(tickers, period, interval)`: Fetch real market data from Yahoo Finance
217
+ - `generate_synthetic_crypto_data(symbols, hours, interval_minutes)`: Generate synthetic crypto data
218
+ - `fetch_binance_data(*args, **kwargs)`: Compatibility function (returns synthetic data)
219
+ - `create_realtime_stream(symbols, exchange)`: Create websocket data stream
220
+ - `create_spread_monitor(symbols, window)`: Create real-time spread monitor
142
221
 
143
- ### Live Monitoring
222
+ ### Real-Time Classes
144
223
 
145
- - `LiveSpreadMonitor(symbol, window)`: Real-time spread monitoring via WebSocket
224
+ - `RealTimeDataStream`: Websocket data streaming for live market data
225
+ - `RealTimeSpreadMonitor`: Real-time spread calculation and monitoring
226
+ - `AnimatedSpreadMonitor`: Animated real-time visualization
146
227
 
147
228
  ## Requirements
148
229
 
149
- - Python >= 3.8
230
+ - Python >= 3.11
150
231
  - numpy >= 1.20
151
232
  - pandas >= 1.5
152
233
  - requests >= 2.28
153
234
  - yfinance >= 0.2
235
+ - matplotlib >= 3.5
236
+ - websocket-client >= 1.0
237
+
238
+ ## WebSocket Support
239
+
240
+ The library supports real-time data via websockets:
241
+
242
+ - **Binance**: `wss://stream.binance.com:9443/ws/` (cryptocurrency data)
243
+ - **Fallback**: Synthetic data generation for testing when websockets unavailable
244
+
245
+ Real-time features:
246
+ - Live spread calculation
247
+ - Animated visualizations
248
+ - Threshold alerts
249
+ - Multi-symbol monitoring
154
250
 
155
251
  ## Academic Citation
156
252
 
@@ -176,6 +272,20 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
176
272
 
177
273
  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
274
 
275
+ ### Development Setup
276
+
277
+ ```bash
278
+ git clone https://github.com/QuantJourneyOrg/qj_bidask
279
+ cd qj_bidask
280
+ pip install -e ".[dev]"
281
+
282
+ # Run tests
283
+ pytest
284
+
285
+ # Run examples
286
+ python examples/realtime_spread_monitor.py
287
+ ```
288
+
179
289
  ## Support
180
290
 
181
291
  - **Documentation**: [GitHub Repository](https://github.com/QuantJourneyOrg/qj_bidask)
@@ -1,12 +1,12 @@
1
1
  quantjourney_bidask/__init__.py,sha256=vumoRDEDOTclYapknfSwKpCZi9IdfJbukdp7S1-kphA,409
2
- quantjourney_bidask/_version.py,sha256=FG3XKw_Vb0JfvroFMn303BEuhI10eKAvkGzI0gQT-LY,235
2
+ quantjourney_bidask/_version.py,sha256=kyNk5HYKJ0-OI9dXUspkUZDOPfOl8yymKmhaJH3QWcU,235
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.5.0.dist-info/licenses/LICENSE,sha256=vny3AM3KIslUu5fdooMsdxVKghoZhDKnBCsLvMDHqLg,1081
9
- quantjourney_bidask-0.5.0.dist-info/METADATA,sha256=17qESjK2WZZl89pukiZF21IzX4xlbP_n14lZWNsfDbg,6234
10
- quantjourney_bidask-0.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- quantjourney_bidask-0.5.0.dist-info/top_level.txt,sha256=rOBM4GxA87iQv-mR8-WZdu3-Yj5ESyggRICpUhJ-4Dg,20
12
- quantjourney_bidask-0.5.0.dist-info/RECORD,,
8
+ quantjourney_bidask-0.6.0.dist-info/licenses/LICENSE,sha256=vny3AM3KIslUu5fdooMsdxVKghoZhDKnBCsLvMDHqLg,1081
9
+ quantjourney_bidask-0.6.0.dist-info/METADATA,sha256=mznMm67-LzniXtsOHzxwdvlLFJnKXnbwiGaSDjBcIMU,9565
10
+ quantjourney_bidask-0.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ quantjourney_bidask-0.6.0.dist-info/top_level.txt,sha256=rOBM4GxA87iQv-mR8-WZdu3-Yj5ESyggRICpUhJ-4Dg,20
12
+ quantjourney_bidask-0.6.0.dist-info/RECORD,,