Metadata-Version: 2.5
Name: hfvol
Version: 0.1.0
Summary: sktime-compatible realized variance, bipower and jump variation, Hawkes intensity transformers and a HAR-RV forecaster, on plain numpy functions. Carved out of srfm-lab.
Project-URL: Homepage, https://github.com/Mattbusel/hfvol
Project-URL: Repository, https://github.com/Mattbusel/hfvol
Project-URL: Documentation, https://github.com/Mattbusel/hfvol/tree/main/docs
Project-URL: Changelog, https://github.com/Mattbusel/hfvol/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/Mattbusel/hfvol/issues
Project-URL: Upstream (srfm-lab), https://github.com/Mattbusel/srfm-lab
Author: Matthew Busel
License-Expression: MIT
License-File: LICENSE
License-File: NOTICE
Keywords: bipower-variation,har-rv,hawkes-process,high-frequency,jump-variation,market-microstructure,quantitative-finance,realized-variance,realized-volatility,sktime,time-series,volatility-forecasting
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.22
Provides-Extra: scipy
Requires-Dist: scipy>=1.8; extra == 'scipy'
Provides-Extra: sktime
Requires-Dist: scipy>=1.8; extra == 'sktime'
Requires-Dist: sktime>=1.0; extra == 'sktime'
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Requires-Dist: scipy>=1.8; extra == 'test'
Description-Content-Type: text/markdown

# hfvol

Realized variance, bipower variation, jump variation, Hawkes intensity and the
HAR-RV forecaster, as sktime estimators on top of plain numpy functions.

```
pip install hfvol            # numpy functions only
pip install "hfvol[sktime]"  # plus the sktime transformers and forecaster
```

## Why

sktime has a Hurst-exponent transformer but no realized measures and no Hawkes
process. The main Python Hawkes library (`tick`) needs a C++ build. hfvol fills
both gaps with small numpy code that passes sktime's own
`check_estimator` suite.

## sktime

```python
import numpy as np, pandas as pd
from hfvol import RealizedVariance, BipowerVariation, JumpVariation, HARForecaster

# 5-minute returns, 78 bars per session, DatetimeIndex
idx = pd.date_range("2024-01-02 09:35", periods=78 * 250, freq="5min")
r = pd.Series(np.random.default_rng(0).normal(0, 1e-3, len(idx)), index=idx)

rv = RealizedVariance(freq=78).fit_transform(r)  # one value per session
bv = BipowerVariation(freq=78).fit_transform(r)  # jump-robust
jv = JumpVariation(freq=78).fit_transform(r)  # max(RV - BV, 0)

f = HARForecaster().fit(rv.reset_index(drop=True))
f.predict(fh=[1, 5, 22])
```

`freq` is either an integer number of bars per period or a pandas offset alias
(`"D"`, `"W"`, ...) that groups a DatetimeIndex by calendar period. Multivariate
frames give one column per asset; Panel and hierarchical data work through
sktime's usual vectorization.

```python
from hfvol import HawkesIntensity

# trade counts per second; the intensity at each second uses only earlier trades
lam = HawkesIntensity(method="mle", time_unit="1s", random_state=0).fit_transform(counts)
```

## numpy

```python
from hfvol import (
    realized_variance,
    bipower_variation,
    jump_variation,
    fit_har,
    har_forecast,
    HawkesParams,
    hawkes_simulate,
    fit_hawkes_mle,
    hawkes_residual_analysis,
)

events = hawkes_simulate(HawkesParams(mu=0.5, alpha=0.8, beta=1.6), T=5000, rng=1)
params, ll = fit_hawkes_mle(events, T=5000, rng=0)
params.branching_ratio  # about 0.5
hawkes_residual_analysis(events, 5000, params)["well_fit"]
```

## More

- [API reference](api.md)
- [Formulas and references](methods.md)
- [Where this came from](provenance.md)
- [Ecosystem plan (sktime, OpenBB)](ecosystem.md)
- Examples: `examples/`

MIT licensed. Carved out of [srfm-lab](https://github.com/Mattbusel/srfm-lab).
