voly 0.0.152__py3-none-any.whl → 0.0.154__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.
voly/client.py CHANGED
@@ -23,8 +23,7 @@ from voly.core.rnd import get_rnd_surface
23
23
  from voly.core.hd import get_historical_data, get_hd_surface
24
24
  from voly.core.interpolate import interpolate_model
25
25
  from voly.core.charts import (
26
- plot_all_smiles, plot_raw_parameters, plot_jw_parameters, plot_fit_performance, plot_3d_surface,
27
- plot_fit_performance
26
+ plot_all_smiles, plot_raw_parameters, plot_jw_parameters, plot_fit_performance, plot_3d_surface
28
27
  )
29
28
 
30
29
 
@@ -37,10 +36,14 @@ class VolyClient:
37
36
  - enable_file_logging: Whether to enable file-based logging
38
37
  - logs_dir: Directory for log files if file logging is enabled
39
38
  """
39
+
40
+ from importlib.metadata import version
41
+ voly_version = version("voly")
42
+
40
43
  if enable_file_logging:
41
44
  setup_file_logging(logs_dir)
42
45
 
43
- logger.info("VolyClient initialized")
46
+ logger.info(f"VolyClient (v{voly_version}) initialized")
44
47
  self._loop = None # For async operations
45
48
 
46
49
  def _get_event_loop(self):
@@ -156,10 +159,6 @@ class VolyClient:
156
159
  option_type: str = 'call') -> float:
157
160
  return iv(option_price, s, K, r, t, option_type)
158
161
 
159
- @staticmethod
160
- def pdf_to_calls(pdf_K: np.ndarray, s: float, K: np.ndarray, r: float, t: float):
161
- return pdf_to_calls(pdf_K, s, K, r, t)
162
-
163
162
  # -------------------------------------------------------------------------
164
163
  # Model Fitting
165
164
  # -------------------------------------------------------------------------
@@ -307,8 +306,19 @@ class VolyClient:
307
306
  def get_rnd_surface(model_results: pd.DataFrame,
308
307
  domain_params: Tuple[float, float, int] = (-1.5, 1.5, 1000),
309
308
  return_domain: str = 'log_moneyness',
310
- method: str = 'rookley') -> Tuple[Dict[str, np.ndarray], Dict[str, np.ndarray], Dict[str, np.ndarray], pd.DataFrame]:
309
+ method: str = 'rookley') -> Dict[str, Any]:
310
+ """
311
+ Generate risk-neutral density surface from volatility surface parameters.
312
+
313
+ Parameters:
314
+ - model_results: DataFrame from fit_model() or interpolate_model()
315
+ - domain_params: Tuple of (min_log_moneyness, max_log_moneyness, num_points)
316
+ - return_domain: Domain for results ('log_moneyness', 'moneyness', 'returns', 'strikes')
317
+ - method: Method for RND estimation ('rookley' or 'breeden')
311
318
 
319
+ Returns:
320
+ - Dictionary with pdf_surface, cdf_surface, x_surface, and moments
321
+ """
312
322
  logger.info("Calculating RND surface")
313
323
 
314
324
  return get_rnd_surface(
@@ -326,41 +336,50 @@ class VolyClient:
326
336
  def get_historical_data(currency: str = 'BTC',
327
337
  lookback_days: str = '90d',
328
338
  granularity: str = '15m',
329
- exchange_name: str = 'binance'):
339
+ exchange_name: str = 'binance') -> pd.DataFrame:
340
+ """
341
+ Fetch historical OHLCV data for a cryptocurrency.
330
342
 
331
- # Generate the surface
332
- df_hist = get_historical_data(
343
+ Parameters:
344
+ - currency: The cryptocurrency to fetch data for (e.g., 'BTC', 'ETH')
345
+ - lookback_days: The lookback period in days, formatted as '90d', '30d', etc.
346
+ - granularity: The time interval for data points (e.g., '15m', '1h', '1d')
347
+ - exchange_name: The exchange to fetch data from (default: 'binance')
348
+
349
+ Returns:
350
+ - Historical price data with OHLCV columns and datetime index
351
+ """
352
+ logger.info(f"Fetching historical {currency} data from {exchange_name}...")
353
+
354
+ return get_historical_data(
333
355
  currency=currency,
334
356
  lookback_days=lookback_days,
335
357
  granularity=granularity,
336
358
  exchange_name=exchange_name
337
359
  )
338
360
 
339
- return df_hist
340
-
341
361
  @staticmethod
342
362
  def get_hd_surface(model_results: pd.DataFrame,
343
363
  df_hist: pd.DataFrame,
344
364
  domain_params: Tuple[float, float, int] = (-1.5, 1.5, 1000),
345
- return_domain: str = 'log_moneyness',
346
- method: str = 'garch',
347
- distribution: str = 'normal',
348
- window_length: str = '30d',
349
- n_fits: int = 400,
350
- simulations: int = 5000,
351
- bandwidth: str = 'silverman') -> Dict[str, Any]:
365
+ return_domain: str = 'log_moneyness') -> Dict[str, Any]:
366
+ """
367
+ Generate historical density surface using normal distributions.
352
368
 
353
- logger.info(f"Calculating historical density surface using {method} method")
369
+ Parameters:
370
+ - model_results: DataFrame with model parameters and maturities
371
+ - df_hist: DataFrame with historical price data
372
+ - domain_params: Tuple of (min_log_moneyness, max_log_moneyness, num_points)
373
+ - return_domain: Domain for results ('log_moneyness', 'moneyness', 'returns', 'strikes')
374
+
375
+ Returns:
376
+ - Dictionary with pdf_surface, cdf_surface, x_surface, and moments
377
+ """
378
+ logger.info("Calculating HD surface")
354
379
 
355
380
  return get_hd_surface(
356
381
  model_results=model_results,
357
382
  df_hist=df_hist,
358
383
  domain_params=domain_params,
359
- return_domain=return_domain,
360
- method=method,
361
- distribution=distribution,
362
- window_length=window_length,
363
- n_fits=n_fits,
364
- simulations=simulations,
365
- bandwidth=bandwidth
384
+ return_domain=return_domain
366
385
  )