lmfinance
lmfinance is a native lmcode host that puts QuantLib behind an LMScript _lmcode_ block: yield curves, bonds, swaps, caps, floors and swaptions, vanilla, barrier and Asian options, Greeks, value at risk and Heston calibration in one executable. It is a scripting host, not a command-line calculator: lmscript compiles the block against the schema embedded in the binary and runs it with run_lmcode.
Install and run
npm install -g @lmctl-ai/lmctl
lmscript bs.lms
lmctl https://raw.githubusercontent.com/lmctl-ai/lmfinance/main/examples/option_pricing.lms
The install attribute of the block downloads the lmfinance release binary for the platform on first use and verifies its SHA-256; no separate installation step is needed. The current release is lmfinance 0.1.4. Linux binaries need dynamic glibc 2.35 or newer (Ubuntu 22.04 or newer); QuantLib and the C++ runtimes are linked statically.
Minimal example
# bs.lms: Black-Scholes call S=100 K=100 r=5% vol=20% T=1 is worth 10.4506
prog = _lmcode_ cli="lmfinance" install="github:lmctl-ai/lmfinance@latest";
let m = model.black_scholes(100.0, 0.05, 0.0, 0.2);
let call = instrument.european_call(100.0, 1.0);
let res = pricing.price(call, m, pricing.analytic());
lmf.print("price " + str(res.price()) + " delta " + str(res.delta()));
lmf.assert_close(res.price(), 10.4506, 0.00005);
lmcode_return_put("price", res.price());
lmcode_return_put("delta", res.delta());
end _lmcode_
r = run_lmcode(prog);
println(json_stringify(r));
require(r.ok, "pricing run failed");
lmscript bs.lms
price 10.4505835721856 delta 0.636830651175619
{"ok":true,"result":{"price":10.450583572185577,"delta":0.6368306511756194}}
CLI flags and host protocol
| Invocation | Effect | Exit |
|---|---|---|
| lmfinance --version | Prints lmfinance X.Y.Z (exactly this form, used by the installer) | 0 |
| lmfinance --notices | Prints the embedded third-party license texts (QuantLib, Boost, runtimes) | 0 |
| lmfinance --lmcode-schema --json | Prints the exact embedded schema bytes (dsl.schema 2) that lmscript compiles against | 0 |
| lmfinance --lmcode-schema | Prints the registry signatures as text, one per line | 0 |
| lmfinance --lmcode-signatures | Prints the same signature list: 320 lines in 0.1.4 (7 contexts, 107 host methods, 206 standard signatures) | 0 |
| lmfinance --lmcode FILE [FILE ...] | Loads and verifies every compiled program first, then runs them in order and writes one result frame; this is what run_lmcode calls | 0, 3 or 4 |
| lmfinance --dry-run --lmcode FILE [FILE ...] | Loads and verifies every program but runs none | 0 or 3 |
| anything else | Usage text on stderr and a cli failure frame | 2 |
Exit codes: 0 success, 2 command-line or invocation metadata error, 3 program load or run error, 4 application or output failure. The environment variable LMFINANCE_MAX_MEMORY_MB sets the total memory budget in MiB (default 4096).
Context objects
Seven context objects are in scope inside the block. Rates are decimals (0.05), volatilities are annual, maturities are years, dates are YYYY-MM-DD strings, and float arguments need a decimal point (100.0, not 100).
| Context | Main members | Returns |
|---|---|---|
| market | set_date, date, flat_curve(rate), zero_curve(), bootstrap_curve() | Curve, or a CurveBuilder with zero, deposit, swap and build |
| instrument | european_call, european_put, american_call, american_put, barrier_call, barrier_put, asian_call, asian_put, bond, zero_bond, swap, cap, floor, swaption | Option, Bond, Swap, CapFloor, Swaption |
| model | black_scholes(spot, rate, dividend, vol), heston(spot, rate, dividend, v0, kappa, theta, sigma, rho) | Model with spot, param, with_spot, with_rate, with_vol |
| pricing | Engines analytic, binomial, binomial_tree, finite_diff, monte_carlo, baw; price(option, model, engine); bond_*, swap_*, capfloor_* and swaption_* valuations | Engine, Result (price, stderr, delta, gamma, vega, theta, rho), float |
| risk | Bumped delta, gamma, vega, rho, theta; bond_dv01, swap_dv01; var_normal, es_normal; series(path); save_profile | float, Series (size, get, mean, std, min, max, quantile, var, es) |
| calibration | implied_vol(option, model, engine, price); heston(spot, rate, dividend) | float, HestonFit (quote, guess, fit, error) |
| lmf | assert_close(a, b, tolerance), check(bool, message), print(text), save_text(path, text), version() | void, string |
The schema also carries the standard lmcode_std_v3 library as vendored by lmfinance 0.1.4: 206 signatures (strings, math, files, collections, Json, the lmcode_return result sink). The current catalog in lmcode-cpp has 226 signatures including the REST and CLI interfaces; lmfinance picks those up when it next syncs and releases.
Detail pages
- Skill: install, commands, safety rules, worked examples, errors and verification for agents
- Guide: domain model, market conventions, engines, architecture and limits
- Reference: every type, method, context object, flag, exit code and standard library signature
- GitHub repository lmctl-ai/lmfinance: source, examples and gallery