Reproducible Financial Calculation
Use the smallest governed input and leave an auditable Calculation Run whenever
the result can affect a conclusion. Keep quick arithmetic that does not support
a conclusion explicitly exploratory.
Follow the calculation workflow
- Search Dataset and Calculation cards before fetching data or computing.
- Inspect only the relevant manifest or run summary. Confirm source lineage,
units, currency, timezone, adjustment policy, and
knowledge_cutoff.
- Reuse a prior result only when
prepare_calculation reports an exact
fingerprint match. Treat similar runs as references, not cached answers.
- Materialize only the needed columns, instruments, and time range. Keep
private portfolio or ledger inputs run-scoped; never register them as a
Dataset or copy them into scripts, logs, or artifacts.
- Create one direct basename-only
.py file under
$TRADINGCODEX_SCRATCH with native apply_patch. For a conclusion-relevant
calculation, call prepare_calculation before execution and use only its
declared inputs and outputs.
- Run exactly
./tcx-calc <filename.py> from the workspace root on POSIX or
.\\tcx-calc.cmd <filename.py> on Windows. Do not invoke system Python,
install packages, use heredocs, or pass -c, -m, paths, or extra args.
- Call the runner-injected
tcx_emit_result global exactly once with one
positional object. Never import it, pass keyword arguments, invent wrapper
fields, or emit a metrics mapping. Copy the exact typed shape from
references/data-runtime.md.
- Record success or failure with
record_calculation_run. On failure, read
its safe error_code and error_message, make one concrete correction,
stage a new script basename, prepare a new immutable spec, and retry. Never
overwrite a prepared script/result, repeat the same failed code unchanged,
install packages, or reuse a failed Run. Stop and hand off as waiting if
the same error code recurs after its targeted correction.
- Bind accepted
calculation_run_ids, Dataset lineage, assumptions,
diagnostics, and warnings into the role artifact. Do not cite an
exploratory sidecar-free execution as decision evidence.
Use search_datasets, get_dataset_manifest, profile_dataset, and
materialize_dataset_slice progressively. Avoid loading complete payloads or
long calculation logs into context.
Apply the quality floor
- Separate observed inputs, derived values, assumptions, and judgment.
- Preserve point-in-time posture; never substitute revised or current data for
the requested vintage without disclosure.
- Make units, sign conventions, compounding, annualization, timing, missing
values, and sample definitions explicit.
- Set deterministic seeds for stochastic work and report solver convergence,
statistical diagnostics, and sensitivity where relevant.
- Reject NaN, Infinity, silent coercion, executable serialization, and results
whose inputs or method cannot be reconstructed.
- Lower readiness when data quality, method assumptions, sample size,
convergence, or sensitivity does not support the claim.
Read references/finance-methods.md before DCF,
IRR, return/risk, regression, optimization, or portfolio calculations. Read
references/data-runtime.md before registering,
materializing, reusing, or recording Dataset and Calculation objects.
1---2name: tcx-calculation3description: Run reproducible financial calculations from governed Dataset slices or declared private inputs, reuse exact prior results, and bind decision-relevant metrics to recorded Calculation Runs. Use for returns, risk, valuation, regression, optimization, scenario, or portfolio math that can affect an investment artifact.4---56# Reproducible Financial Calculation78Use the smallest governed input and leave an auditable Calculation Run whenever9the result can affect a conclusion. Keep quick arithmetic that does not support10a conclusion explicitly exploratory.1112## Follow the calculation workflow13141. Search Dataset and Calculation cards before fetching data or computing.152. Inspect only the relevant manifest or run summary. Confirm source lineage,16 units, currency, timezone, adjustment policy, and `knowledge_cutoff`.173. Reuse a prior result only when `prepare_calculation` reports an exact18 fingerprint match. Treat similar runs as references, not cached answers.194. Materialize only the needed columns, instruments, and time range. Keep20 private portfolio or ledger inputs run-scoped; never register them as a21 Dataset or copy them into scripts, logs, or artifacts.225. Create one direct basename-only `.py` file under23 `$TRADINGCODEX_SCRATCH` with native `apply_patch`. For a conclusion-relevant24 calculation, call `prepare_calculation` before execution and use only its25 declared inputs and outputs.266. Run exactly `./tcx-calc <filename.py>` from the workspace root on POSIX or27 `.\\tcx-calc.cmd <filename.py>` on Windows. Do not invoke system Python,28 install packages, use heredocs, or pass `-c`, `-m`, paths, or extra args.297. Call the runner-injected `tcx_emit_result` global exactly once with one30 positional object. Never import it, pass keyword arguments, invent wrapper31 fields, or emit a metrics mapping. Copy the exact typed shape from32 [references/data-runtime.md](references/data-runtime.md).338. Record success or failure with `record_calculation_run`. On failure, read34 its safe `error_code` and `error_message`, make one concrete correction,35 stage a new script basename, prepare a new immutable spec, and retry. Never36 overwrite a prepared script/result, repeat the same failed code unchanged,37 install packages, or reuse a failed Run. Stop and hand off as `waiting` if38 the same error code recurs after its targeted correction.399. Bind accepted `calculation_run_ids`, Dataset lineage, assumptions,40 diagnostics, and warnings into the role artifact. Do not cite an41 exploratory sidecar-free execution as decision evidence.4243Use `search_datasets`, `get_dataset_manifest`, `profile_dataset`, and44`materialize_dataset_slice` progressively. Avoid loading complete payloads or45long calculation logs into context.4647## Apply the quality floor4849- Separate observed inputs, derived values, assumptions, and judgment.50- Preserve point-in-time posture; never substitute revised or current data for51 the requested vintage without disclosure.52- Make units, sign conventions, compounding, annualization, timing, missing53 values, and sample definitions explicit.54- Set deterministic seeds for stochastic work and report solver convergence,55 statistical diagnostics, and sensitivity where relevant.56- Reject NaN, Infinity, silent coercion, executable serialization, and results57 whose inputs or method cannot be reconstructed.58- Lower readiness when data quality, method assumptions, sample size,59 convergence, or sensitivity does not support the claim.6061Read [references/finance-methods.md](references/finance-methods.md) before DCF,62IRR, return/risk, regression, optimization, or portfolio calculations. Read63[references/data-runtime.md](references/data-runtime.md) before registering,64materializing, reusing, or recording Dataset and Calculation objects.