CoolFace
Apppublic

Jing997/copper-cathodes-world-monitor

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

Copper Cathode Commodity Monitor

A Streamlit dashboard for copper price intelligence, targeting copper producers and mining companies. Deployed on HuggingFace Spaces (free CPU tier).

The dashboard aggregates LME, COMEX, and SHFE-derived copper prices, macro stress signals, speculative positioning data, and RSS news sentiment into a single five-tab interface. It is intended as an educational and analytical reference — not a trading system.


Data Sources

SourceTicker / IDFrequencyCostLicense
yfinance — COMEX front-monthHG=F1h (market) / 12h (overnight)Free, no keyYahoo ToS — session cache only
yfinance — USD/CNY rateCNY=X1hFree, no keyYahoo ToS — session cache only
Alpha Vantage — LME-equivalent daily priceCOPPER24h (25 calls/day hard limit)Free, key requiredAlpha Vantage ToS
FRED — World Bank monthly LME pricePCOPPUSDM24hFree, key requiredPublic domain
FRED — Macro stress signalsSTLFSI4 + 6 others24hFree, key requiredPublic domain
akshare — SHFE front-month (derived use only)SHFE copper2hFree, no keyResearch / derived use only — raw price never stored or displayed
feedparser RSS — Copper news headlines6 confirmed-live feeds30 minFree, no keyRSS ToS — title + source link only
CFTC Commitment of Traders (COT)CFTC code 08569224h (weekly release, Tuesdays)Free, no keyPublic domain
World Bank Commodity APIPCOPP.USD24h (monthly data)Free, no keyCC BY 4.0

Architecture

External APIs
  yfinance (HG=F, CNY=X)
  Alpha Vantage (COPPER)
  FRED API (PCOPPUSDM, STLFSI4, ...)
  akshare (SHFE front-month)
  feedparser RSS (6 feeds)
  CFTC Socrata API (COT)
  World Bank API (PCOPP.USD)
          |
          v
  cache_manager.py
    HuggingFace Dataset repo (Jing997/copper-monitor-cache)
    Parquet files with per-source TTL enforcement
    FinBERT score cache (permanent, keyed by headline hash)
          |
          v
  modules/
    price_fetcher.py    -- COMEX, LME spot, SHFE (transient), USD/CNY, forward curve
    macro_fetcher.py    -- FRED indicators, CFTC COT, World Bank monthly price
    news_fetcher.py     -- RSS headline fetch + copper keyword filter
    spread_calc.py      -- COMEX-LME basis, LME cash/3M spread, China import premium
    stress_index.py     -- 6-signal PCA composite market stress index
    sentiment.py        -- FinBERT batch scoring + Gemini daily brief
          |
          v
  app.py
    5-tab Streamlit UI (Price Overview, Spread & Arbitrage,
    Market Stress Index, Sentiment, News Feed)

Setup

1. Install dependencies

bash
pip install -r requirements.txt

2. Configure secrets

The following secrets must be set before running locally or deploying to HuggingFace Spaces:

SecretPurpose
FRED_KEYFRED API access (macro indicators, World Bank LME price)
ALPHAVANTAGE_KEYLME-equivalent copper price via Alpha Vantage (25 calls/day limit)
GEMINI_API_KEYGemini 2.5 Flash-Lite daily market brief (optional — app runs without it)
HF_TOKENHuggingFace Dataset cache read/write (Jing997/copper-monitor-cache)

For local development, export secrets as environment variables:

bash
export FRED_KEY="your_fred_key"
export ALPHAVANTAGE_KEY="your_alphavantage_key"
export GEMINI_API_KEY="your_gemini_key"   # optional
export HF_TOKEN="your_hf_token"

3. Run locally

bash
streamlit run app.py

4. Deploy to HuggingFace Spaces

  1. 1.Fork this repository to your GitHub account.
  2. 2.Create a new HuggingFace Space (Streamlit SDK, free CPU tier).
  3. 3.Link the Space to your forked GitHub repository.
  4. 4.In the Space settings under Repository secrets, add the four secrets listed above.
  5. 5.Push to the linked branch — the Space will build and deploy automatically.

Dashboard Tabs

TabContents
Price OverviewLive KPI cards for COMEX (HG=F), LME spot, USD/CNY, and COMEX forward curve shape. Includes a 90-day COMEX price history chart (USD/MT).
Spread & ArbitrageCOMEX-LME basis, LME cash/3M spread with contango/backwardation label, China import premium (after import duty, VAT, and CIF deductions), and indicative TC/RC benchmark.
Market Stress IndexEqual-weighted composite of 6 signals (realized volatility, LME-COMEX basis Z-score, USD Index, China Imports YoY, STLFSI4, news sentiment). Displays a gauge, numeric score, state label (High Stress / Normal / Low Stress / Bullish), and 90-day history chart with threshold lines.
Sentiment7-day and 30-day rolling FinBERT sentiment averages, daily headline count bar chart, top 10 headlines from the last 48 hours with per-headline sentiment badges, and an optional Gemini-generated 2-sentence market brief (hidden when GEMINI_API_KEY is absent or quota is exceeded).
News FeedLast 30 copper news headlines (up to 7 days), each displayed with title, source name, publication time, sentiment badge, and a clickable link to the original article. No article body content is fetched or displayed.

Compliance Notes

  • —Educational disclaimer: This dashboard is for educational and informational purposes only. Not financial advice.
  • —SHFE data: Raw SHFE prices (CNY/MT) are never stored, logged, or displayed. Only the derived China Import Premium (a computed USD/MT value) appears in the UI, in accordance with the akshare research/derived-use license.
  • —yfinance (COMEX): Raw OHLCV data from yfinance is kept in session-level st.cache_data only. It is never written to the HuggingFace Dataset cache.
  • —RSS headlines: Only the headline title and source link are fetched and displayed. Article body content is never retrieved, stored, or shown, in accordance with RSS terms of service.
  • —Alpha Vantage: A strict 24-hour TTL is enforced via cache_manager.is_stale("lme_spot"). The API is never called without first checking staleness. Maximum 25 calls per day.

Attribution

  • —World Bank — Monthly copper price data (PCOPP.USD) provided by the World Bank, licensed under CC BY 4.0.
  • —ProsusAI/finbert — Sentiment analysis model by ProsusAI, licensed under Apache 2.0.
  • —Market Stress Index methodology — Inspired by the OFR Financial Stress Index (OFRwp-17-04) and the St. Louis Fed STLFSI4. Not a trading recommendation.