普贤教程 › 包参考
finance 包
财务计算
| 项 | 值 |
|---|---|
| 包名 | finance |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | finance.px |
| 分类 | 数学与统计 |
| 文件数 / 行数 | 1 / 249 |
安装与引入
bash
pxpkg init # 首次 pxpkg add finance@0.2.0 pxpkg install
px
import finance所属分类教程:数学与统计
公开接口
| 函数 | 参数 |
|---|---|
fin_pmt | rate, nper, pv, fv = 0 |
fin_pv | rate, nper, pmt, fv = 0 |
fin_fv | rate, nper, pmt, pv = 0 |
fin_nper | rate, pmt, pv, fv = 0 |
fin_rate_guess | pmt, pv, nper |
fin_amortize | principal, rate, nper |
fin_amortize_round | principal, rate, nper, digits = 2 |
fin_total_interest | schedule |
fin_simple_interest | principal, rate, time |
fin_compound_interest | principal, rate, time, freq = 1 |
fin_effective_rate | nominal, freq |
fin_nominal_rate | effective, freq |
fin_npv | rate, cashflows |
fin_irr | cashflows |
fin_payback | cashflows |
fin_roi | cost, gain |
fin_tax | amount, rate |
fin_tax_bracket | amount, brackets |
fin_discount | price, discount_pct |
其余 2 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
fin_round | x, digits = 2 |
fin_markup | cost, margin_pct |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/finance — 财务计算 ------------------------------------------------------------ 纯函数库,双模式一致。 实现要点(统一口径,正数表示现金流出/利息支出): payment > 0 每期还款额 interest > 0 当期利息 = 上期余额 × 期利率 principal > 0 当期本金 = payment - interest balance >= 0 期末剩余本金,逐期递减 payment == interest + principal(逐行自洽) 末期把浮点残差抹平(最后一期本金 = 剩余余额,余额归零)。 另新增 fin_amortize_round(principal, rate, nper, digits) 与 fin_total_interest()。 对齐 PHP 财务扩展 / numpy-financial / Excel 财务函数: fin_pmt(rate, nper, pv, fv = 0) → 每期还款额(等额本息) fin_pv(rate, nper, pmt, fv = 0) → 现值 fin_fv(rate, nper, pmt, pv = 0) → 终值 fin_nper(rate, pmt, pv, fv = 0) → 期数 fin_rate_guess(pmt, pv, nper) → 利率估算(牛顿迭代) fin_amortize(principal, rate, nper) → 摊销表 [{period, payment, interest, principal, balance}] fin_simple_interest(principal, rate, time) → 单利 fin_compound_interest(principal, rate, time, freq = 1) → 复利 fin_effective_rate(nominal, freq) → 实际年利率 fin_nominal_rate(effective, freq) → 名义年利率 fin_npv(rate, cashflows) → 净现值 fin_irr(cashflows) → 内部收益率(牛顿迭代) fin_payback(cashflows) → 投资回收期 fin_roi(cost, gain) → 投资回报率 fin_tax(amount, rate) → 税额 fin_tax_bracket(amount, brackets) → 阶梯税率 fin_discount(price, discount_pct) → 折后价 fin_markdown(cost, margin_pct) → 成本加成定价 ============================================================