openqdata 0.3.0__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.
- openqdata-0.3.0/CHANGELOG.md +35 -0
- openqdata-0.3.0/LICENSE +131 -0
- openqdata-0.3.0/MANIFEST.in +10 -0
- openqdata-0.3.0/NOTICE +1 -0
- openqdata-0.3.0/PKG-INFO +103 -0
- openqdata-0.3.0/README.md +60 -0
- openqdata-0.3.0/docs/arbfree.md +109 -0
- openqdata-0.3.0/docs/caching.md +60 -0
- openqdata-0.3.0/docs/conf.py +14 -0
- openqdata-0.3.0/docs/connectors/fred.md +24 -0
- openqdata-0.3.0/docs/connectors/index.md +24 -0
- openqdata-0.3.0/docs/connectors/massive.md +188 -0
- openqdata-0.3.0/docs/connectors/vixdata.md +36 -0
- openqdata-0.3.0/docs/connectors/widb.md +80 -0
- openqdata-0.3.0/docs/connectors/yahoo.md +14 -0
- openqdata-0.3.0/docs/development.md +67 -0
- openqdata-0.3.0/docs/extensions.md +36 -0
- openqdata-0.3.0/docs/getting-started.md +117 -0
- openqdata-0.3.0/docs/glossary.md +23 -0
- openqdata-0.3.0/docs/index.md +53 -0
- openqdata-0.3.0/docs/notebooks.md +25 -0
- openqdata-0.3.0/docs/releasing.md +49 -0
- openqdata-0.3.0/docs/widb-benchmark/fields.md +112 -0
- openqdata-0.3.0/docs/widb-benchmark/fit-quality.md +127 -0
- openqdata-0.3.0/docs/widb-benchmark/forwards.md +92 -0
- openqdata-0.3.0/docs/widb-benchmark/pipeline.md +287 -0
- openqdata-0.3.0/openqdata.example.toml +3 -0
- openqdata-0.3.0/pyproject.toml +48 -0
- openqdata-0.3.0/setup.cfg +4 -0
- openqdata-0.3.0/src/openqdata/README.md +5 -0
- openqdata-0.3.0/src/openqdata/__init__.py +15 -0
- openqdata-0.3.0/src/openqdata/arbfree/README.md +5 -0
- openqdata-0.3.0/src/openqdata/arbfree/__init__.py +9 -0
- openqdata-0.3.0/src/openqdata/arbfree/arbfree.py +1494 -0
- openqdata-0.3.0/src/openqdata/arbfree/sanos.py +316 -0
- openqdata-0.3.0/src/openqdata/arbfree/sanos_tools.py +958 -0
- openqdata-0.3.0/src/openqdata/arbfree/tridiag.py +85 -0
- openqdata-0.3.0/src/openqdata/benchmark/README.md +5 -0
- openqdata-0.3.0/src/openqdata/benchmark/__init__.py +4 -0
- openqdata-0.3.0/src/openqdata/biz_calendar.py +506 -0
- openqdata-0.3.0/src/openqdata/cli.py +91 -0
- openqdata-0.3.0/src/openqdata/env.py +112 -0
- openqdata-0.3.0/src/openqdata/fred/README.md +5 -0
- openqdata-0.3.0/src/openqdata/fred/__init__.py +14 -0
- openqdata-0.3.0/src/openqdata/fred/client.py +57 -0
- openqdata-0.3.0/src/openqdata/fred/rates.py +162 -0
- openqdata-0.3.0/src/openqdata/massive/README.md +5 -0
- openqdata-0.3.0/src/openqdata/massive/__init__.py +15 -0
- openqdata-0.3.0/src/openqdata/massive/client.py +1183 -0
- openqdata-0.3.0/src/openqdata/massive/expiries.py +242 -0
- openqdata-0.3.0/src/openqdata/massive/options/README.md +5 -0
- openqdata-0.3.0/src/openqdata/massive/options/__init__.py +6 -0
- openqdata-0.3.0/src/openqdata/massive/options/contracts.py +610 -0
- openqdata-0.3.0/src/openqdata/massive/processing.py +447 -0
- openqdata-0.3.0/src/openqdata/massive/testing/README.md +5 -0
- openqdata-0.3.0/src/openqdata/massive/testing/__init__.py +8 -0
- openqdata-0.3.0/src/openqdata/massive/testing/generate.py +61 -0
- openqdata-0.3.0/src/openqdata/massive/testing/scope.py +8 -0
- openqdata-0.3.0/src/openqdata/massive/tickers/README.md +5 -0
- openqdata-0.3.0/src/openqdata/massive/tickers/__init__.py +5 -0
- openqdata-0.3.0/src/openqdata/massive/tickers/basics.py +66 -0
- openqdata-0.3.0/src/openqdata/massive/tickers/data.py +362 -0
- openqdata-0.3.0/src/openqdata/massive/tickers/filtered_history.py +260 -0
- openqdata-0.3.0/src/openqdata/massive/trade_conds.py +324 -0
- openqdata-0.3.0/src/openqdata/models/README.md +5 -0
- openqdata-0.3.0/src/openqdata/models/__init__.py +4 -0
- openqdata-0.3.0/src/openqdata/pool.py +34 -0
- openqdata-0.3.0/src/openqdata/tickers/README.md +5 -0
- openqdata-0.3.0/src/openqdata/tickers/__init__.py +13 -0
- openqdata-0.3.0/src/openqdata/tickers/ticker_calendar.py +370 -0
- openqdata-0.3.0/src/openqdata/utils/README.md +3 -0
- openqdata-0.3.0/src/openqdata/utils/__init__.py +35 -0
- openqdata-0.3.0/src/openqdata/utils/cvxpy.py +47 -0
- openqdata-0.3.0/src/openqdata/utils/pd.py +125 -0
- openqdata-0.3.0/src/openqdata/utils/pl.py +114 -0
- openqdata-0.3.0/src/openqdata/vixdata/README.md +5 -0
- openqdata-0.3.0/src/openqdata/vixdata/__init__.py +6 -0
- openqdata-0.3.0/src/openqdata/vixdata/cboe.py +119 -0
- openqdata-0.3.0/src/openqdata/vixdata/client.py +44 -0
- openqdata-0.3.0/src/openqdata/vixdata/formula.py +132 -0
- openqdata-0.3.0/src/openqdata/widb/README.md +5 -0
- openqdata-0.3.0/src/openqdata/widb/__init__.py +25 -0
- openqdata-0.3.0/src/openqdata/widb/arbfree.py +581 -0
- openqdata-0.3.0/src/openqdata/widb/bad.py +69 -0
- openqdata-0.3.0/src/openqdata/widb/client.py +517 -0
- openqdata-0.3.0/src/openqdata/widb/connection.py +72 -0
- openqdata-0.3.0/src/openqdata/widb/day.py +1098 -0
- openqdata-0.3.0/src/openqdata/widb/fitstats.py +328 -0
- openqdata-0.3.0/src/openqdata/widb/options_filter.py +338 -0
- openqdata-0.3.0/src/openqdata/widb/sanos.py +96 -0
- openqdata-0.3.0/src/openqdata/widb/testing/README.md +5 -0
- openqdata-0.3.0/src/openqdata/widb/testing/__init__.py +0 -0
- openqdata-0.3.0/src/openqdata/widb/testing/generate.py +45 -0
- openqdata-0.3.0/src/openqdata/widb/testing/scope.py +8 -0
- openqdata-0.3.0/src/openqdata/widb/timeseries.py +434 -0
- openqdata-0.3.0/src/openqdata/yahoo/README.md +5 -0
- openqdata-0.3.0/src/openqdata/yahoo/__init__.py +8 -0
- openqdata-0.3.0/src/openqdata/yahoo/client.py +229 -0
- openqdata-0.3.0/src/openqdata.egg-info/PKG-INFO +103 -0
- openqdata-0.3.0/src/openqdata.egg-info/SOURCES.txt +144 -0
- openqdata-0.3.0/src/openqdata.egg-info/dependency_links.txt +1 -0
- openqdata-0.3.0/src/openqdata.egg-info/requires.txt +32 -0
- openqdata-0.3.0/src/openqdata.egg-info/top_level.txt +1 -0
- openqdata-0.3.0/tests/arbfree/test_arbfree.py +349 -0
- openqdata-0.3.0/tests/arbfree/test_arbfree_density_projection.py +140 -0
- openqdata-0.3.0/tests/arbfree/test_input_handling.py +50 -0
- openqdata-0.3.0/tests/arbfree/test_market_fit.py +114 -0
- openqdata-0.3.0/tests/arbfree/test_sanos.py +200 -0
- openqdata-0.3.0/tests/arbfree/test_sanos_dlv.py +62 -0
- openqdata-0.3.0/tests/arbfree/test_solver_limits.py +131 -0
- openqdata-0.3.0/tests/conftest.py +41 -0
- openqdata-0.3.0/tests/fred/test_fred_rates.py +62 -0
- openqdata-0.3.0/tests/fred/test_local_rates.py +68 -0
- openqdata-0.3.0/tests/massive/test_client_endpoints.py +184 -0
- openqdata-0.3.0/tests/massive/test_massive_options_contracts.py +123 -0
- openqdata-0.3.0/tests/massive/test_massive_processing.py +92 -0
- openqdata-0.3.0/tests/massive/test_request_safety.py +116 -0
- openqdata-0.3.0/tests/massive/test_ticker_events.py +21 -0
- openqdata-0.3.0/tests/massive/test_trade_conds.py +20 -0
- openqdata-0.3.0/tests/stored_data/.gitignore +7 -0
- openqdata-0.3.0/tests/stored_data/README.md +7 -0
- openqdata-0.3.0/tests/stored_data/processed/.gitkeep +0 -0
- openqdata-0.3.0/tests/stored_data/processed/fred/rates.csv +4 -0
- openqdata-0.3.0/tests/stored_data/processed/yahoo/prices.csv +3 -0
- openqdata-0.3.0/tests/stored_data/raw/.gitkeep +0 -0
- openqdata-0.3.0/tests/stored_data/synthetic_massive.py +157 -0
- openqdata-0.3.0/tests/stored_data/synthetic_widb.py +65 -0
- openqdata-0.3.0/tests/test_cli.py +148 -0
- openqdata-0.3.0/tests/test_docs_examples.py +22 -0
- openqdata-0.3.0/tests/test_environment.py +118 -0
- openqdata-0.3.0/tests/test_extension_namespaces.py +30 -0
- openqdata-0.3.0/tests/test_offline.py +42 -0
- openqdata-0.3.0/tests/tickers/test_calendar_cache.py +43 -0
- openqdata-0.3.0/tests/tickers/test_ticker_calendar.py +61 -0
- openqdata-0.3.0/tests/tickers/test_tickers.py +291 -0
- openqdata-0.3.0/tests/utils/test_biz_calendar.py +192 -0
- openqdata-0.3.0/tests/utils/test_cvxpy_patch.py +26 -0
- openqdata-0.3.0/tests/utils/test_pd.py +144 -0
- openqdata-0.3.0/tests/utils/test_pl.py +137 -0
- openqdata-0.3.0/tests/vixdata/test_cboe.py +100 -0
- openqdata-0.3.0/tests/vixdata/test_formula.py +73 -0
- openqdata-0.3.0/tests/widb/test_client.py +105 -0
- openqdata-0.3.0/tests/widb/test_connection.py +45 -0
- openqdata-0.3.0/tests/widb/test_options_filter_schema.py +31 -0
- openqdata-0.3.0/tests/widb/test_pipeline.py +935 -0
- openqdata-0.3.0/tests/yahoo/test_local_prices.py +194 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- The WIDB pipeline's defaults (`mk_arb_free_day`, `arb_free_model_day`, `filter_options_day`, `TimeSeriesDefinition`, fit statistics) are the benchmark linear fit `fit_config(0)`, so a default call reads the stored data instead of computing a second data set. The reduced set is always selected from that fit.
|
|
6
|
+
- `fitstats` takes `--population`.
|
|
7
|
+
- Fit quality: final SPX results for the full book and the reduced set at all three smoothness levels, with run times.
|
|
8
|
+
- Documentation: a "read one day" example in the README and getting started, expanded `AGENTS.md` (with `CLAUDE.md` pointing to it), cache-version behaviour, storage layout, fit statistics reference, batch-command defaults; examples read with `cacheonly`.
|
|
9
|
+
- Fit objective corrected: the slack of a quote now measures the distance outside bid/ask. It measured the distance from the mid, which also made the per-expiry bid/ask fit infeasible. The mid term is the sum over quotes of the distance from the mid; it was the largest distance per expiry. All fits change; fitter data version 0.58. Every reported statistic counts a price as outside when it is outside the actual bid/ask, with no tolerance.
|
|
10
|
+
- Each stored day fit records how many surface fits it took (`num_surface_fits`) and the share within bid/ask after the first and in the kept fit (`within_first_fit`, `within_kept_fit`); the fit-statistics table counts the reweighted days and the time-series figures mark them in a second colour.
|
|
11
|
+
- `MkArbFree` has reweighting parameters, `reweight_max_iter` and `reweight_min_within`: the surface fit can be repeated with reweighted quotes to raise the share within bid/ask. Off by default.
|
|
12
|
+
- `openqdata.widb.arbfree.fit_config(smoothness)` gives the fit configuration of the benchmark data: mid fit for linear, bid/ask fit with reweighting for 0.1, mid fit with reweighting for 0.25. The batch command and the fit statistics use it.
|
|
13
|
+
- Batch command `openqdata.widb.arbfree`: several option sets, smoothness levels and time limits per call, retries of failed days with longer limits, thread limit per worker, and a timing report.
|
|
14
|
+
- WIDB fits: HiGHS runs first and Clarabel second. A day fit fails, and is not stored, if no point satisfies the constraints or fewer than 25% of quotes are within bid/ask.
|
|
15
|
+
- Fit statistics (`openqdata.widb.fitstats`) evaluate every model on the full book and on the reduced set and report the two separately.
|
|
16
|
+
- Documentation: rewritten pipeline and interpolation-quality pages with SPX results for 2005–2025; new page on forwards, discount factors and WRDS data issues; `call_bid` / `call_ask` are the recommended market quotes.
|
|
17
|
+
- Removed: the experimental JAX backend (`openqdata.jax`, `openqdata.arbfree.sanos_jax`, `openqdata.utils.backbone`, the `backbone` argument of `NormalizedStrikes`) and the `jax` extra. Nothing used it.
|
|
18
|
+
- Dependencies: dropped `h5py` and `sortedcontainers` (not imported; `cdxcore` requires them) and the upper bounds on SQLAlchemy and psycopg2 (the WRDS SDK sets its own).
|
|
19
|
+
- Fixed: `ArbFreePricer.price` truncated prices to integers when given integer strikes.
|
|
20
|
+
- `MkArbFree` checks all quotes before fitting: equal shapes, finite strikes, bids and asks, ask above bid. Infinite quotes were passed to the solver, and NaN quotes failed with a misleading message. Valid inputs fit as before; no version change.
|
|
21
|
+
- Fixed: option cash volume (`approx_cash_vol_prev_k`, `approx_cash_vol_today_k`, and the `min_opt_vol_k` filter of `filter_contracts`) omitted the contract multiplier and was 100 times too small. It is now contracts × `shares_per_contract` × mean of open and close; cache version 0.27.
|
|
22
|
+
- Fixed: the Massive weighted-mid spot tape (`build_unadjusted_spot_wmid`) used crossed, locked, zero-price and non-finite quotes. It now applies the same quote validity rule as `filter_valid_quotes` (`valid_quote_mask`); cache version 0.2.
|
|
23
|
+
- Documentation: getting started opens with what the package provides and a first example without data (executed by the tests); new glossary and notebook index with each notebook's prerequisites; FRED example and zero-rate handling corrected; Sphinx math enabled; CI builds the documentation strictly.
|
|
24
|
+
- Removed: the `--no-arb-mode` batch option, `ArbFreePricer.atm_volatilities`, `SanosLPSolver.simplex_strategy`, `openqdata.utils.testing`, and unused quantile fields of the market-fit result.
|
|
25
|
+
|
|
26
|
+
## 0.2.0
|
|
27
|
+
|
|
28
|
+
First public release of openqdata.
|
|
29
|
+
|
|
30
|
+
- Storage and caching: two configured locations, `raw` and `processed`; versioned caches keyed by scope and configuration; an offline test mode.
|
|
31
|
+
- Connectors, each with a `Client` class: WRDS OptionMetrics IvyDB (`WIDBClient`), Massive (`MassiveClient`), Yahoo Finance (`YFClient`), FRED (`FREDClient`) and Cboe VIX (`CboeClient`).
|
|
32
|
+
- WIDB benchmark data: cleaned daily option quotes with an arbitrage-free SANOS interpolation (`openqdata.widb.sanos.fit_sanos_day`).
|
|
33
|
+
- The `arbfree` toolkit for linear (DLV) and SANOS arbitrage-free option surfaces.
|
|
34
|
+
- Array-based fit diagnostics support masked quotes with or without implied-volatility output.
|
|
35
|
+
- Namespaces for extension packages: `openqdata.models` and `openqdata.benchmark`.
|
openqdata-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree
|
|
8
|
+
to them as both strict obligations and conditions to all
|
|
9
|
+
your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the
|
|
14
|
+
software to do everything you might do with the software
|
|
15
|
+
that would otherwise infringe the licensor's copyright
|
|
16
|
+
in it for any permitted purpose. However, you may
|
|
17
|
+
only distribute the software according to [Distribution
|
|
18
|
+
License](#distribution-license) and make changes or new works
|
|
19
|
+
based on the software according to [Changes and New Works
|
|
20
|
+
License](#changes-and-new-works-license).
|
|
21
|
+
|
|
22
|
+
## Distribution License
|
|
23
|
+
|
|
24
|
+
The licensor grants you an additional copyright license
|
|
25
|
+
to distribute copies of the software. Your license
|
|
26
|
+
to distribute covers distributing the software with
|
|
27
|
+
changes and new works permitted by [Changes and New Works
|
|
28
|
+
License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of
|
|
33
|
+
the software from you also gets a copy of these terms or the
|
|
34
|
+
URL for them above, as well as copies of any plain-text lines
|
|
35
|
+
beginning with `Required Notice:` that the licensor provided
|
|
36
|
+
with the software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to
|
|
43
|
+
make changes and new works based on the software for any
|
|
44
|
+
permitted purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Noncommercial Purposes
|
|
53
|
+
|
|
54
|
+
Any noncommercial purpose is a permitted purpose.
|
|
55
|
+
|
|
56
|
+
## Personal Uses
|
|
57
|
+
|
|
58
|
+
Personal use for research, experiment, and testing for
|
|
59
|
+
the benefit of public knowledge, personal study, private
|
|
60
|
+
entertainment, hobby projects, amateur pursuits, or religious
|
|
61
|
+
observance, without any anticipated commercial application,
|
|
62
|
+
is use for a permitted purpose.
|
|
63
|
+
|
|
64
|
+
## Noncommercial Organizations
|
|
65
|
+
|
|
66
|
+
Use by any charitable organization, educational institution,
|
|
67
|
+
public research organization, public safety or health
|
|
68
|
+
organization, environmental protection organization,
|
|
69
|
+
or government institution is use for a permitted purpose
|
|
70
|
+
regardless of the source of funding or obligations resulting
|
|
71
|
+
from the funding.
|
|
72
|
+
|
|
73
|
+
## Fair Use
|
|
74
|
+
|
|
75
|
+
You may have "fair use" rights for the software under the
|
|
76
|
+
law. These terms do not limit them.
|
|
77
|
+
|
|
78
|
+
## No Other Rights
|
|
79
|
+
|
|
80
|
+
These terms do not allow you to sublicense or transfer any of
|
|
81
|
+
your licenses to anyone else, or prevent the licensor from
|
|
82
|
+
granting licenses to anyone else. These terms do not imply
|
|
83
|
+
any other licenses.
|
|
84
|
+
|
|
85
|
+
## Patent Defense
|
|
86
|
+
|
|
87
|
+
If you make any written claim that the software infringes or
|
|
88
|
+
contributes to infringement of any patent, your patent license
|
|
89
|
+
for the software granted under these terms ends immediately. If
|
|
90
|
+
your company makes such a claim, your patent license ends
|
|
91
|
+
immediately for work on behalf of your company.
|
|
92
|
+
|
|
93
|
+
## Violations
|
|
94
|
+
|
|
95
|
+
The first time you are notified in writing that you have
|
|
96
|
+
violated any of these terms, or done anything with the software
|
|
97
|
+
not covered by your licenses, your licenses can nonetheless
|
|
98
|
+
continue if you come into full compliance with these terms,
|
|
99
|
+
and take practical steps to correct past violations, within
|
|
100
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
101
|
+
end immediately.
|
|
102
|
+
|
|
103
|
+
## No Liability
|
|
104
|
+
|
|
105
|
+
***As far as the law allows, the software comes as is, without
|
|
106
|
+
any warranty or condition, and the licensor will not be liable
|
|
107
|
+
to you for any damages arising out of these terms or the use
|
|
108
|
+
or nature of the software, under any kind of legal claim.***
|
|
109
|
+
|
|
110
|
+
## Definitions
|
|
111
|
+
|
|
112
|
+
The **licensor** is the individual or entity offering these
|
|
113
|
+
terms, and the **software** is the software the licensor makes
|
|
114
|
+
available under these terms.
|
|
115
|
+
|
|
116
|
+
**You** refers to the individual or entity agreeing to these
|
|
117
|
+
terms.
|
|
118
|
+
|
|
119
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
120
|
+
or other kind of organization that you work for, plus all
|
|
121
|
+
organizations that have control over, are under the control of,
|
|
122
|
+
or are under common control with that organization. **Control**
|
|
123
|
+
means ownership of substantially all the assets of an entity,
|
|
124
|
+
or the power to direct its management and policies by vote,
|
|
125
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
126
|
+
|
|
127
|
+
**Your licenses** are all the licenses granted to you for the
|
|
128
|
+
software under these terms.
|
|
129
|
+
|
|
130
|
+
**Use** means anything you do with the software requiring one
|
|
131
|
+
of your licenses.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include CHANGELOG.md
|
|
3
|
+
include openqdata.example.toml
|
|
4
|
+
recursive-include docs *.md *.py
|
|
5
|
+
recursive-include src README.md
|
|
6
|
+
recursive-exclude src *.ipynb
|
|
7
|
+
include LICENSE
|
|
8
|
+
include NOTICE
|
|
9
|
+
graft tests
|
|
10
|
+
recursive-exclude tests __pycache__ *.pyc
|
openqdata-0.3.0/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Required Notice: Copyright 2026 Hans Buehler. openqdata (https://github.com/hansbuehler/openqdata).
|
openqdata-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: openqdata
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Systematic access to cached quantitative market data for academic research
|
|
5
|
+
Author: Hans Buehler
|
|
6
|
+
License-Expression: PolyForm-Noncommercial-1.0.0
|
|
7
|
+
Project-URL: Repository, https://github.com/hansbuehler/openqdata
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Requires-Python: <3.15,>=3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
License-File: NOTICE
|
|
15
|
+
Requires-Dist: cdxcore>=0.1.97
|
|
16
|
+
Requires-Dist: numpy>=1.26
|
|
17
|
+
Requires-Dist: scipy>=1.12
|
|
18
|
+
Requires-Dist: pandas>=2.2
|
|
19
|
+
Requires-Dist: polars>=1
|
|
20
|
+
Requires-Dist: pyarrow
|
|
21
|
+
Requires-Dist: requests
|
|
22
|
+
Requires-Dist: urllib3
|
|
23
|
+
Requires-Dist: prettytable
|
|
24
|
+
Requires-Dist: click>=8
|
|
25
|
+
Requires-Dist: pandas-market-calendars>=4.4
|
|
26
|
+
Requires-Dist: cvxpy
|
|
27
|
+
Requires-Dist: highspy
|
|
28
|
+
Requires-Dist: wrds>=3.2; python_version < "3.14"
|
|
29
|
+
Requires-Dist: sqlalchemy>=2
|
|
30
|
+
Requires-Dist: psycopg2-binary>=2.9
|
|
31
|
+
Requires-Dist: massive>=2.5
|
|
32
|
+
Requires-Dist: yfinance>=1.3
|
|
33
|
+
Provides-Extra: test
|
|
34
|
+
Requires-Dist: pytest>=8.2; extra == "test"
|
|
35
|
+
Requires-Dist: ruff; extra == "test"
|
|
36
|
+
Requires-Dist: build; extra == "test"
|
|
37
|
+
Provides-Extra: docs
|
|
38
|
+
Requires-Dist: sphinx>=8; extra == "docs"
|
|
39
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
40
|
+
Provides-Extra: plot
|
|
41
|
+
Requires-Dist: matplotlib; extra == "plot"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# openqdata
|
|
45
|
+
|
|
46
|
+
Data connectors and processing pipelines with simple, versioned caching, for academic research in quantitative finance. openqdata is not a trading system and provides no investment advice.
|
|
47
|
+
|
|
48
|
+
The package has four parts:
|
|
49
|
+
|
|
50
|
+
1. **Caching and configuration.** Every result is cached under two storage locations, `raw` and `processed`, keyed by its scope and configuration.
|
|
51
|
+
2. **Data connectors.** WRDS OptionMetrics IvyDB (WIDB), Massive, Yahoo Finance, FRED and Cboe VIX. Each source has a `Client` class that holds its authentication and basic access methods.
|
|
52
|
+
3. **The WIDB benchmark data.** Cleaned daily option data from WRDS OptionMetrics IvyDB, together with an arbitrage-free interpolation of each day's quotes. The interpolation is a linear or SANOS surface that prices any strike and maturity.
|
|
53
|
+
4. **The `arbfree` toolkit.** It fits arbitrage-free option surfaces to bid/ask quotes from any source.
|
|
54
|
+
|
|
55
|
+
Targets Python 3.13 and supports Python 3.12–3.14.
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
python -m pip install openqdata # or: pip install -e '.[test]' from a clone
|
|
59
|
+
export OQ_DATA_ROOT=/path/to/your/data # optional; the default is ~/.local/share/openqdata
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Reading one day of the WIDB benchmark data
|
|
63
|
+
|
|
64
|
+
Stored fits are identified by their full configuration. **Always build it with `fit_config(smoothness)`**: `MkArbFree(smoothness=0.1)` has different settings and finds nothing. Read with `override_cache_mode="cacheonly"`, so that a missing day raises instead of being fitted or downloaded.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from datetime import date
|
|
68
|
+
from openqdata.arbfree.arbfree import ArbFreePricer
|
|
69
|
+
from openqdata.widb.arbfree import arb_free_model_day, fit_config
|
|
70
|
+
from openqdata.widb.sanos import fit_sanos_model_day
|
|
71
|
+
|
|
72
|
+
fitted = arb_free_model_day("SPX", date(2025, 8, 28), mk_arb_free=fit_config(0.1), override_cache_mode="cacheonly") # full book
|
|
73
|
+
model, stats = ArbFreePricer.from_dict(fitted["model"]), fitted["stats"]
|
|
74
|
+
reduced = fit_sanos_model_day("SPX", date(2025, 8, 28), fit_config(0.1), override_cache_mode="cacheonly") # reduced set
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Smoothness is `0` (linear), `0.1` or `0.25`. The data are licensed: you need your own WRDS access, and the fits live in your configured data locations, never in Git.
|
|
78
|
+
|
|
79
|
+
### Clients
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from openqdata.widb import WIDBClient
|
|
83
|
+
from openqdata.massive import MassiveClient
|
|
84
|
+
from openqdata.yahoo import YFClient
|
|
85
|
+
from openqdata.fred import FREDClient
|
|
86
|
+
from openqdata.vixdata import CboeClient
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Documentation
|
|
90
|
+
|
|
91
|
+
- [Getting started](https://github.com/hansbuehler/openqdata/blob/main/docs/getting-started.md): installation, storage and credentials
|
|
92
|
+
- [Caching, test mode and commands](https://github.com/hansbuehler/openqdata/blob/main/docs/caching.md)
|
|
93
|
+
- [Data connectors](https://github.com/hansbuehler/openqdata/blob/main/docs/connectors/index.md)
|
|
94
|
+
- [WIDB benchmark data](https://github.com/hansbuehler/openqdata/blob/main/docs/widb-benchmark/pipeline.md), [interpolation quality](https://github.com/hansbuehler/openqdata/blob/main/docs/widb-benchmark/fit-quality.md), [forwards and WRDS data issues](https://github.com/hansbuehler/openqdata/blob/main/docs/widb-benchmark/forwards.md) and [field reference](https://github.com/hansbuehler/openqdata/blob/main/docs/widb-benchmark/fields.md)
|
|
95
|
+
- [The arbfree toolkit](https://github.com/hansbuehler/openqdata/blob/main/docs/arbfree.md)
|
|
96
|
+
- [Extension packages](https://github.com/hansbuehler/openqdata/blob/main/docs/extensions.md)
|
|
97
|
+
- [Development and testing](https://github.com/hansbuehler/openqdata/blob/main/docs/development.md), [releasing](https://github.com/hansbuehler/openqdata/blob/main/docs/releasing.md) and the [changelog](https://github.com/hansbuehler/openqdata/blob/main/CHANGELOG.md)
|
|
98
|
+
|
|
99
|
+
## Licensing and data
|
|
100
|
+
|
|
101
|
+
The code is licensed under [PolyForm Noncommercial 1.0.0](https://github.com/hansbuehler/openqdata/blob/main/LICENSE), with the attribution in [NOTICE](https://github.com/hansbuehler/openqdata/blob/main/NOTICE). Dependency and provider-data licenses are separate. This software license grants no rights to redistribute licensed observations or derived datasets.
|
|
102
|
+
|
|
103
|
+
This repository contains no licensed observations or datasets. Offline tests use synthetic inputs. To run the examples you need your own access to each provider.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# openqdata
|
|
2
|
+
|
|
3
|
+
Data connectors and processing pipelines with simple, versioned caching, for academic research in quantitative finance. openqdata is not a trading system and provides no investment advice.
|
|
4
|
+
|
|
5
|
+
The package has four parts:
|
|
6
|
+
|
|
7
|
+
1. **Caching and configuration.** Every result is cached under two storage locations, `raw` and `processed`, keyed by its scope and configuration.
|
|
8
|
+
2. **Data connectors.** WRDS OptionMetrics IvyDB (WIDB), Massive, Yahoo Finance, FRED and Cboe VIX. Each source has a `Client` class that holds its authentication and basic access methods.
|
|
9
|
+
3. **The WIDB benchmark data.** Cleaned daily option data from WRDS OptionMetrics IvyDB, together with an arbitrage-free interpolation of each day's quotes. The interpolation is a linear or SANOS surface that prices any strike and maturity.
|
|
10
|
+
4. **The `arbfree` toolkit.** It fits arbitrage-free option surfaces to bid/ask quotes from any source.
|
|
11
|
+
|
|
12
|
+
Targets Python 3.13 and supports Python 3.12–3.14.
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
python -m pip install openqdata # or: pip install -e '.[test]' from a clone
|
|
16
|
+
export OQ_DATA_ROOT=/path/to/your/data # optional; the default is ~/.local/share/openqdata
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Reading one day of the WIDB benchmark data
|
|
20
|
+
|
|
21
|
+
Stored fits are identified by their full configuration. **Always build it with `fit_config(smoothness)`**: `MkArbFree(smoothness=0.1)` has different settings and finds nothing. Read with `override_cache_mode="cacheonly"`, so that a missing day raises instead of being fitted or downloaded.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from datetime import date
|
|
25
|
+
from openqdata.arbfree.arbfree import ArbFreePricer
|
|
26
|
+
from openqdata.widb.arbfree import arb_free_model_day, fit_config
|
|
27
|
+
from openqdata.widb.sanos import fit_sanos_model_day
|
|
28
|
+
|
|
29
|
+
fitted = arb_free_model_day("SPX", date(2025, 8, 28), mk_arb_free=fit_config(0.1), override_cache_mode="cacheonly") # full book
|
|
30
|
+
model, stats = ArbFreePricer.from_dict(fitted["model"]), fitted["stats"]
|
|
31
|
+
reduced = fit_sanos_model_day("SPX", date(2025, 8, 28), fit_config(0.1), override_cache_mode="cacheonly") # reduced set
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Smoothness is `0` (linear), `0.1` or `0.25`. The data are licensed: you need your own WRDS access, and the fits live in your configured data locations, never in Git.
|
|
35
|
+
|
|
36
|
+
### Clients
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from openqdata.widb import WIDBClient
|
|
40
|
+
from openqdata.massive import MassiveClient
|
|
41
|
+
from openqdata.yahoo import YFClient
|
|
42
|
+
from openqdata.fred import FREDClient
|
|
43
|
+
from openqdata.vixdata import CboeClient
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Documentation
|
|
47
|
+
|
|
48
|
+
- [Getting started](https://github.com/hansbuehler/openqdata/blob/main/docs/getting-started.md): installation, storage and credentials
|
|
49
|
+
- [Caching, test mode and commands](https://github.com/hansbuehler/openqdata/blob/main/docs/caching.md)
|
|
50
|
+
- [Data connectors](https://github.com/hansbuehler/openqdata/blob/main/docs/connectors/index.md)
|
|
51
|
+
- [WIDB benchmark data](https://github.com/hansbuehler/openqdata/blob/main/docs/widb-benchmark/pipeline.md), [interpolation quality](https://github.com/hansbuehler/openqdata/blob/main/docs/widb-benchmark/fit-quality.md), [forwards and WRDS data issues](https://github.com/hansbuehler/openqdata/blob/main/docs/widb-benchmark/forwards.md) and [field reference](https://github.com/hansbuehler/openqdata/blob/main/docs/widb-benchmark/fields.md)
|
|
52
|
+
- [The arbfree toolkit](https://github.com/hansbuehler/openqdata/blob/main/docs/arbfree.md)
|
|
53
|
+
- [Extension packages](https://github.com/hansbuehler/openqdata/blob/main/docs/extensions.md)
|
|
54
|
+
- [Development and testing](https://github.com/hansbuehler/openqdata/blob/main/docs/development.md), [releasing](https://github.com/hansbuehler/openqdata/blob/main/docs/releasing.md) and the [changelog](https://github.com/hansbuehler/openqdata/blob/main/CHANGELOG.md)
|
|
55
|
+
|
|
56
|
+
## Licensing and data
|
|
57
|
+
|
|
58
|
+
The code is licensed under [PolyForm Noncommercial 1.0.0](https://github.com/hansbuehler/openqdata/blob/main/LICENSE), with the attribution in [NOTICE](https://github.com/hansbuehler/openqdata/blob/main/NOTICE). Dependency and provider-data licenses are separate. This software license grants no rights to redistribute licensed observations or derived datasets.
|
|
59
|
+
|
|
60
|
+
This repository contains no licensed observations or datasets. Offline tests use synthetic inputs. To run the examples you need your own access to each provider.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# The arbfree toolkit
|
|
2
|
+
|
|
3
|
+
`openqdata.arbfree` fits arbitrage-free option surfaces to bid/ask quotes. The toolkit works on its own: it takes plain arrays and has no dependency on any data source. The [WIDB benchmark data](widb-benchmark/pipeline.md) use it to interpolate cleaned option quotes without arbitrage.
|
|
4
|
+
|
|
5
|
+
## Method
|
|
6
|
+
|
|
7
|
+
The fitter represents each expiry by discrete probability masses on a strike grid. The no-arbitrage conditions are:
|
|
8
|
+
|
|
9
|
+
- non-negative masses with total mass one;
|
|
10
|
+
- mean equal to the forward;
|
|
11
|
+
- a calendar ordering across expiries.
|
|
12
|
+
|
|
13
|
+
All three are linear constraints, so finding a surface inside the bid/ask spread is a linear program. For the linear surface, a fit inside bid/ask exists, up to numerical precision, if and only if the quotes are free of arbitrage. A smooth surface is more restrictive and can miss quotes that are free of arbitrage.
|
|
14
|
+
|
|
15
|
+
- **Linear (DLV, discrete local volatility) surface:** `smoothness=None` or `0`. See [SSRN 2642630](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2642630) and [arXiv:2211.13227](https://arxiv.org/abs/2211.13227).
|
|
16
|
+
- **SANOS surface:** `smoothness > 0`. A smooth, arbitrage-free, non-parametric option surface, following [SANOS](https://arxiv.org/abs/2601.11209). The strike range is extended per remark 2.7 of that paper.
|
|
17
|
+
|
|
18
|
+
All inputs use forward-normalized, undiscounted coordinates: the strike is `k = K/F` and the call price is `c = C/(DF·F)`. Maturities are year fractions.
|
|
19
|
+
|
|
20
|
+
## Classes
|
|
21
|
+
|
|
22
|
+
| Object | Role |
|
|
23
|
+
|---|---|
|
|
24
|
+
| `arbfree.MkArbFree` | Frozen configuration and fitter. Calling it with `expiries, strikes, bids, asks` returns an `ArbFreePricer`. |
|
|
25
|
+
| `arbfree.ArbFreePricer` | The fitted surface: `price(...)`, `compute_market_fit(...)`, `interpolate_atm_vols(...)`, `to_dict()` / `from_dict()`. |
|
|
26
|
+
| `sanos.SanosFitter`, `sanos_tools.SanosPricer` | Stand-alone SANOS fitter and pricer on a fixed model grid. |
|
|
27
|
+
| `sanos_tools.SanosLPSolver` | LP backend with time limits and density repair. It runs HiGHS (simplex for linear fits, interior point for smooth surfaces) and falls back to Clarabel if HiGHS returns no usable point. An early-stopped iterate is accepted only when it verifiably satisfies every constraint. |
|
|
28
|
+
| `tridiag.solve_sanos_tridiagonal` | Banded solver for SANOS transition operators. |
|
|
29
|
+
|
|
30
|
+
`MkArbFree` works in two modes:
|
|
31
|
+
|
|
32
|
+
- **`no_arb_mode="expiry"`** fits each expiry on its own. Strikes that cannot be fitted inside bid/ask are masked; an expiry is dropped if fewer than half of its strikes can be fitted.
|
|
33
|
+
- **`no_arb_mode="surface"`** (the default) then fits a globally arbitrage-free surface.
|
|
34
|
+
|
|
35
|
+
Before fitting it adds one strike below and one above the quotes, where the call is at intrinsic value, by extending the outermost prices; boundary strikes whose slope does not allow this are trimmed, and the fit fails with an error if none does. Expiries with fewer than `min_strikes_per_expiry` strikes are dropped.
|
|
36
|
+
|
|
37
|
+
In the surface fit, if the first solver stops early with fewer than 90% of quotes inside bid/ask, `MkArbFree` runs Clarabel as well. It keeps the Clarabel result if that is optimal or has more quotes inside bid/ask, and the first result otherwise.
|
|
38
|
+
|
|
39
|
+
### Objective
|
|
40
|
+
|
|
41
|
+
The surface fit minimizes `(1 − w) · Σᵢ eᵢ + w · Σᵢ |fitᵢ − midᵢ| / hᵢ` over all quotes, with `w = mid_fit_weight`. `eᵢ` is the distance of quote `i` outside bid/ask divided by `hᵢ`, the half-spread floored at `min_half_spread`. The first term keeps the fit inside bid/ask; the second pulls it towards the mid.
|
|
42
|
+
|
|
43
|
+
| Parameter | Default | Meaning |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `smoothness` | `None` | SANOS smoothness η: the smoothing kernel has volatility `√η` times the at-the-money volatility. `None` for linear (`0` is converted to `None`); for example `0.1` or `0.25`. |
|
|
46
|
+
| `surface_expiry_linear` | `True` | Keep the per-expiry step linear when fitting a smooth surface. |
|
|
47
|
+
| `mid_fit_weight` | `0.1` | Weight `w` of the objective, which selects the method: 1 fits the mids only, has fewer variables and is the fastest; a small value fits to the bid/ask. |
|
|
48
|
+
| `reweight_max_iter` | `1` | Maximum number of surface fits. Above 1, the fit is repeated with reweighted quotes; see below. |
|
|
49
|
+
| `reweight_min_within` | `0.9` | Reweighting stops once this share of quotes is within bid/ask. |
|
|
50
|
+
| `min_half_spread` | `1e-4` | Spread floor for weighting and error statistics, in normalized units. |
|
|
51
|
+
| `min_dlv`, `max_dlv` | `None` | Optional bounds on discrete local volatility. |
|
|
52
|
+
| `timeout_seconds` | `300` | Solver time limit per fit, in seconds. It is excluded from the cache key. |
|
|
53
|
+
|
|
54
|
+
`no_arb_mode`, `min_atm_vol`, `min_strikes_per_expiry`, `min_density` and `min_dC_eps` are expert settings described in the class. All fields except `timeout_seconds` are part of the cache key. For the WIDB benchmark data use `openqdata.widb.arbfree.fit_config(smoothness)`, not the defaults of this class; see [default settings per smoothness](widb-benchmark/pipeline.md#default-settings-per-smoothness).
|
|
55
|
+
|
|
56
|
+
### Reweighting
|
|
57
|
+
|
|
58
|
+
A single fit minimizes summed distances, not the number of quotes outside bid/ask. When the surface cannot reach every quote, it spreads the shortfall over many small misses. Reweighting targets the count instead:
|
|
59
|
+
|
|
60
|
+
1. Fit once with all quotes weighted equally.
|
|
61
|
+
2. Weight each quote by `1 / (excess + 0.1)`, with its excess from the previous fit in half-spreads, and fit again. Quotes that are inside or nearly inside become expensive to miss; quotes far outside become cheap.
|
|
62
|
+
3. Repeat until `reweight_min_within` of the quotes are within bid/ask, a fit gains less than 0.25 points, or `reweight_max_iter` fits are done. The fit with the highest share within bid/ask is kept.
|
|
63
|
+
|
|
64
|
+
The weights multiply the distance outside bid/ask, or the distance from the mid when `mid_fit_weight` is 1. Reweighting raises the share within bid/ask and worsens the fit of the quotes that stay outside, so the mean excess of those quotes rises. Each further fit costs about as much as the first.
|
|
65
|
+
|
|
66
|
+
## Example
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import numpy as np
|
|
70
|
+
from scipy.stats import norm
|
|
71
|
+
from cdxcore.verbose import Context
|
|
72
|
+
from openqdata.arbfree.arbfree import ArbFreePricer, MkArbFree
|
|
73
|
+
|
|
74
|
+
def bs_call(k, vol, t): # undiscounted call on a unit forward
|
|
75
|
+
sd = vol * np.sqrt(t)
|
|
76
|
+
d1 = -np.log(k) / sd + 0.5 * sd
|
|
77
|
+
return norm.cdf(d1) - k * norm.cdf(d1 - sd)
|
|
78
|
+
|
|
79
|
+
expiries = np.array([0.1, 0.25, 0.5, 1.0])
|
|
80
|
+
strikes, bids, asks = [], [], []
|
|
81
|
+
for t in expiries:
|
|
82
|
+
k = np.linspace(0.8, 1.2, 21)
|
|
83
|
+
mid = bs_call(k, 0.2 - 0.1 * np.log(k), t) # a simple skew
|
|
84
|
+
half = np.maximum(0.02 * mid, 2e-4)
|
|
85
|
+
strikes.append(k); bids.append(mid - half); asks.append(mid + half)
|
|
86
|
+
|
|
87
|
+
model = MkArbFree(smoothness=0.1)(expiries=expiries, strikes=strikes, bids=bids, asks=asks,
|
|
88
|
+
verbose=Context.quiet)
|
|
89
|
+
fit = model.compute_market_fit(expiries=expiries, strikes=strikes, bids=bids, asks=asks, and_vols=False)
|
|
90
|
+
prices, vols = model.price(np.array([[0.3]]), strikes=np.array([[0.9, 1.0, 1.1]]),
|
|
91
|
+
mode="surface", and_vols=True)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`compute_market_fit` reports `pcnt_fit`, which despite its name is the **fraction of quotes outside** bid/ask. It also reports `mean_err` and `median_err`, the excess outside bid/ask in half-spread units, conditional on being outside. In this example `pcnt_fit` is `0.0`.
|
|
95
|
+
|
|
96
|
+
## Saving and reloading
|
|
97
|
+
|
|
98
|
+
`to_dict()` returns plain NumPy data that can be written as HDF5. `from_dict()` restores the pricer without recalibrating:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from cdxcore.subdir import SubDir
|
|
102
|
+
from openqdata import env
|
|
103
|
+
|
|
104
|
+
store = env.locations.processed("examples/arbfree", fmt=SubDir.PYTREE_HDF5)
|
|
105
|
+
store.write("model", model.to_dict())
|
|
106
|
+
restored = ArbFreePricer.from_dict(store.read("model"))
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The [field reference](widb-benchmark/fields.md#saved-model-parameters) describes every saved field.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Caching, test mode and commands
|
|
2
|
+
|
|
3
|
+
## Caching
|
|
4
|
+
|
|
5
|
+
Cached functions in openqdata use `cdxcore`'s `SubDir.cache`. Each cache entry is identified by two kinds of arguments:
|
|
6
|
+
|
|
7
|
+
- **Scope** arguments say *what* is computed, for example the ticker and the date. They appear directly in the file path.
|
|
8
|
+
- **Configuration** arguments say *how* it is computed. They are frozen dataclasses such as `RawDayFilter`, `ExpiryFilter`, `MkArbFree` or `OptionsFilter`, and they enter the path as a short label plus a hash.
|
|
9
|
+
|
|
10
|
+
Operational arguments, such as worker pools, verbosity and timeouts, do not affect the key.
|
|
11
|
+
|
|
12
|
+
Every cached function and configuration also carries a `@version`. Changing that version, or the version of anything it declares as a dependency, makes the existing entries stale. What happens then depends on the cache mode:
|
|
13
|
+
|
|
14
|
+
- In mode `on` (the default) a read **deletes the stale entry and recomputes it**, which can mean downloading from the provider or refitting for an hour.
|
|
15
|
+
- In mode `cacheonly` the read raises instead.
|
|
16
|
+
|
|
17
|
+
So analysis of existing data should read with `cacheonly`, and a version change to the WIDB fitter (`MkArbFree`) or the day pipeline invalidates days of refitting; it is decided deliberately, not as a side effect.
|
|
18
|
+
|
|
19
|
+
Pass `override_cache_mode=...` to a cached function, or set `cache_mode`/`OQ_DATA_CACHE_MODE` globally:
|
|
20
|
+
|
|
21
|
+
| Mode | Behaviour |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `on` | Read a compatible entry, or compute and write it (the default). |
|
|
24
|
+
| `off` | Compute without reading or writing. |
|
|
25
|
+
| `update` | Compute and overwrite. |
|
|
26
|
+
| `readonly` | Read if present; compute without writing otherwise. |
|
|
27
|
+
| `cacheonly` | Read only. Raise on a missing or incompatible entry; never download or compute. |
|
|
28
|
+
| `gen`, `clear` | Advanced `cdxcore` modes; see its documentation. |
|
|
29
|
+
|
|
30
|
+
A cached function identifies its inputs by scope and configuration, not by the content of a frame you pass in. If you pass an edited frame, use `override_cache_mode="off"` so that an existing entry cannot override your edits.
|
|
31
|
+
|
|
32
|
+
## Test mode
|
|
33
|
+
|
|
34
|
+
Set `OQ_DATA_TEST_MODE=1` to read only from existing fixture caches:
|
|
35
|
+
|
|
36
|
+
- Every cached call runs in `cacheonly` mode.
|
|
37
|
+
- Every provider entry point (`require_live`) refuses to run.
|
|
38
|
+
- `OQ_DATA_TEST_ROOT` must point to a directory that contains `raw/` and `processed/`.
|
|
39
|
+
|
|
40
|
+
The offline test suite uses this mode. Generating fixtures is always a separate, explicit live operation with an external data root.
|
|
41
|
+
|
|
42
|
+
## Commands
|
|
43
|
+
|
|
44
|
+
Processing modules and client modules can be run from the command line:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
python -m openqdata.fred.rates --help
|
|
48
|
+
python -m openqdata.widb.day --help
|
|
49
|
+
python -m openqdata.massive.client --help
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Public functions take keyword arguments as JSON through `--params`. Client methods are invoked as `Client.method`, with optional constructor arguments in `--init-params`. Credential helpers are never exposed. Dates are ISO strings.
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
python -m openqdata.fred.rates load_fred_rates \
|
|
56
|
+
--params '{"start":"2022-01-01","end":"2022-02-01"}' \
|
|
57
|
+
--output /tmp/rates.parquet
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Outside test mode, this can download data. `--output` must be outside the Git working tree. Some modules, such as `openqdata.widb.day` and `openqdata.widb.arbfree`, have their own batch commands. Configuration dataclasses and numerical classes are Python APIs only.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Minimal Sphinx/MyST documentation scaffold."""
|
|
2
|
+
import tomllib
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
metadata = tomllib.loads((Path(__file__).resolve().parents[1] / "pyproject.toml").read_text())["project"]
|
|
6
|
+
project = metadata["name"]
|
|
7
|
+
release = metadata["version"]
|
|
8
|
+
extensions = ["myst_parser", "sphinx.ext.autodoc"]
|
|
9
|
+
source_suffix = {".md": "markdown"}
|
|
10
|
+
master_doc = "index"
|
|
11
|
+
exclude_patterns = ["_build"]
|
|
12
|
+
myst_heading_anchors = 3 # resolve page.md#heading links between pages
|
|
13
|
+
myst_enable_extensions = ["dollarmath"] # $...$ in the Massive page
|
|
14
|
+
html_theme = "alabaster"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# FRED
|
|
2
|
+
|
|
3
|
+
`openqdata.fred` downloads short-term US rates from [FRED](https://fred.stlouisfed.org). Set `FRED_API_KEY` to a [FRED API key](https://fred.stlouisfed.org/docs/api/api_key.html).
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from datetime import date
|
|
7
|
+
from openqdata.fred import FREDClient
|
|
8
|
+
|
|
9
|
+
client = FREDClient()
|
|
10
|
+
rates = client.load_rates("2024-01-02", "2024-03-28") # cached
|
|
11
|
+
sofr = client.fetch_series("SOFR", date(2024, 1, 2), date(2024, 3, 28)) # one series, uncached
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Both calls download from FRED unless the data are cached.
|
|
15
|
+
|
|
16
|
+
`load_rates` (also available as `openqdata.fred.load_fred_rates`) returns these columns:
|
|
17
|
+
|
|
18
|
+
- `date`;
|
|
19
|
+
- `sofr`, `effr`, `dgs1mo`, `dgs3mo` and `dgs6mo`, as `Float32` decimals (`0.05` means 5%);
|
|
20
|
+
- `on`, the overnight rate: SOFR when available, otherwise EFFR, otherwise the one-month Treasury rate.
|
|
21
|
+
|
|
22
|
+
Dates without any observed rate are dropped; observed zero and negative rates are kept. The rate columns are then forward-filled.
|
|
23
|
+
|
|
24
|
+
FRED accepts the API key only as a URL parameter. openqdata removes it from request error messages.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Data connectors
|
|
2
|
+
|
|
3
|
+
Each data source is a subpackage with a `Client` class. They all follow the same pattern:
|
|
4
|
+
|
|
5
|
+
| Element | Convention |
|
|
6
|
+
|---|---|
|
|
7
|
+
| Authentication | Read lazily from the provider's own environment variable by a static helper (`credentials()`, `get_token()`, `api_key()`). It is called only when the client first needs network access. |
|
|
8
|
+
| Live-access guard | Every network entry point calls `env.require_live(...)`. It refuses to run in [test mode](../caching.md#test-mode). |
|
|
9
|
+
| Storage | `Client.locations` gives the source's `raw` and `processed` subdirectories below the configured roots. |
|
|
10
|
+
| Caching | Fetch and processing methods are cached and versioned by scope and configuration. See [caching](../caching.md). |
|
|
11
|
+
| Commands | Public client methods are available as `python -m openqdata.<source>.client Client.method --params '{...}'`. Credential helpers are never exposed. |
|
|
12
|
+
|
|
13
|
+
| Source | Client | Data | Credentials |
|
|
14
|
+
|---|---|---|---|
|
|
15
|
+
| [WIDB](widb.md) | `openqdata.widb.WIDBClient` | WRDS OptionMetrics IvyDB: option quotes, spot, forwards, zero curves | `WRDS_USERNAME`, `.pgpass` |
|
|
16
|
+
| [Massive](massive.md) | `openqdata.massive.MassiveClient` | Stock and option trades, quotes, bars, contracts, corporate actions | `MASSIVE_TOKEN` |
|
|
17
|
+
| [Yahoo Finance](yahoo.md) | `openqdata.yahoo.YFClient` | Price history, dividends, earnings dates | none |
|
|
18
|
+
| [FRED](fred.md) | `openqdata.fred.FREDClient` | SOFR, EFFR and short Treasury rates | `FRED_API_KEY` |
|
|
19
|
+
| [Cboe VIX](vixdata.md) | `openqdata.vixdata.CboeClient` | Official daily VIX history; discrete VIX formula | none |
|
|
20
|
+
|
|
21
|
+
Some modules derive data from these connectors:
|
|
22
|
+
|
|
23
|
+
- **Ticker calendars.** `openqdata.tickers` combines Massive and Yahoo data into standard expiries, dividend and split flags, and earnings dates. See `build_ticker_calendar`.
|
|
24
|
+
- **Business-day calendar.** `openqdata.biz_calendar` provides NYSE business days, half days and two normalized-moneyness scales, both with log-strike scale `log(1.1)`: `NMS`, regularized over about one hour (1/8 of a business day), and `NMS5`, regularized over five business days. The Massive contract filter uses `NMS`; the WIDB pipeline's `nms` and `nms_atm` fields use `NMS5`.
|