compute-precious-miner-gross-margin

Original🇨🇳 Chinese
Translated
1 scriptsChecked / no sensitive code detected

Calculate the 'Gross Margin Proxy for Gold/Silver Mining Industry' using public metal prices and mining cost metrics (AISC/All-in Cost/Cash Cost), and determine whether the current level is in the historical high/low range.

1installs
Added on

NPX Install

npx skill4agent add fatfingererr/macro-skills compute-precious-miner-gross-margin

SKILL.md Content (Chinese)

View Translation Comparison →
<essential_principles>
<principle name="margin_proxy_definition"> **Gross Margin Proxy Definition**
The Mining Gross Margin Proxy uses a simplified formula:
gross_margin_proxy = (metal_price - unit_cost) / metal_price
Where:
  • metal_price: Spot price of the metal or near-month futures price
  • unit_cost: AISC (All-In Sustaining Cost), Cash Cost (C1), or All-In Cost
This indicator is not equivalent to the gross margin in financial statements, but can quickly capture marginal changes in the price-cost relationship. </principle>
<principle name="cost_metric_hierarchy"> **Cost Metric Hierarchy**
MetricIncluded ItemsApplicable Scenario
Cash Cost (C1)On-site mining + processing + on-site administrationCash flow stress test
AISCC1 + sustaining capital expenditure + exploration + administrationIndustry Standard (defined by WGC)
All-In Cost (AIC)AISC + growth capital expenditureComplete economic cost
It is recommended to prioritize AISC due to its best comparability and high data availability. </principle>
<principle name="aggregation_logic"> **Basket Aggregation Logic**
MethodFormulaIntuition
equal_weightΣ margin_i / NSimple average, equal weight for each company
production_weightedΣ (margin_i × prod_i) / Σ prod_iProduction-weighted, reflects "industry gross margin"
marketcap_weightedΣ (margin_i × mcap_i) / Σ mcap_iMarket cap-weighted, reflects "equity exposure"
It is recommended to use production_weighted to more accurately reflect the overall gross margin structure of the industry. </principle>
<principle name="data_frequency_alignment"> **Data Frequency Alignment**
  • Metal Prices: Daily frequency or monthly average price
  • Mining Costs: Quarterly (most companies only disclose AISC in quarterly reports)
  • Alignment Methods:
    • Forward-fill costs to each period within the quarter
    • Or use the same-quarter average price (cleaner)
This Skill recommends using quarterly frequency as the baseline to avoid over-smoothing. </principle>
<principle name="data_sources"> **Data Acquisition Methods**
This skill uses public data:
  • Gold Price: LBMA Gold Price / COMEX Near-Month Futures
  • Silver Price: LBMA Silver Price / COMEX Near-Month Futures
  • AISC: Company IR investor presentations / Quarterly Report MD&A / Press releases
  • Production Volume: Same as above, unit in oz / GEO / AgEq oz
Scripts are located in the
scripts/
directory and can be executed directly. </principle>
</essential_principles>
<objective> Implement the calculation model for the 'Precious Metals Mining Gross Margin Proxy':
  1. Data Integration: Fetch metal price series and mining cost/production volume data
  2. Gross Margin Proxy Calculation: Single company level + basket aggregation
  3. Historical Percentiles: Determine the current level's position in the historical range
  4. Driver Decomposition: Distinguish between price-driven vs cost-driven changes
  5. Signal Generation: Mark extreme high/low range intervals
Output: Gross margin time series, historical percentiles, driver decomposition, trading/research links. </objective>
<quick_start>
Fastest Way: Execute Default Scenario Analysis
bash
cd skills/compute-precious-miner-gross-margin
pip install pandas numpy requests yfinance beautifulsoup4 lxml  # First-time use
python scripts/margin_calculator.py --quick --metal gold
Sample Output:
json
{
  "skill": "compute_precious_miner_margin_proxy",
  "metal": "gold",
  "frequency": "quarterly",
  "cost_metric": "AISC",
  "basket": {
    "miners": ["NEM", "GOLD", "AEM"],
    "aggregation": "production_weighted"
  },
  "latest": {
    "date": "2025-Q4",
    "metal_price_usd_oz": 2650.0,
    "unit_cost_proxy_usd_oz": 1320.0,
    "gross_margin_proxy": 0.502,
    "history_percentile": 0.78,
    "regime_label": "high_margin"
  }
}
Full Scenario Analysis:
bash
python scripts/margin_calculator.py \
  --metal silver \
  --miners CDE,HL,AG \
  --start-date 2015-01-01 \
  --frequency quarterly \
  --cost-metric AISC \
  --aggregation production_weighted \
  --output result.json
</quick_start>
<intake> What operation do you need to perform?
  1. Quick Calculation - Calculate the gross margin proxy for major mining baskets using default parameters
  2. Full Analysis - Perform scenario analysis with custom parameters (select metal, miners, cost metric)
  3. Data Research - Learn how to obtain AISC / cost data (crawler design)
  4. Signal Generation - Convert gross margin into trading/research signals
  5. Methodology Learning - Understand calculation logic and data sources
Please select or directly provide analysis parameters. </intake>
<routing> | Response | Action | |-----------------------------|----------------------------------------------------| | 1, "quick", "fast", "calculate" | Execute `python scripts/margin_calculator.py --quick` | | 2, "full", "complete", "analyze" | Read `workflows/analyze.md` and execute | | 3, "data", "research", "crawler" | Read `workflows/data-research.md` | | 4, "signal", "trading", "generate" | Read `workflows/signal-generation.md` and execute | | 5, "learn", "methodology", "why" | Read `references/methodology.md` | | Provide parameters (e.g., miner list) | Read `workflows/analyze.md` and execute with parameters |
After routing, read the corresponding file and execute. </routing>
<directory_structure>
compute-precious-miner-gross-margin/
├── SKILL.md                           # This file (router)
├── skill.yaml                         # Frontend display metadata
├── manifest.json                      # Skill metadata
├── workflows/
│   ├── analyze.md                     # Full scenario analysis workflow
│   ├── data-research.md               # Data source research and crawler design
│   └── signal-generation.md           # Signal generation workflow
├── references/
│   ├── data-sources.md                # Data sources and acquisition methods
│   ├── methodology.md                 # Methodology and calculation logic
│   └── input-schema.md                # Complete input parameter definition
├── templates/
│   ├── output-json.md                 # JSON output template
│   └── output-markdown.md             # Markdown report template
├── scripts/
│   └── margin_calculator.py           # Main calculation script
└── examples/
    └── sample-output.json             # Sample output
</directory_structure>
<reference_index>
Methodology: references/methodology.md
  • Gross margin proxy definition
  • Cost metric hierarchy analysis
  • Aggregation methods and intuition
  • Historical percentile calculation
Data Sources: references/data-sources.md
  • Gold and silver price data sources
  • AISC / Cash Cost data sources
  • Production volume data sources
  • Crawler design guidelines
Input Parameters: references/input-schema.md
  • Complete parameter definition
  • Default values and recommended ranges
  • Default miner baskets
</reference_index>
<workflows_index>
WorkflowPurposeApplication Scenario
analyze.mdFull scenario analysisNeed to calculate gross margin with custom parameters
data-research.mdData source researchLearn how to obtain cost data
signal-generation.mdSignal generationConvert gross margin into trading/research signals
</workflows_index>
<templates_index>
TemplatePurpose
output-json.mdJSON output structure definition
output-markdown.mdMarkdown report template
</templates_index>
<scripts_index>
ScriptCommandPurpose
margin_calculator.py
--quick --metal gold
Quick calculation for gold mining industry
margin_calculator.py
--quick --metal silver
Quick calculation for silver mining industry
margin_calculator.py
--miners NEM,GOLD --freq Q
Custom miners and frequency calculation
margin_calculator.py
--decompose
Driver decomposition analysis
</scripts_index>
<input_schema_summary>
Core Parameters
ParameterTypeDefault ValueDescription
metalstringgoldTarget metal (gold/silver)
minersarrayDefault basketList of miner tickers
start_datestring10 years agoCalculation start date (YYYY-MM-DD)
end_datestringtodayCalculation end date
frequencystringquarterlyFrequency (daily/weekly/monthly/quarterly)
cost_metricstringAISCCost metric
aggregationstringproduction_weightedAggregation method
Advanced Parameters
ParameterTypeDefault ValueDescription
price_seriesstringspotPrice metric
fx_modestringnoneFX handling
outlier_rulestringwinsorize_1_99Outlier processing
history_window_yearsint20Historical percentile window
Complete parameter definition can be found in
references/input-schema.md
.
</input_schema_summary>
<output_schema_summary>
json
{
  "skill": "compute_precious_miner_margin_proxy",
  "metal": "silver",
  "frequency": "quarterly",
  "cost_metric": "AISC",
  "basket": {
    "miners": ["CDE", "HL", "AG"],
    "aggregation": "production_weighted"
  },
  "latest": {
    "date": "2025-Q4",
    "metal_price_usd_oz": 31.50,
    "unit_cost_proxy_usd_oz": 6.30,
    "gross_margin_proxy": 0.80,
    "history_percentile": 0.94,
    "regime_label": "extreme_high_margin"
  },
  "decomposition": {
    "last_3m_price_change_pct": 0.12,
    "last_3m_cost_change_pct": -0.03,
    "driver": "mostly_price_up"
  },
  "notes": [
    "gross_margin_proxy uses (price - AISC)/price as an approximation; not equivalent to the gross margin in financial statements.",
    "If cost data is quarterly, it has been aligned via forward-fill within the quarter / same-quarter average price."
  ],
  "recommended_next_checks": [
    "Compare 3/6/12-month forward returns of SIL/SILJ or individual stocks using the same margin proxy (event study)",
    "Check for rising capital expenditure/M&A activity, or cost re-inflation (diesel/wages/reagents) leading to gross margin decline"
  ]
}
Complete output structure can be found in
templates/output-json.md
. </output_schema_summary>
<success_criteria> Successful execution should produce:
  • Gross margin proxy time series data
  • Unit cost and gross margin for each miner
  • Basket aggregated gross margin
  • Historical percentiles and range labels (extreme_high/high/neutral/low/extreme_low)
  • Driver decomposition (price-driven vs cost-driven)
  • Results output in specified format (JSON or Markdown)
  • Follow-up research recommendations </success_criteria>