cotmetrics
Turn raw COT (Commitments of Traders) data into positioning metrics and trading
signals — the positioning index, concentration / clustering / position-size,
reversal signals, and the CotIndexer that assembles per-instrument weekly panels.
Split out of the cot-analyzer dashboard so the metrics layer installs without the
Dash/Plotly UI stack. Reads prices and COT from the shared
cotdata store.
Install
pip install cotmetrics
This pulls in cotdata, the data layer beneath
it. cotmetrics computes metrics over a populated cotdata store — point
COTDATA_STORE at one before you can read real prices/COT (see
cotdata for how to build the store). Optional
extras: pip install "cotmetrics[options]" (max-pain options snapshots via yfinance).
Use
import cotmetrics # flat metric fns, side-effect-free import
from cotmetrics.indexer import get_indexer, boot_options_update
from cotmetrics.signals import append_trading_signals
cotmetrics.calculate_cot_index(...)
import cotmetrics is side-effect-free. get_indexer() constructs (and caches) the
CotIndexer, which loads the store on first use; the daily options fetch runs only
when you call boot_options_update() explicitly.
Config / paths
| env | meaning | default |
|---|---|---|
COTDATA_STORE |
shared price/COT store (from cotdata) | required |
COTMETRICS_CACHE |
derived per-instrument parquet cache | ~/.cache/cotmetrics |
COTMETRICS_CITPY |
CIT PY research notes (dated .md/.txt), persistent data not a cache. Point it at the generating tool's output dir, never inside COTDATA_STORE |
~/.local/share/cotmetrics/citpy |
COTMETRICS_PARAMS |
instrument/params config | packaged sample params.yaml |
COTMETRICS_DATA |
working dir for real_test_data (fixture) exports | <cache>/../cotmetrics_data |
The packaged params.yaml is a small generic sample (a handful of well-known
symbols, untuned 52-week lookbacks) so cotmetrics runs out of the box. For a real
instrument universe and any tuned parameters, set COTMETRICS_PARAMS to your own
config file.
Each instrument carries NpfLookbackWeeks, a per-market window that every frame
computes the full lookback family on, under the column infix NPF ("Comm NPF Idx",
"Comm NPF Zscore", ...) and the lookback argument "NPF". Fixed windows (26, 52)
come from Lookbacks, and an optional CmrLookbackWeeks adds the CMR family.
Deprecated in 0.19.0, removal not before 0.20.0: the NPF table was called Custom.
Until removal, CustomLookbackWeeks is still read when NpfLookbackWeeks is absent (a
file carrying both with different values is refused), frames also carry an identical
copy of the family under the old Custom infix ("Comm Custom Idx"), the lookback
argument "Custom" is accepted wherever "NPF" is, Instrument.custom_lookback
aliases npf_lookback, and the old constants (COMM_CUSTOM_IDX, ...) resolve to the
new columns. Each of these emits a DeprecationWarning. Values are identical under
both names.
Scheduling (weekly COT refresh + email)
COT data is produced by cotdata, not here. cotmetrics only reads the shared store, so
refresh COT on the schedule cotdata documents (see the "Scheduling on Linux (cron)"
section of the cotdata README:
cotdata-update --cot-all, run through the CFTC's Friday ~3:30pm ET release window).
scripts/cron_update.sh wraps that refresh and emails the weekly report only when the
COT report date actually advances. It takes its config from the environment (no paths
baked in), so point the crontab at it:
# Friday afternoon (times in ET): refresh COT, email the report only if new data landed.
*/2 15-16 * * 5 COTDATA_STORE=/path/to/store /path/to/cotmetrics/scripts/cron_update.sh >> /path/to/cot.log 2>&1
| env | meaning | default |
|---|---|---|
COTDATA_STORE |
shared cotdata store | required |
COTDATA_UPDATE |
the cotdata-update binary |
cotdata-update on PATH |
The script reads status.json's newest_data.cot_legacy before and after the update and
runs scripts/generate-weekly-report-email.sh only on a change, so re-running across the
release window is a harmless no-op until the CFTC zip lands.
This route suits a box that produces COT. It runs cotdata-update itself, so on a
box whose store is a replica fed by a producer push, it would make a second producer
racing that push. Such a box has no download to trigger on, and should instead let the
consuming app send: cot-analyzer's store poller notices status.json advancing and
calls cotmetrics.weekly_email in-process, guarded by an opt-in flag and a ledger so it
sends once per COT week. Sending in-process also means the email inherits the app's own
COTMETRICS_PARAMS, which is worth more than it sounds: unset, that silently resolves
to the 6-symbol SAMPLE universe, and an email covering six markets looks exactly like an
email covering forty-seven.
Sending it directly
scripts/generate-weekly-report-email.py sends one now, and is a thin CLI over
cotmetrics.weekly_email.send_weekly_matrix_email. It reads three variables from the
environment of the process invoking it and loads no .env of its own:
| env | meaning |
|---|---|
EMAIL_USER |
the sending account |
RECEIVER_EMAIL_USER |
where the report goes |
EMAIL_PASSWORD |
an app password, not the account password |
The subject line names the COT week the matrix carries, not the day the send ran.
Development (from source)
Developed alongside its sibling repos in a shared workspace, with cotdata installed
editable rather than from PyPI:
git clone https://github.com/mspinola/cotmetrics
pip install -e ../cotdata -e ".[options,dev]"
export COTDATA_STORE=~/code/cotdata_store # shared data store
pytest
Docs
- Two properties of positioning series that break naive statistics on them. Percentile exceedances arrive in episodes, so a count of them is not a sample size; and correlating positioning levels is spurious, because the series is near unit-root. Worth reading before computing a standard error, a p-value, or a correlation on anything this package emits.
License
MIT — see LICENSE.
Metadata
Release files for cotmetrics 0.19.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cotmetrics-0.19.0.tar.gz | 239.0 kB | With provenance | Details for cotmetrics-0.19.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cotmetrics-0.19.0-py3-none-any.whl | Python 3 | none | any | Details for cotmetrics-0.19.0-py3-none-any.whl |
Total release size: 409.3 kB
Release files / cotmetrics-0.19.0.tar.gz
| Download URL | cotmetrics-0.19.0.tar.gz |
|---|---|
| Size | 239.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
859ea7b92b698ee4e3f6d5b567f1b909b611fb7661851825a674c2f1990c60e0
|
|
BLAKE2b-256 checksum How to use checksums |
c6fe139ebeb8eea7975fd825e34e0ffa8b0368bab0f0f8612163fa11c53512f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / cotmetrics-0.19.0-py3-none-any.whl
| Download URL | cotmetrics-0.19.0-py3-none-any.whl |
|---|---|
| Size | 170.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9da0abc77aeeb6bfe58e65b437bc839ad253d3816d2f15f760b10f398200d253
|
|
BLAKE2b-256 checksum How to use checksums |
6665e1f26e14db6fae28d339ebd72262c5abbc408ec951c30cb0ad287b6328dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for cotmetrics 0.19.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for cotmetrics-0.19.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.