Skip to content

About

Automated multi-page Streamlit platform and CFTC Legacy Futures scraper tracking weekly institutional non-commercial positioning, side-by-side asset orderflow divergence, and historical order-injection rankings across 21 Forex, Crypto, Equity Index, Metals, and Energy futures.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

37 Commits

Folders and files

Repository files navigation

๐Ÿ›๏ธ CFTC Commitment of Traders (COT) Analytics

An automated multi-page Streamlit platform and CFTC Legacy Futures scraper for tracking weekly institutional non-commercial positioning, side-by-side asset orderflow divergence, and historical order-injection rankings across 21 Forex, Crypto, Equity Index, Metals, and Energy futures contracts.

Overview โ€ข Pages & Features โ€ข Methodology โ€ข 21 Tracked Assets โ€ข Architecture โ€ข Structure โ€ข Setup โ€ข License

Python 3.9+ Streamlit Multi-Page App CFTC Legacy Futures MIT License

21 Futures Contracts Pandas Seaborn Requests Millify French UI Labels Dark Theme


๐Ÿ“‹ Executive Overview

Cot-Reports automates the ingestion and quantitative analysis of weekly Commodity Futures Trading Commission (CFTC) Commitments of Traders (deacot) legacy futures reports. By isolating Non-Commercial (speculative / institutional) long and short futures contracts, the platform enables macro and FX traders to monitor weekly institutional orderflow, spot diverging currency pair positioning, and rank the strongest contract inflows relative to each market's historical distribution.

When launched, the Streamlit home page (0_๐Ÿ“Š_Accueil.py) automatically checks the freshness of local CSV datasets (csv_folder/forex/eur.csv). If datasets are missing or older than 7 days, it invokes main_scraper.py to fetch annual deacot{year}.zip archives directly from cftc.gov, parses all 21 configured contract codes, and updates csv_folder/ on disk.

UI Language Note: While this documentation is written in English, the Streamlit page titles, sidebar links, and explanatory labels in 0_๐Ÿ“Š_Accueil.py, pages/1_โš–๏ธ_Comparateur d'actifs.py, and pages/2_๐Ÿ’ธ_Meilleures_metriques.py are presented in French.


๐Ÿงฉ Application Pages & Features

Page File UI Title (French) Core Analytical Functionality
0_๐Ÿ“Š_Accueil.py Commitments of traders - Datas Auto-freshness check (check_for_updates() triggers download_and_process_cot_data([2025, 2026]) if data is absent or $\ge 7$ days old), COT methodology primer, and Dashboard Options ecosystem links.
pages/1_โš–๏ธ_Comparateur d'actifs.py Comparateur d'actifs financiers Side-by-side weekly institutional positioning comparison for any two of the 21 contracts (default: EUR vs. USD) over a user-selected lookback slider. Renders a seaborn diverging gradient on Net position, zero-aligned positive/negative bars on Change long and Change short, and CSV export buttons.
pages/2_๐Ÿ’ธ_Meilleures_metriques.py Plus grosses injections d'ordres des derniers rapports COT Ranks all 21 assets by the historical significance of their latest weekly orderflow injection, split into Long Injection Rankings (Classement positions long) and Short Injection Rankings (Classement positions short) formatted via millify.
main_scraper.py (CLI / Module Scraper) Downloads annual CFTC deacot{year}.zip bundles, extracts Non-Commercial Long/Short levels and weekly changes, computes Net position, deduplicates dates (DD/MM/YY newest-first), and writes standardized CSVs into csv_folder/<category>/.

๐Ÿงฎ Orderflow Ranking Methodology

1. Standardized Weekly Net Positioning (main_scraper.py)

For each weekly report date $t$, the scraper extracts CFTC Non-Commercial open contracts and computes net positioning:

$$\text{Net Position}_t = \text{Long}_t - \text{Short}_t$$

Each exported CSV stores Date, Long, Short, Change long, Change short, Net position, url_report, and type.

2. Historical Orderflow Injection Ranking (pages/2_๐Ÿ’ธ_Meilleures_metriques.py)

For every historical report row of an asset, ranking() decomposes weekly contract changes into directional buying flow ($\text{total_long} \ge 0$, combining new long entries and short covering) and selling flow ($\text{total_short} \le 0$, combining new short entries and long liquidations):

$$\Delta_{\text{flow}, t} = \text{total_long}_t + \text{total_short}_t = \Delta\text{Long}_t - \Delta\text{Short}_t$$

  1. All historical positive flows ($\Delta_{\text{flow}, t} \ge 0$) are sorted descending; all negative flows ($\Delta_{\text{flow}, t} &lt; 0$) are sorted ascending (most negative first).
  2. The latest week's flow ($\Delta_{\text{flow}, 0}$) receives an intra-asset historical rank (Rank 1 = largest positive or negative weekly orderflow injection in the dataset).
  3. All 21 assets are then sorted across markets by their Rank to surface which futures contracts experienced unusually extreme institutional capital flows in the latest CFTC release.

๐ŸŒ Tracked Futures & CFTC Codes

ALL_ASSET in main_scraper.py tracks 21 contracts across 5 asset categories (csv_folder/):

Category (csv_folder/) Asset CSV File CFTC Market Code Report Group
Forex (forex/) Euro (EUR) eur.csv 099741 deacmesf
Forex (forex/) Japanese Yen (JPY) jpy.csv 097741 deacmesf
Forex (forex/) Australian Dollar (AUD) aud.csv 232741 deacmesf
Forex (forex/) New Zealand Dollar (NZD) nzd.csv 112741 deacmesf
Forex (forex/) Canadian Dollar (CAD) cad.csv 090741 deacmesf
Forex (forex/) British Pound (GBP) gbp.csv 096742 deacmesf
Forex (forex/) Swiss Franc (CHF) chf.csv 092741 deacmesf
Forex (forex/) Mexican Peso (MXN) mxn.csv 095741 deacmesf
Forex (forex/) Brazilian Real (BRL) brl.csv 102741 deacmesf
Forex (forex/) South African Rand (ZAR) zar.csv 122741 deacmesf
Forex (forex/) US Dollar Index (USD) usd.csv 098662 deanybtsf
Crypto (crypto/) Bitcoin (BTC) btc.csv 133741 deacmesf
Crypto (crypto/) Ethereum (ETH) eth.csv 146021 deacmesf
Index (index/) NASDAQ-100 (NASDAQ-100) nasdaq-100.csv 209742 deacmesf
Index (index/) S&P 500 (S&P 500) s&p 500.csv 13874A deacmesf
Index (index/) Dow Jones (DOW JONES) dow jones.csv 124603 deacbtsf
Metals (metals/) Silver (SILVER) silver.csv 084691 deacmxsf
Metals (metals/) Copper (COPPER) copper.csv 085692 deacmxsf
Metals (metals/) Gold (GOLD) gold.csv 088691 deacmxsf
Other (other/) Crude Oil (OIL) oil.csv 067651 deanymesf
Other (other/) Natural Gas (GAS) gas.csv 023651 deanymesf

๐Ÿ—๏ธ System Architecture

flowchart TD
    CFTC["CFTC Historical Archives\n(cftc.gov/files/dea/history/deacot{year}.zip)"] --> Scraper["main_scraper.py\ndownload_and_process_cot_data()"]
    Scraper --> Store["csv_folder/\ncrypto/, forex/, index/, metals/, other/ (21 CSVs)"]
    Home["0_๐Ÿ“Š_Accueil.py\ncheck_for_updates() (7+ days check)"] -->|"Triggers refresh if stale/missing"| Scraper
    Store --> Home
    Store --> Comp["pages/1_โš–๏ธ_Comparateur d'actifs.py\nSide-by-Side Styler Tables & CSV Export"]
    Store --> Metrics["pages/2_๐Ÿ’ธ_Meilleures_metriques.py\nranking() Long & Short Flow Leaderboards"]
Loading

๐Ÿ“‚ Repository Structure

Cot-Reports/
โ”œโ”€โ”€ .streamlit/
โ”‚   โ””โ”€โ”€ config.toml                        # Streamlit dark theme (#0E1117 background)
โ”œโ”€โ”€ csv_folder/
โ”‚   โ”œโ”€โ”€ crypto/                            # btc.csv, eth.csv
โ”‚   โ”œโ”€โ”€ forex/                             # aud.csv, brl.csv, cad.csv, chf.csv, eur.csv, gbp.csv, jpy.csv, mxn.csv, nzd.csv, usd.csv, zar.csv
โ”‚   โ”œโ”€โ”€ index/                             # dow jones.csv, nasdaq-100.csv, s&p 500.csv
โ”‚   โ”œโ”€โ”€ metals/                            # copper.csv, gold.csv, silver.csv
โ”‚   โ””โ”€โ”€ other/                             # gas.csv, oil.csv
โ”œโ”€โ”€ deacot2025_extracted/
โ”‚   โ””โ”€โ”€ annual.txt                         # Extracted CFTC 2025 annual report dataset
โ”œโ”€โ”€ pages/
โ”‚   โ”œโ”€โ”€ 1_โš–๏ธ_Comparateur d'actifs.py       # Dual-asset COT comparison & diverging heatmap tables
โ”‚   โ””โ”€โ”€ 2_๐Ÿ’ธ_Meilleures_metriques.py       # Historical order-injection ranking dashboard
โ”œโ”€โ”€ .gitattributes
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ 0_๐Ÿ“Š_Accueil.py                        # Main Streamlit entrypoint & auto-update controller
โ”œโ”€โ”€ LICENSE                                # MIT License
โ”œโ”€โ”€ README.md                              # Project documentation
โ”œโ”€โ”€ deacot2025.zip                         # Local 2025 CFTC annual archive
โ”œโ”€โ”€ ideas.txt                              # French feature backlog & research notes
โ”œโ”€โ”€ main_scraper.py                        # CFTC ZIP downloader & per-asset CSV generator
โ””โ”€โ”€ requirements.txt                       # Dependencies (streamlit, pandas, seaborn, requests, millify)

๐Ÿš€ Installation & Usage

Prerequisites

  • Python: 3.9+
  • Internet access when refreshing weekly reports from cftc.gov (bundled csv_folder/ allows immediate offline exploration)

1. Clone the Repository

git clone https://github.com/khalid-naami/Cot-Reports.git
cd Cot-Reports

2. Create a Virtual Environment & Install Dependencies

Windows (PowerShell):

python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt

macOS / Linux:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

3. Refresh CFTC Data Manually (Optional)

python main_scraper.py

4. Launch the Streamlit Application

streamlit run 0_๐Ÿ“Š_Accueil.py

Navigate between Accueil, Comparateur d'actifs, and Meilleures metriques in the Streamlit sidebar.


๐Ÿ“ก Data Provider & Disclaimer

  • Regulatory Market Data: U.S. Commodity Futures Trading Commission (cftc.gov) Legacy Futures-Only annual archives (deacot2025.zip / deacot2026.zip).

Disclaimer: Commitments of Traders data reflects lagged Tuesday institutional/non-commercial futures positioning released weekly by the CFTC. This dashboard is strictly for macroeconomic and quantitative market research and does not constitute trading or financial advice.


๐Ÿ“œ License

Released under the MIT License. See LICENSE for full terms.

About

Automated multi-page Streamlit platform and CFTC Legacy Futures scraper tracking weekly institutional non-commercial positioning, side-by-side asset orderflow divergence, and historical order-injection rankings across 21 Forex, Crypto, Equity Index, Metals, and Energy futures.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages