From b05e728ae23d088ca6c9ecccf6ed00d2ab6f3839 Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Tue, 22 Sep 2026 08:07:00 +0800 Subject: Add bond full milestone: profile probe, coupon/accrual rules, ledger and point-in-time valuation (3d-29) --- tests/FundLab.Api.Tests/FundValuationTests.fs | 77 ++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'tests/FundLab.Api.Tests/FundValuationTests.fs') diff --git a/tests/FundLab.Api.Tests/FundValuationTests.fs b/tests/FundLab.Api.Tests/FundValuationTests.fs index 1897fd3..197686d 100644 --- a/tests/FundLab.Api.Tests/FundValuationTests.fs +++ b/tests/FundLab.Api.Tests/FundValuationTests.fs @@ -19,6 +19,17 @@ module FundValuationSupport = AccruedInterest = None Date = None MaturityDate = None + ParValue = None + IssuePrice = None + ValueDate = None + ListingDate = None + PublishDate = None + PayInterestDay = None + CouponRate = None + CouponRateExplain = None + BondExpireYears = None + Rating = None + DataStatus = None } let stockProbeReturning (prices: Map) = @@ -109,12 +120,52 @@ type FundValuationTests(fixture: PostgresFixture) = repository().CreateBondTrade( key, fundId, - { InstrumentCode = code; BondName = Some "南航转债"; Quantity = quantity; Price = price } + { + InstrumentCode = code + BondName = Some "南航转债" + Quantity = quantity + Price = price + CleanPrice = price + AccruedInterest = 0m + ParValue = 100m + SettlementDate = DateOnly(2026, 9, 21) + CouponRate = None + ValueDate = None + MaturityDate = None + TradeDate = Some(DateOnly(2026, 9, 21)) + } ) with | BondTradeWriteResult.BondTradeCreated _ -> () | other -> failwithf "unexpected bond trade result: %A" other + let buyBondWithTerms fundId code quantity cleanPrice = + let key = fixture.Key(sprintf "valuation-bond-terms-%s" (Guid.NewGuid().ToString("N"))) + + match + repository().CreateBondTrade( + key, + fundId, + { + InstrumentCode = code + BondName = Some "南航转债" + Quantity = quantity + Price = cleanPrice + CleanPrice = cleanPrice + AccruedInterest = 0m + ParValue = 100m + SettlementDate = DateOnly(2026, 9, 21) + CouponRate = Some 0.02m + ValueDate = Some(DateOnly(2020, 10, 15)) + MaturityDate = Some(DateOnly(2026, 10, 15)) + TradeDate = Some(DateOnly(2026, 9, 21)) + } + ) + with + | BondTradeWriteResult.BondTradeCreated _ -> () + | other -> failwithf "unexpected bond trade result: %A" other + + let app stockPrices bondPrices = App.createApplicationWithProbes (repository ()) (FundValuationSupport.probes stockPrices bondPrices) @@ -142,6 +193,30 @@ type FundValuationTests(fixture: PostgresFixture) = Assert.Contains("\"pricedPositions\":2", body) Assert.Contains("\"unavailablePositions\":0", body) + [] + member _.``bond valuation accrues interest point-in-time and values on a dirty basis``() = + let fundId = createFund 10000.00m + buyBondWithTerms fundId "110075" 10m 106.368m + + let valuationAt asOf = + PersistenceTestHelpers.invoke + (app Map.empty (Map.ofList [ "110075", 106.368m ])) + "GET" + (sprintf "/api/funds/%O/valuation?asOfDate=%s" fundId asOf) + [ "Authorization", "Bearer test-token" ] + "" + + let status, early = valuationAt "2026-09-21" + Assert.Equal(200, status) + Assert.Contains("\"accruedInterest\":\"1.86849300\"", early) + Assert.Contains("\"dirtyPrice\":\"108.23649300\"", early) + Assert.Contains("\"valueBasis\":\"dirty\"", early) + Assert.Contains("\"marketValue\":\"1082.36\"", early) + + let _, later = valuationAt "2026-10-01" + Assert.Contains("\"accruedInterest\":\"1.92328800\"", later) + Assert.Contains("\"marketValue\":\"1082.91\"", later) + [] member _.``all-unavailable valuation keeps cash intact and marks positions unavailable without zeroing``() = let fundId = createFund 5000.00m -- cgit v1.2.3