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-marginTags
Translated version includes tags in frontmatterSKILL.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_priceWhere:
- 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**
| Metric | Included Items | Applicable Scenario |
|---|---|---|
| Cash Cost (C1) | On-site mining + processing + on-site administration | Cash flow stress test |
| AISC | C1 + sustaining capital expenditure + exploration + administration | Industry Standard (defined by WGC) |
| All-In Cost (AIC) | AISC + growth capital expenditure | Complete 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**
| Method | Formula | Intuition |
|---|---|---|
| equal_weight | Σ margin_i / N | Simple average, equal weight for each company |
| production_weighted | Σ (margin_i × prod_i) / Σ prod_i | Production-weighted, reflects "industry gross margin" |
| marketcap_weighted | Σ (margin_i × mcap_i) / Σ mcap_i | Market 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 directory and can be executed directly.
</principle>
scripts/</essential_principles>
<objective>
Implement the calculation model for the 'Precious Metals Mining Gross Margin Proxy':
- Data Integration: Fetch metal price series and mining cost/production volume data
- Gross Margin Proxy Calculation: Single company level + basket aggregation
- Historical Percentiles: Determine the current level's position in the historical range
- Driver Decomposition: Distinguish between price-driven vs cost-driven changes
- 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 goldSample 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?
- Quick Calculation - Calculate the gross margin proxy for major mining baskets using default parameters
- Full Analysis - Perform scenario analysis with custom parameters (select metal, miners, cost metric)
- Data Research - Learn how to obtain AISC / cost data (crawler design)
- Signal Generation - Convert gross margin into trading/research signals
- 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>
| Workflow | Purpose | Application Scenario |
|---|---|---|
| analyze.md | Full scenario analysis | Need to calculate gross margin with custom parameters |
| data-research.md | Data source research | Learn how to obtain cost data |
| signal-generation.md | Signal generation | Convert gross margin into trading/research signals |
| </workflows_index> |
<templates_index>
| Template | Purpose |
|---|---|
| output-json.md | JSON output structure definition |
| output-markdown.md | Markdown report template |
| </templates_index> |
<scripts_index>
| Script | Command | Purpose |
|---|---|---|
| margin_calculator.py | | Quick calculation for gold mining industry |
| margin_calculator.py | | Quick calculation for silver mining industry |
| margin_calculator.py | | Custom miners and frequency calculation |
| margin_calculator.py | | Driver decomposition analysis |
| </scripts_index> |
<input_schema_summary>
Core Parameters
| Parameter | Type | Default Value | Description |
|---|---|---|---|
| metal | string | gold | Target metal (gold/silver) |
| miners | array | Default basket | List of miner tickers |
| start_date | string | 10 years ago | Calculation start date (YYYY-MM-DD) |
| end_date | string | today | Calculation end date |
| frequency | string | quarterly | Frequency (daily/weekly/monthly/quarterly) |
| cost_metric | string | AISC | Cost metric |
| aggregation | string | production_weighted | Aggregation method |
Advanced Parameters
| Parameter | Type | Default Value | Description |
|---|---|---|---|
| price_series | string | spot | Price metric |
| fx_mode | string | none | FX handling |
| outlier_rule | string | winsorize_1_99 | Outlier processing |
| history_window_years | int | 20 | Historical 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 .
</output_schema_summary>
templates/output-json.md<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>