Repository navigation
Dec 26 - #363
Open
yellowbean wants to merge 18 commits into
Open
Dec 26#363yellowbean wants to merge 18 commits into
yellowbean wants to merge 18 commits into
Conversation
* Fix#326: totalize Hermite slope helpers (no head/last/tail) - secantSlopes via pattern matching; total for 0/1/n points, no tail - remove unused top-level initialSlopes (shadowed by local one, zero callers) - Fritsch-Carlson initial slopes in one pass: first secant, harmonic means of adjacent secants, last secant; direct [] / [_] clauses in fritschCarlsonSlopes replace the length<2 guard - adjustSlopes monotonicity filter numerically unchanged - hermiteTest 3 -> 7: multi-date singleton/empty curves, 4-point node reproduction, 3-point interior, pv4 pricing a single-point curve against pv2 oracle - old-vs-new slope equivalence verified exhaustively on 19,530 delta sequences; full suite 551/551 pass * Fix#355: remove 17 redundant pattern branches (-Woverlapping-patterns) - all 17 dead branches were defensive catch-alls or refactor leftovers behind exhaustive matches; enumerated constructor counts per site (TxnComment 31, PoolSource 13, InterestInfo 7, Bond 3, BondType 8, AssetUnion 7, RateAssumption 2, AmortRule 2, single-ctor LiqFacility/SrtType) - DealAction.hs: drop the two dead 'Missing revolving Assumption' clauses in performActionWrap, subsumed by the BuyAsset -> BuyAssetFrom delegation clause and the Nothing-assumption clause above them - behavior-preserving: unreachable code only; no exported signature, JSON, or reachable-error-message changes - clean build: 0 x -Woverlapping-patterns (was 17); full suite 551/551 * build: enable -O2 for library, executable and test suite (#357 Tier 1) Override cabal's default -O1 for every component. -fllvm is left off because the LLVM toolchain is not part of shell.nix. No behaviour change; all 551 tests pass.
Add exact integer fast paths for mulBR, mulBIR, mulBI, mulBInt, divideBI and divideBB. Data.Fixed.fromRational floors (including for negative values), so the fast path uses div; divideBI preserves the legacy RatioZeroDenominator exception on a zero divisor. Add legacy-oracle UTs covering rounding edges, negative values, large/repeating rates and deterministic sweeps. All 592 tests pass.
Replace quadratic acc ++ [row] / trs ++ [row] accumulation with Data.DList in the mortgage default/schedule/delinquency projections, buildCollectedCF and nextLeaseTill. Carry the previous balance/borrower/factor/last row explicitly instead of calling last on the growing accumulator. Stressed 500-asset runPool: 1.22s -> 0.30s (-N1); unstressed path unchanged. All 592 tests pass, including a differential check of the delinquency schedule path against the pre-change build.
Replace the O(n * residual) elem scan in prorataFactors with IntSet membership. residual is typically O(n), so this removes an O(n^2) term from pool-level DefaultByAmt and other pro-rata allocations. Add a legacy elem oracle plus edge-case UTs for empty/single/zero/negative balances, amount caps, residual ties and a 2000-asset list. All 602 tests pass.
Add a forward-cursor fast path for getValByDates when curve points and input dates are ascending, avoiding a reversed-list allocation and O(n) scan for every date. Descending dates fall back lazily for the remaining suffix; unsorted points and unsupported curve types use the legacy per-date lookup, so results are unchanged. Add legacy-oracle UTs covering Inc/Exc, duplicates, exact boundaries, before/after-range dates, descending and mixed date order, unsorted points, empty curves/dates, FactorCurveClosed, ThresholdCurve and PricingCurve. 609 tests pass.
getObligorFields/getObligorTags/getObligorId/getOriginInfo are Asset class methods already shipped by Asset(..); getSpread is already exported by UseRate(..). The explicit re-exports made GHC -Wduplicate-exports fire on every build. All names stay exported, so this is a pure warning fix with no API or behavior change. Verified by typecheck and 609/609 tests. The remaining 3 duplicates (_Bond/_MultiIntBond/_BondGroup in Liability.hs) are deferred until that file's WIP work lands.
All 34 copies of 'debug = flip trace' project-wide are dead (zero non-comment call sites); this removes the 24 copies in non-WIP modules (23 src files + app/Main.hs) plus the lone unused import in MixedAsset.hs. The copies in the 9 WIP files and unbuilt StudentLoan.hs are deferred. No behavior change: the bindings were unused; imports imported nothing else. Verified: build clean, 609/609 tests, lib census deltas unused-top-binds 94->71, missing-signatures 35->12, unused-imports 404->403, all other flags unchanged.
…onflict spacing (#356) - 27 stale hiding clauses fixed: 'import Data.Aeson hiding (json)' (aeson>=2 dropped the alias) in 21 non-WIP modules, 'Data.Fixed hiding (Ratio)', 'Types hiding (Current)' x2, 'Types hiding (getOriginDate)'. 12 of the Data.Aeson imports became instance-only and are now 'import Data.Aeson ()' (GHC-suggested), the rest are kept as used. - Dead internal code removed (11 bindings, all unexported with zero call sites; 9 GHC-confirmed 'Defined but not used'): Util.mulIntegerR/debugLine/testSumToOne, Lib.addD/floatToFixed, Asset.normalPerfVector, Deal.updateSrtRate/queryTrigger (which also frees the Triggers import), Lease.calcGapDays, DealBase data ActionTypeOnDate (DoSettle/DoAccrue/DoUpdateRate) + data UnderBond - both absent from the deriveJSON splice, so no JSON output changes. - Util.hs:185: 'fromMaybe 0 $findIndex' -> '$ findIndex' (same parse, silences -Woperator-whitespace-ext-conflict). Lib warning census vs the 28ec30e baseline: dodgy-imports 37->10 (remaining are in WIP files), duplicate-exports 8->3 (earlier commit), unused-top-binds 94->56, missing-signatures 35->12, total 2744->2634. Tests: 609/609 PASS. No API or behavior change.
Build each target once, then publish the original binary alongside a stripped copy (macOS re-signed after strip). Add a smoke test that starts the stripped binary and requires a successful /version response before release upload. Document the new asset names and variants.
After stripping, pack a copy with UPX -9 for Linux and Windows and smoke-test it alongside the stripped binary before publishing. macOS is excluded because UPX does not support Mach-O.
…nge (#359) interpolateWithHermite used Piecewise.interpolate, which throws "interpolate: argument outside range" for queries at or beyond the last node. pv4 feeds bond cashflow dates straight into it, so a cashflow on the curve's final date (or later) escaped as a runtime exception (HTTP 500 via warp) instead of pricing - even though the engine's own bond-pricing curves are flat and getValByDate (used by duration/convexity) already holds the last point flat. Switch to Piecewise.interpolateConstantExt: bit-identical in-range (verified on a dense 40-point grid against interpolation-0.1.1.2) and constant extension on both borders, so a query at/beyond the last node returns the last node's yield and a query before the first node returns the first yield. Regression tests (hermiteTest): - query exactly at the last node -> that node's yield - query beyond the last node -> last yield (flat) - pv4 cashflow exactly at / beyond the last curve date -> Right, matching the flat-rate pv2 oracle Tests: 591/591 (clean tree) and 613/613 (working tree incl. WIP)
…#359 follow-up) pv4 only validated that the pricing curve does not start before the valuation date. A multi-point curve starting after the first cashflow was accepted: since fa0520f it silently discounted those cashflows at the first node's rate (before that it threw "interpolate: argument outside range"), while the risk path (pv -> getValByDate) priced the same cashflows at 0%. Enforce pricingDate <= firstCurveDate <= firstCashflowDate for multi-point curves: reject with a typed Left when the first cashflow is strictly before the curve start. The long-end constant extension stays (the curve horizon is an assumption); single-point curves keep their existing flat-rate semantics at all dates (they never take the Hermite path) and are therefore exempt. Tests: pv4 accepts a curve starting at the first cashflow (node rate exact), rejects a cashflow before the curve start with the new Left, and keeps the single-point flat rate for a pre-node cashflow. 594/594 clean tree; 616/616 on the working tree (WIP applied).
follow-up) PV (pv4) used Hermite-interpolated rates while duration/convexity read the curve through getValByDate (step for IRateCurve, linear for PricingCurve, Inc/Exc mixed in convexity), and asset PV (pv3) / Z-spread (pv) used yet another lookup. One PriceResult could mix three different rate curves; measured on a 3-CF bond: PV 1013.42 vs the duration path's implied PV 1002.13, convexity 0.0887 vs the PV-consistent 10.3236. - Add one canonical discount-rate evaluator, curveRatesAt: Hermite (Fritsch-Carlson) with constant extension at both borders, matching pv4; flat/single/empty curves short-circuit (flat keeps legacy arithmetic bit-identical); exotic Ts types fall back to getValByDate. - Add pvWithRate (same arithmetic as pv) and route pv, pv3, pv3', calcDuration and calcConvexity through the canonical evaluator. - Fix calcConvexity's foldr: it ignored the accumulator, so only the first cashflow's term survived (e.g. 0.0887 vs 10.44 on a 3-CF bond; the single-cashflow test could not see it). - getValByDate is unchanged and still serves non-discount lookups (triggers, resets, lease/mortgage rates, DealQuery). PV for flat/single/empty curves is unchanged; bond and asset PVs now agree on multi-point curves. Existing expected values updated where they encoded the bugs (BondTest PriceResult duration/convexity, assetPricingTest convexity and the first-CF node rate). Tests: +15 (curve consistency, node dates, flat/duplicate/empty/short-end, exotic fallback, pv/pv3/pv4 parity, asset PVCurve path, Z-spread round-trip, foldr summation). 609/609 clean tree; 631/631 with the in-flight WIP.
…359 follow-up) pv4 used getTsDates/getTsVals directly, which are non-exhaustive/error on Ts constructors outside the five rate types (IRate/Ratio/Float/Pricing/Balance): ThresholdCurve, BoolCurve, FactorCurveClosed etc. threw a runtime pattern-match failure instead of a typed error. Guard pv4 with isHermiteCurve and return Left "pv4: unsupported pricing curve type: <Type>". Supported curve types still price exactly as before (regression test covers all five), so the Either contract of pv4/priceBond now covers every Ts input. pv/pv3/duration/convexity keep their total getValByDate fallback by design. Tests: 2 new (unsupported type => Left with the exact tag; all five supported types price). 611/611 clean tree; 633/633 with the in-flight WIP.
- Interface: add the MultiIntLiable subclass for multi-interest bonds; move getDueIntAt/getDueIntOverIntAt/getTotalDueIntAt out of the general Liable class. - Assets: add termEndDate/rateResetDatesOverTerm helpers and implement getIndexes/getSpread/getResetDates (plus origin balance/rate accessors) across Mortgage, Loan, Installment, Lease, FixedAsset, Receivable and ProjectedCashFlow; re-investment accounts return their index. - Liabilities: same accessors for bonds, expenses, hedges, credit enhancements and accounts. - Tests: UseRate/getIndexes/getSpread/getResetDates coverage per type, WAL ByQuarter cases, Receivable/FixedAsset origin accessors, pv4 Left cases. - README: protobuf note.
Zero-API-risk batch from the #365 tracker. Every removed name is flagged by GHC's -Wunused-top-binds (which only fires for non-exported bindings), so no public API changes. - Stale dodgy imports: 8 x 'Data.Aeson hiding (json)' removed; AssetBase's 'Types hiding (Current,originTerm)' reduced to the real 'startDate' hide. - Duplicate exports: drop Liability's repeated _Bond/_MultiIntBond/_BondGroup line. - Dead code: 9 'debug = flip trace' copies (+ Debug.Trace imports), 19 internal type synonyms, 14 unused lens bindings (removed from makeLensesFor lists), 14 unused functions (incl. pv3', toTimeYield, emptyTxn, getIndexRateByDates, buildSrtAccrueAction/buildSrtResetAction, calcAvailFund, eval, getDefaultLagAndRate). - Dodgy exports: IRR(..)/RateReset(..)/DistributionSeq(..) -> plain names. - Missing signatures: add epocDate/emptyCashflow; drop dead dealStatType. - Remove imports orphaned by the above (Ledger Control.Lens, Types Data.Map, Liability Lib names). Lib census: 2630 -> 2516; dodgy-imports 10->0, duplicate-exports 3->0, dodgy-exports 3->0, unused-top-binds 56->0, missing-signatures 12->0. Tests: 633/633.
GHC-proven redundant imports only; no runtime, API, or instance change. - 372 whole-module imports whose names are unused are reduced to the instance-only form 'import M ()' (or 'import qualified M as X ()'), so instance availability is unchanged. - 17 explicit import lists pruned of unused names (including 4 multi-line lists, plus the Reports multi-line list), all by the names GHC reported. - Where an import becomes fully empty it is kept as '()' rather than deleted, because GHC hedges on instance usage. Lib census: 2516 -> 2127; Wunused-imports 389 -> 0. Tests: 633/633. Deliberately excluded: behavior-changing classes (incomplete patterns, x-partial, orphan-instance restructuring).
Expanded the 87 leading tabs in Assumptions/DealAction/DealRun/Deal with expandtabs(8), preserving GHC's 8-column tab stops so layout is unchanged. Verified no tab occurred inside a string literal before rewriting. Wtabs 4 -> 0; tests 633/633.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Override cabal's default -O1 for every component. -fllvm is left off because the LLVM toolchain is not part of shell.nix. No behaviour change; all 551 tests pass.