voly 0.0.74__tar.gz → 0.0.76__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: voly
3
- Version: 0.0.74
3
+ Version: 0.0.76
4
4
  Summary: Options & volatility research package
5
5
  Author-email: Manu de Cara <manu.de.cara@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "voly"
7
- version = "0.0.74"
7
+ version = "0.0.76"
8
8
  description = "Options & volatility research package"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -60,7 +60,7 @@ line_length = 100
60
60
  multi_line_output = 3
61
61
 
62
62
  [tool.mypy]
63
- python_version = "0.0.74"
63
+ python_version = "0.0.76"
64
64
  warn_return_any = true
65
65
  warn_unused_configs = true
66
66
  disallow_untyped_defs = true
@@ -364,13 +364,13 @@ class VolyClient:
364
364
  - Surface. Dict composed of (iv_surface, x_surface)
365
365
  """
366
366
  # Generate the surface
367
- surface = get_iv_surface(
367
+ iv_surface, x_surface = get_iv_surface(
368
368
  fit_results=fit_results,
369
369
  log_moneyness_params=log_moneyness_params,
370
370
  return_domain=return_domain
371
371
  )
372
372
 
373
- return surface
373
+ return iv_surface, x_surface
374
374
 
375
375
  @staticmethod
376
376
  def plot_model(fit_results: pd.DataFrame,
@@ -393,18 +393,14 @@ class VolyClient:
393
393
  plots = {}
394
394
 
395
395
  # Generate IV surface and domain
396
- surface = get_iv_surface(fit_results, log_moneyness_params, return_domain)
397
-
398
- # Get iv_surface and x_surface from the return value
399
- iv_surface = surface['iv_surface']
400
- x_surface = surface['x_surface']
396
+ iv_surface, x_surface = get_iv_surface(fit_results, log_moneyness_params, return_domain)
401
397
 
402
398
  # Plot volatility smiles
403
399
  plots['smiles'] = plot_all_smiles(
404
400
  x_surface=x_surface,
405
401
  iv_surface=iv_surface,
406
402
  option_chain=option_chain,
407
- domain_type=return_domain
403
+ return_domain=return_domain
408
404
  )
409
405
 
410
406
  # Plot parameters
@@ -19,20 +19,20 @@ pio.renderers.default = "browser"
19
19
 
20
20
 
21
21
  @catch_exception
22
- def plot_volatility_smile(x_domain: np.ndarray,
22
+ def plot_volatility_smile(x_array: np.ndarray,
23
23
  iv_array: np.ndarray,
24
24
  option_chain: pd.DataFrame = None,
25
25
  maturity: Optional[str] = None,
26
- domain_type: str = 'log_moneyness') -> go.Figure:
26
+ return_domain: str = 'log_moneyness') -> go.Figure:
27
27
  """
28
28
  Plot volatility smile for a single expiry.
29
29
 
30
30
  Parameters:
31
- - x_domain: Array of x-axis values in the specified domain
31
+ - x_array: Array of x-axis values in the specified domain
32
32
  - iv_array: Implied volatility values
33
33
  - option_chain: Optional market data for comparison
34
34
  - maturity: Maturity name for filtering market data
35
- - domain_type: Type of x-domain ('log_moneyness', 'moneyness', 'strikes', 'delta')
35
+ - return_domain: Type of x-domain ('log_moneyness', 'moneyness', 'strikes', 'delta')
36
36
 
37
37
  Returns:
38
38
  - Plotly figure
@@ -40,9 +40,9 @@ def plot_volatility_smile(x_domain: np.ndarray,
40
40
  # Map domain types to axis labels
41
41
  domain_labels = {
42
42
  'log_moneyness': 'Log Moneyness',
43
- 'moneyness': 'Moneyness (S/K)',
43
+ 'moneyness': 'Moneyness',
44
44
  'strikes': 'Strike Price',
45
- 'delta': 'Call Delta'
45
+ 'delta': 'Delta'
46
46
  }
47
47
 
48
48
  fig = go.Figure()
@@ -50,7 +50,7 @@ def plot_volatility_smile(x_domain: np.ndarray,
50
50
  # Add model curve
51
51
  fig.add_trace(
52
52
  go.Scatter(
53
- x=x_domain,
53
+ x=x_array,
54
54
  y=iv_array * 100, # Convert to percentage
55
55
  mode='lines',
56
56
  name='Model',
@@ -68,7 +68,7 @@ def plot_volatility_smile(x_domain: np.ndarray,
68
68
  if iv_type in maturity_data.columns:
69
69
  fig.add_trace(
70
70
  go.Scatter(
71
- x=maturity_data['log_moneyness'],
71
+ x=maturity_data[return_domain],
72
72
  y=maturity_data[iv_type] * 100, # Convert to percentage
73
73
  mode='markers',
74
74
  name=iv_type.replace('_', ' ').upper(),
@@ -76,7 +76,7 @@ def plot_volatility_smile(x_domain: np.ndarray,
76
76
  )
77
77
  )
78
78
 
79
- title = f'Vol Smile for {maturity} (DTE: {maturity_data["dtm"].iloc[0]:.1f})'
79
+ title = f'Vol Smile for {maturity} (DTM: {maturity_data["dtm"].iloc[0]:.1f})'
80
80
  else:
81
81
  title = f'Vol Smile for {maturity}'
82
82
  else:
@@ -85,7 +85,7 @@ def plot_volatility_smile(x_domain: np.ndarray,
85
85
  # Update layout
86
86
  fig.update_layout(
87
87
  title=title,
88
- xaxis_title=domain_labels.get(domain_type, 'X Domain'),
88
+ xaxis_title=domain_labels.get(return_domain, 'X Domain'),
89
89
  yaxis_title='Implied Volatility (%)',
90
90
  template='plotly_dark',
91
91
  legend=dict(orientation='h', yanchor='bottom', y=1.02, xanchor='right', x=1)
@@ -98,7 +98,7 @@ def plot_volatility_smile(x_domain: np.ndarray,
98
98
  def plot_all_smiles(x_surface: Dict[str, np.ndarray],
99
99
  iv_surface: Dict[str, np.ndarray],
100
100
  option_chain: Optional[pd.DataFrame] = None,
101
- domain_type: str = 'log_moneyness') -> List[go.Figure]:
101
+ return_domain: str = 'log_moneyness') -> List[go.Figure]:
102
102
  """
103
103
  Plot volatility smiles for all expiries.
104
104
 
@@ -106,18 +106,18 @@ def plot_all_smiles(x_surface: Dict[str, np.ndarray],
106
106
  - x_surface: Dictionary mapping maturity names to x-domain arrays
107
107
  - iv_surface: Dictionary mapping maturity names to IV arrays
108
108
  - option_chain: Optional market data for comparison
109
- - domain_type: Type of x-domain ('log_moneyness', 'moneyness', 'strikes', 'delta')
109
+ - return_domain: Type of x-domain ('log_moneyness', 'moneyness', 'strikes', 'delta')
110
110
 
111
111
  Returns:
112
112
  - List of Plotly figures
113
113
  """
114
114
  return [
115
115
  plot_volatility_smile(
116
- x_domain=x_surface[maturity],
116
+ x_array=x_surface[maturity],
117
117
  iv_array=iv_surface[maturity],
118
118
  option_chain=option_chain,
119
119
  maturity=maturity,
120
- domain_type=domain_type
120
+ return_domain=return_domain
121
121
  )
122
122
  for maturity in iv_surface.keys()
123
123
  ]
@@ -148,7 +148,7 @@ def plot_raw_parameters(fit_results: pd.DataFrame) -> go.Figure:
148
148
  maturity_names = fit_results.index
149
149
 
150
150
  # Create hover text with maturity info
151
- tick_labels = [f"{m} (DTE: {fit_results.loc[m, 'dtm']:.1f}, YTE: {fit_results.loc[m, 'ytm']:.4f})"
151
+ tick_labels = [f"{m} (DTM: {fit_results.loc[m, 'dtm']:.1f}"
152
152
  for m in maturity_names]
153
153
 
154
154
  # Plot each parameter
@@ -224,7 +224,9 @@ def process_option_chain(df: pd.DataFrame, currency: str) -> pd.DataFrame:
224
224
  df['ask_iv'] = df['ask_iv'].replace({0: np.nan}) / 100
225
225
 
226
226
  # Calculate log-moneyness
227
- df['log_moneyness'] = np.log(df['underlying_price'] / df['strike'])
227
+ df['log_moneyness'] = np.log(df['index_price'] / df['strike'])
228
+ # Calculate moneyness
229
+ df['moneyness'] = np.exp(df['log_moneyness'])
228
230
 
229
231
  logger.info(f"Processing complete!")
230
232
 
@@ -238,4 +238,4 @@ def get_iv_surface(fit_results: pd.DataFrame,
238
238
  ytm=ytm
239
239
  )
240
240
 
241
- return {'iv_surface': iv_surface, 'x_surface': x_surface}
241
+ return iv_surface, x_surface
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: voly
3
- Version: 0.0.74
3
+ Version: 0.0.76
4
4
  Summary: Options & volatility research package
5
5
  Author-email: Manu de Cara <manu.de.cara@gmail.com>
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes