Skip to content

Commit a15d2b0

Browse files
authored
Fix API (#68)
1 parent 309a159 commit a15d2b0

42 files changed

Lines changed: 805 additions & 521 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/api/hurst.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _range_std(pdf: Any, range_seconds: float, seconds_in_day: int) -> float:
5252

5353
def _ohlc_hurst(df: pd.DataFrame, serie: str, periods: tuple) -> dict[str, float]:
5454
template = OHLC(
55-
serie=serie,
55+
series=serie,
5656
period="10m",
5757
rogers_satchell_variance=True,
5858
parkinson_variance=True,
@@ -97,7 +97,7 @@ async def hurst_wiener(
9797
gk_vals = []
9898
rs_vals = []
9999
template = OHLC(
100-
serie="0",
100+
series="0",
101101
period="10m",
102102
rogers_satchell_variance=True,
103103
parkinson_variance=True,

docs/api/options/moneyness.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Moneyness
2+
3+
Conversion utilities between strike, log-strike, and
4+
[moneyness](../../glossary.md#moneyness) representations.
5+
6+
These functions provide a single authoritative source for the relationships
7+
between absolute strikes, log-strikes, and time-scaled moneyness used
8+
throughout the library.
9+
10+
::: quantflow.options.moneyness

docs/api/options/vol_surface.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
## Bid/Ask Prices
1919

20-
::: quantflow.options.surface.Price
21-
2220
::: quantflow.options.surface.SpotPrice
2321

2422
::: quantflow.options.surface.FwdPrice
@@ -27,8 +25,6 @@
2725

2826
::: quantflow.options.surface.OptionArrays
2927

30-
::: quantflow.options.surface.OptionMetadata
31-
3228
::: quantflow.options.surface.OptionPrice
3329

3430
::: quantflow.options.surface.OptionPrices
@@ -41,6 +37,8 @@
4137

4238
::: quantflow.options.inputs.OptionType
4339

40+
::: quantflow.options.inputs.OptionMetadata
41+
4442
::: quantflow.options.inputs.VolSurfaceInputs
4543

4644
::: quantflow.options.inputs.VolSurfaceInput

docs/api/ta/ewma.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# EWMA
22

33

4-
::: quantflow.ta.EWMA
4+
::: quantflow.ta.ewma.EWMA

docs/api/ta/kalman.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Kalman Filter
22

3-
::: quantflow.ta.KalmanFilter
3+
::: quantflow.ta.kalman.KalmanFilter

docs/api/ta/supersmoother.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Reference:
1111
Ehlers, J. (2013). "Cycle Analytics for Traders"
1212

1313

14-
::: quantflow.ta.SuperSmoother
14+
::: quantflow.ta.supersmoother.SuperSmoother

docs/api/utils/price.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Bid/Ask Prices
2+
3+
::: quantflow.utils.price.Price
4+
5+
::: quantflow.utils.price.PriceVolume

mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ nav:
7474
- Black-Scholes: api/options/black.md
7575
- Calibration: api/options/calibration.md
7676
- Deep IV Factor Model: api/options/divfm.md
77+
- Moneyness: api/options/moneyness.md
7778
- Put-Call Parity: api/options/parity.md
7879
- Pricer: api/options/pricer.md
7980
- SVI Smile: api/options/svi.md
@@ -90,7 +91,7 @@ nav:
9091
- Poisson Process: api/sp/poisson.md
9192
- Wiener Process: api/sp/wiener.md
9293
- Copulas: api/sp/copula.md
93-
- Technical Analysis:
94+
- Timeseries Analysis:
9495
- api/ta/index.md
9596
- EWMA: api/ta/ewma.md
9697
- Kalman Filter: api/ta/kalman.md
@@ -109,6 +110,7 @@ nav:
109110
- Distributions: api/utils/distributions.md
110111
- Marginal 1D: api/utils/marginal1d.md
111112
- Numbers: api/utils/numbers.md
113+
- Price: api/utils/price.md
112114
- Types: api/utils/types.md
113115
- Tutorials:
114116
- tutorials/index.md

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ readme = "readme.md"
3333
requires-python = ">=3.11,<3.15"
3434
dependencies = [
3535
"scipy>=1.14.1",
36+
"pandas>=2.0.0",
3637
"pydantic>=2.0.2",
3738
"ccy>=2.0.0",
3839
"python-dotenv>=1.0.1",
39-
"polars[pandas,pyarrow]>=1.11.0",
4040
"statsmodels>=0.14.6,<0.15.0",
4141
]
4242

quantflow/options/calibration/base.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from quantflow.utils import plot
1616

1717
from ..bs import implied_black_volatility
18+
from ..moneyness import log_strike_from_moneyness, moneyness_from_log_strike
1819
from ..pricer import OptionPricerBase
1920
from ..surface import OptionPrice, VolSurface
2021

@@ -150,7 +151,9 @@ def model_post_init(self, _ctx: Any) -> None:
150151
entries = tuple(self.options.values())
151152
self._log_strikes = np.asarray([e.log_strike for e in entries])
152153
self._ttms = np.asarray([e.ttm for e in entries])
153-
self._moneyness = self._log_strikes / np.sqrt(self._ttms)
154+
self._moneyness = np.asarray(
155+
moneyness_from_log_strike(self._log_strikes, self._ttms)
156+
)
154157
self._mid_prices = np.asarray([e.mid_price() for e in entries])
155158
self._mid_ivs = np.asarray([e.mid_iv() for e in entries])
156159

@@ -223,7 +226,7 @@ def cost_weight(self, ttm: float, log_strike: float) -> float:
223226
Up-weights wing options via `exp(moneyness_weight * moneyness**2)`,
224227
capped at `max_cost_weight`. The quadratic form mimics `1/vega`.
225228
"""
226-
moneyness = log_strike / np.sqrt(ttm)
229+
moneyness = float(moneyness_from_log_strike(log_strike, ttm))
227230
weight = np.exp(self.moneyness_weight * moneyness * moneyness)
228231
return float(min(weight, self.max_cost_weight))
229232

@@ -281,7 +284,11 @@ def cost_function(self, params: np.ndarray) -> float:
281284
def _model_grid(
282285
self, ttm: float, max_moneyness: float, support: int
283286
) -> pd.DataFrame:
284-
log_strikes = np.linspace(-max_moneyness, max_moneyness, support) * np.sqrt(ttm)
287+
log_strikes = np.asarray(
288+
log_strike_from_moneyness(
289+
np.linspace(-max_moneyness, max_moneyness, support), ttm
290+
)
291+
)
285292
return self.pricer.maturity(ttm).prices(log_strikes)
286293

287294
def plot(

0 commit comments

Comments
 (0)