eptr2-imbalance-costs

Calculate and analyze Turkish electricity imbalance costs including KUPST (Kesinleşmiş Üretim Planından Sapma Tutarı/Production Plan Deviation Cost), positive/negative imbalance penalties, and DSG (De

eptr2
imbalance
costs

SKILL.md

GitHub

Imbalance and KÜPST costs

Use contract-aware utilities for historical analysis. The library distinguishes regulation periods (pre_2026, 26_01 from 2026-01-01, 26_02 from 2026-11-01, 27_01 from 2027-01-01); do not apply a timeless 3% margin or one tolerance to a range crossing a rule boundary. Functions called without a contract use the newest parameters (regulation_period="current"); pass a contract or a period label to reproduce a specific period.

from eptr2.util.costs import calculate_unit_price_and_costs_by_contract

costs = calculate_unit_price_and_costs_by_contract(
    contract="PH26070101", mcp=4000, smp=4000,
    system_direction="Enerji Açığı",
)
print(costs)

For ranges or plant data, prefer the main functions: they resolve floor/ceiling, V, B, margins and KÜPST tolerance and multiplier (by category) for each hour, and fetch MCP, SMP and systemStatus when prices is not given. Where EPİAŞ's published imbalance prices are available (fetched rows, or positiveImbalance / negativeImbalance in prices) they are used, and imb_price_source says published; otherwise the prices are calculated. Hours without SMP (the rest of the current day, future hours) are skipped with a warning; pass prices with an SMP scenario to price them. KÜPST unit cost is always calculated. Storage categories differ: a plant with storage ("depolamalı üretim tesisi") is plant_w_battery (tolerance 0.05, multiplier 0.10), standalone storage is battery, and a plant with an integrated storage unit ("bütünleşik depolama ünitesi") uses its main source's tolerance, so pass its main source (e.g. "Rüzgar"); names like "RES+BESS" resolve to plant_w_battery. Hydro, geothermal and biomass are other_renewable (tolerance and multiplier of other sources, maintenance multiplier from 30 fault entries like wind and solar; other sources from 25). From 2027-01-01 consumption units pay KÜPST too: pass is_producer=False with category consumption_art17 (tolerance 0.75) or consumption_other (0.30); before 2027 consumers have no KÜPST. Pass include_calculated=True to also get the calculated prices for a check against the published ones.

from eptr2.util.costs import calculate_imbalance_costs

rows = calculate_imbalance_costs(
    data=[{"date": "2026-11-01T10:00:00+03:00", "actual": 80, "forecast": 100}],
    category="Rüzgar",
    prices=[{"date": "2026-11-01T10:00:00+03:00", "mcp": 3000, "smp": 3200,
             "system_direction": "Enerji Açığı"}],
    return_df=False,
)
print(rows[0]["imb_cost"], rows[0]["kupst_cost"], rows[0]["total_cost"])

No credentials are required for pure calculations or when prices are given. Fetch systemStatus from mcp-smp-imb for API-based analyses. Pass direction explicitly, especially when MCP equals SMP: -1 / Enerji Açığı means deficit, +1 / Enerji Fazlası means surplus, and 0 / Dengede means balanced. The MCP calculation tool accepts system_direction and requires it for equal prices.

Output unit_pos_imb_cost and unit_neg_imb_cost are TL/MWh; multiplying by the corresponding imbalance energy gives TL. unit_kupst is not the plant's total charge. Distinguish positive/negative imbalance energy, unit prices, unit opportunity costs, and total costs.

Read formulas.md for function selection and examples.md for per-contract KÜPST and API-backed comparisons. State whether the result is historical or a scenario with overridden assumptions. Do not equate a simple plant calculation with every aggregator settlement rule.