Read and value results
run(model) returns a result object with convenient JavaScript accessors and a serializable, versioned result shape.
import { cashflow, currencies, defineModel, entity, inflow, periods, run, schedule } from "deccf";
const building = entity.asset();
const rent = cashflow({ owner: building, direction: inflow, schedule: schedule.monthly(), amount: 10_000 });
const model = defineModel({
name: "one-year-rent",
currency: currencies.SEK,
timeline: periods.monthly({ from: "2026-01", count: 12 }),
entities: { building },
flows: { rent },
});
const result = run(model);
console.log(result.metrics.total);
console.log(result.flow(rent));
console.log(result.deterministic.metrics["model.total"]);
console.log(result.deterministic.series["flow.rent"].values);
return model;Convenience readers include flow, option, field, account, state, category, entity, and component. Component outputs expose named calculations and flows; repeated component outputs are keyed by their stable input row IDs. Series follow the model's calendar; consider the date range and period grain when interpreting values.
Built-in metrics include model.total, model.npv, model.irr, and model.wal_years, plus custom metrics from defineModel({ metrics }). NPV uses the run's discount rate, which defaults to zero. IRR and weighted average life can be null when the cashflows do not produce a solvable value.
Declare a time-based metric with metric({ calculate, periodLength, frequency }). These values count model periods. The callback reads its inclusive range from ctx.metricPeriod. Results include metric series, and the annual rollup follows the metric's annualAggregation setting and fiscal-year start month.
The serialized result includes results_version, engine, warnings, inputs.preconditions, deterministic.metrics, deterministic.series, deterministic.annual_rollup, graph, scenarios, monte_carlo, statements, slices, and timings. A normal deterministic run marks scenarios and Monte Carlo as not_run; statements and slices are empty.
timings reports integer microsecond ticks from performance.now() and includes totalMs for the complete run duration in milliseconds. It separates setup, the period calculation, metrics, and output assembly. Every declared model metric has its own duration; pack metrics are grouped by domain pack. These runtime measurements vary with the machine and current load and do not affect calculation results.
Use result.toJSON() or JSON.stringify(result), which calls toJSON() automatically. See Result format for the exact fields.
Next: Extend the model with a pack.