Dynevia
IT EN
Contact

Energy6 min read

Why energy pricing engines fail silently, and how to test them

Italy's public register of power and gas offers looks like a price list. It is really a model. Reviewing a live pricing engine, we found prices tripled, a gas index six months out of date and offers that had vanished, without a single line in the logs. Here is how to build, and test, a calculation that holds up.

ARERA, the Italian energy regulator, publishes the power and gas offers on the free retail market as open data through its Portale Offerte. For a comparison service or a pricing engine there is no richer source. It is also a format that invites silent errors: the calculation runs, numbers come out, the logs stay clean. Reviewing a comparison engine in production, which imports this data every day, we found three families of errors. They had one thing in common: the system treated each of them as a valid result.

Rows within a component are alternatives

In the data format, a single price component can carry several rows: one per time-of-use band, one per consumption tier, one per validity period, and almost always an extra “standard” row. They are alternatives, not addends. The engine added them up.

  • The per-kWh price on the offer card summed bands F1, F2 and F3: €0.411 instead of about €0.136, across 63% of the electricity catalogue.
  • One gas offer came out at €2.635 per standard cubic metre (Smc) instead of €0.845. Estimated annual spend: more than €5,000 instead of €2,415.
  • The spread on index-linked offers, published band by band, was applied three times over to the whole consumption.

The correct rule fits in three lines. Within a component, pick a single row: the tier that matches the consumption, then the standard row. Between conflicting standard rows with no explanation, take the more expensive, so that no offer looks cheaper than it is. Across different components, add them up. Once row selection was fixed, 874 of 1,890 electricity offers and 18 of 1,258 gas offers went down, with a median drop of €149 a year on electricity. None went up. Every other offer stayed identical to the cent.

Free text is not data

The second family comes from names. The mark-up on index-linked gas offers was looked up in a component named exactly “SPREAD”. In 235 of roughly 870 index-linked offers the supplier called it something else, and the engine valued it at zero. Those offers cost the bare index, €0.10 to €0.34 per Smc less than the real price, and rose to the top of the ranking. Descriptions said “two-band” on offers with three prices. One offer declared €168 per kWh: almost certainly €/MWh entered in the wrong unit.

  • Price type, whether fixed, indexed or time-of-use, is read from structured fields. Descriptions are for people, not for the calculation.
  • Energy cost components are summed by unit of measure, whatever they are called, and a mixed-price offer tied to an index is priced as indexed. After those two fixes, 257 gas offers went up and none went down.
  • Every price passes a plausibility check before it enters the ranking.
  • Watch where an error spreads. Deduplication by supplier and estimated spend made different offers with the same wrong price disappear: one supplier showed one offer in six. Once the calculation was fixed, 51 gas offers became visible again.

Where no open data exists, as with mobile and broadband, offers are read from operators' web pages by a language model. There the rule is stricter: an offer stays in the catalogue only if its monthly fee actually appears in the text of the page.

Stale data raises no errors

The third family is the most insidious. The file of gas indices published by ARERA lives at an address that contains a fingerprint of the document. When the file is republished the address changes, but the previous version stays online and answers normally. For months the engine imported a PSV, the Italian wholesale gas price, frozen at December 2025, €0.328 per Smc, while the June 2026 figure was €0.504. No errors, nothing in the logs, and the “last updated” timestamp in the database moved on every run. On top of that, the calculation copied the latest value across all twelve months of the estimate. At 1,400 Smc a year, 1,137 of 1,515 gas offers were underestimated by €291: an offer quoted at €676 actually cost €968.

Today the engine finds the link on the open data page instead of trusting a stored address. It rejects any index more than three months old, since publication lags by about two months: in that case it imports nothing and stops with an error. Next to each value it stores the month the value refers to. An automated test pins the rule down and also checks it against the regulator's live site.

A pricing engine publishes figures that someone will sign. A wrong number is damage, not a bug.

How to test a pricing engine

A fix is only as good as the way you prove it. On our projects, testing a pricing engine has four layers.

  • Full-catalogue regression. Old and new calculations run on the same data and are compared offer by offer; every difference needs a written cause. Isolation matters: the code assigned functions to global variables, so with two versions loaded in the same process the last one won. The comparison lied. Use separate processes.
  • Invariants. When two formulas produce the same numbers, such as annual spend and its breakdown into bill items, a test requires across the whole catalogue that the parts add up to the total. After the latest change to the calculation: zero deviations on 376 offers.
  • A reversible canary. The new engine went live alongside the old one: a parameter switches it on for a single browser, a constant for the whole site, and removing the module restores the previous state. Check the cache first. In one plugin the cache key did not include the engine's address: with caching on, results from the new engine would have reached visitors still on the old one, and the canary would have stopped being a canary without a single error. For visitors on the new engine, that cache is off.
  • Checks in operation. For mobile and broadband, every import is compared with each source's historical median and flags sources that are stalled, failing, emptied or shrinking. And the check needs watching in turn: one that stops running sends no alerts, so something has to notice its absence.
Contact

Is your process still living in a spreadsheet?

Tell us what the system has to do, what data it works with and what constraints apply. We'll come back to you with the questions that matter and a phased proposal.

Get in touch