nx_dcf_lib.nx
buildroot/runtime/nx_dcf_lib.nx
about
nx_dcf_lib.nx -- DISCOUNTED CASH FLOW: intrinsic valuation + margin of safety, integer-exact.
The operator's "projections -> intrinsic value vs price" ask. This is Graham/Buffett value math: project
a firm's free cash flows, discount them (and a terminal value) back to today at the required return, sum
to an INTRINSIC value, and compare to the market PRICE with a margin of safety. A stock is a buy only
when intrinsic exceeds price by a real margin -- price is what you pay, value is what you get.
NO FLOATS: the discount factor is carried scaled x1e6 and rolled forward one period at a time
(df_t = df_{t-1} * 10000 / (10000 + rate_bp)); every present value is exact integer arithmetic with
defined truncation. Rates and growth are basis points (10% -> 1000).
★FAIL-CLOSED ON THE DCF TRAP: the Gordon terminal value final*(1+g)/(r-g) EXPLODES to nonsense when
growth >= discount rate (division by <=0). Analysts produce absurd trillion-dollar valuations exactly
this way. dcf_terminal REFUSES (DCF_UNDEFINED) rather than emitting a garbage number. A valuation you
cannot compute honestly is not a valuation.
SCALE ENVELOPE (declared): cashflow * df fits i64 for cashflows up to ~9e12 units at df~1e6. DRY:
composes nx_matter_lib helpers. license_tier: ORIGINAL No hw writes (Rule 26). LIB.
dependencies 1 imports · 2 importers
imports: nx_matter_lib.nx
imported by: nx_dcf_gate.nxnx_finance_svc.nx
structs
| none |
consts
| 21 | const DCF_MAGIC_1500: i64 = 1500 |
| 23 | const DCF_DF_SCALE: i64 = 1000000 // discount factor carried x1e6 (1.0 = 1000000) |
| 24 | const DCF_BP_FULL: i64 = 10000 // 100% in basis points |
| 25 | const DCF_UNDEFINED: i64 = 0 - 2000000001 // terminal value undefined (growth >= rate) |
| 26 | const DCF_BAD: i64 = 0 - 2000000002 // invalid input (e.g. price <= 0) |
functions
| 29 | func dcf_discount_factor(rate_bp: i64, period: i64) -> i64 |
| 40 | func dcf_pv(cashflow: i64, rate_bp: i64, period: i64) -> i64 |
| 45 | func dcf_terminal(final_cf: i64, growth_bp: i64, rate_bp: i64) -> i64 |
| 52 | func dcf_intrinsic(cashflows: *i64, n: i64, rate_bp: i64, terminal_value: i64) -> i64 |
| 65 | func dcf_margin_of_safety_bp(intrinsic: i64, price: i64) -> i64 |
| 71 | func dcf_verdict(intrinsic: i64, price: i64) -> i64 |
| 79 | func dcf_verdict_str(v: i64) -> *u8 |