code wiki / (root) / nx_dcf_lib.nx

nx_dcf_lib.nx

buildroot/runtime/nx_dcf_lib.nx

3971 B84 linesdepth 7pulls 12 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_matter_lib.nx nx_dcf_lib.nx nx_dcf_gate.nx nx_finance_svc.nx

imports: nx_matter_lib.nx

imported by: nx_dcf_gate.nxnx_finance_svc.nx

structs

none

consts

21const DCF_MAGIC_1500: i64 = 1500
23const DCF_DF_SCALE: i64 = 1000000 // discount factor carried x1e6 (1.0 = 1000000)
24const DCF_BP_FULL: i64 = 10000 // 100% in basis points
25const DCF_UNDEFINED: i64 = 0 - 2000000001 // terminal value undefined (growth >= rate)
26const DCF_BAD: i64 = 0 - 2000000002 // invalid input (e.g. price <= 0)

functions

29func dcf_discount_factor(rate_bp: i64, period: i64) -> i64
called by 2: maindcf_pv
40func dcf_pv(cashflow: i64, rate_bp: i64, period: i64) -> i64
45func dcf_terminal(final_cf: i64, growth_bp: i64, rate_bp: i64) -> i64
52func dcf_intrinsic(cashflows: *i64, n: i64, rate_bp: i64, terminal_value: i64) -> i64
called by 1: main calls 1: dcf_pv
65func dcf_margin_of_safety_bp(intrinsic: i64, price: i64) -> i64
called by 2: mainfin_dcf_verdict
71func dcf_verdict(intrinsic: i64, price: i64) -> i64
called by 2: mainfin_dcf_verdict
79func dcf_verdict_str(v: i64) -> *u8
called by 2: mainfin_dcf_verdict