Minor-unit money, periodic cash-flow estimates, and rounded loan schedules for MoonBit
金额使用整数最小单位,财务指标使用浮点估算。
$env:MOONBIT_INSTALL_VERSION = "0.10.16+b1a0e846e"
irm https://cli.moonbitlang.com/install/powershell.ps1 | iexcurl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s -- '0.10.16+b1a0e846e'git clone https://github.com/Lyllyl789/aurum.git
cd aurum
git rev-parse HEAD
moon version --all
moon fmt --check
moon check
moon test
moon run bin
moon run examples/use-cases
moon run examples/readmemoon fmt --check
moon check
moon test
moon test lib/money lib/tvm lib/capital lib/amortize lib/integration
moon test lib/capitalmoon check --target js
moon test --target js
moon run --target js bin
moon run --target js examples/use-cases
moon run --target js examples/readmeaurum/
├── lib/ # 核心库
│ ├── money/ # 精确金额与舍入
│ ├── tvm/ # 货币时间价值
│ ├── capital/ # 资本预算
│ ├── amortize/ # 贷款摊销
│ ├── wear/ # 固定资产折旧
│ ├── bond/ # 债券定价
│ ├── ratio/ # 财务比率
│ └── currency/ # 多币种与汇率
├── bin/ # 命令行演示
├── examples/
│ ├── readme/ # README 完整导入与运行示例
│ └── use-cases/ # 三个固定输入场景
├── notes/ # 设计笔记
└── moon.modimport {
"Lyllyl789/aurum/lib/money",
"Lyllyl789/aurum/lib/tvm",
"Lyllyl789/aurum/lib/capital",
"Lyllyl789/aurum/lib/amortize",
}
pkgtype(kind: "executable")///|
fn main {
let a = @money.Money::of(12345, "CNY")
let b = @money.Money::of(100, "CNY")
println("金额合计 CNY = " + a.add(b).to_decimal_string())
let invoice = match @money.Money::parse("100.00", "CNY") {
Some(value) => value
None => abort("invalid invoice")
}
let shares = match invoice.allocate_by_weights([1, 2, 3]) {
Some(value) => value
None => abort("invalid weights")
}
for share in shares {
println("份额 CNY = " + share.to_decimal_string())
}
match @tvm.future_value(10000.0, 0.05, 10) {
Some(value) => println("终值估算 = " + value.to_string())
None => abort("invalid TVM input or non-finite result")
}
match @capital.net_present_value(0.10, [-1000.0, 300.0, 400.0, 500.0]) {
Some(value) => println("NPV 估算 = " + value.to_string())
None => abort("invalid cashflows or non-finite result")
}
let rows = match
@amortize.equal_installment_money_schedule(
@money.Money::of(1000000, "CNY"),
0.01,
12,
@money.round_half_up(),
) {
Some(value) => value
None => abort("invalid loan input or overflow")
}
let summary = match @amortize.summarize_money_schedule(rows) {
Some(value) => value
None => abort("loan reconciliation failed or overflow")
}
println("贷款总利息 CNY = " + summary.interest.to_decimal_string())
println(
"贷款期末余额 CNY = " + summary.ending_balance.to_decimal_string(),
)
}金额合计 CNY = 124.45
份额 CNY = 16.67
份额 CNY = 33.33
份额 CNY = 50.00
终值估算 = 16288.946267774423
NPV 估算 = -21.03681442524436
贷款总利息 CNY = 661.86
贷款期末余额 CNY = 0.00moon add Lyllyl789/aurum@0.1.0import {
"Lyllyl789/aurum/lib/money",
"Lyllyl789/aurum/lib/tvm",
"Lyllyl789/aurum/lib/capital",
"Lyllyl789/aurum/lib/amortize",
}
pkgtype(kind: "executable")| 模块 | 当前实现的返回与校验 |
|---|---|
| amortize | 浮点 API 要求有限本金、每期利率大于 -1、期数大于 0;返回 Double? 或 Array[Payment]?。Money 计划要求正本金、非负每期利率,利息逐期按指定舍入模式到币种最小单位;可传入可选额外本金,提前结清后的行置零,最后一个非零还款调整为结清余额。summarize_money_schedule 校验期号、币种、逐期加总和余额衔接,并汇总本金/利息/还款。 |
| wear | 成本与残值须有限,使用年限须大于 0;逐年函数的年份须在 1 到使用年限内,工作量法的总工作量须有限且大于 0、当期工作量须有限。结果非有限返回 None。当前未强制成本、残值和工作量的财务业务关系;调用方须自行确认残值不高于成本及当期工作量的业务范围。 |
| bond | 票息、面值、收益率或市价中实际使用的输入须有限,期数须大于 0;定价依赖 tvm 的 rate > -1 约束。零价格使久期/凸性返回 None;到期收益率在实现的搜索范围内无法括根或计算失败也返回 None。 |
| ratio | 任一参与计算的输入非有限、分母为 0 或比值非有限时返回 None。它不检查各指标的财务业务关系。 |
| currency | lookup 只查询上述 12 种币种,未知代码返回 None。cross_rate 要求两个正且有限的外部汇率,乘积非有限时返回 None。convert 要求正且有限的外部 rate 与受支持目标币种;非有限或舍入后超出 Int 范围的结果返回 None。 |
Install
Download zipMinor-unit money, periodic cash-flow estimates, and rounded loan schedules for MoonBit