Skip to content

Conversation

@Thorium
Copy link
Contributor

@Thorium Thorium commented Sep 10, 2025

Summary

This PR introduces the initial Business (B2B) analytical extensions under the namespace FSharp.Finance.B2B.*.

Purpose: provide optional analytics (NOT a full commercial / operational platform) for:

  • Trade credit early‑payment discount implied annual rates
  • Basic invoice factoring parameter construction
  • Lightweight product metadata classification
  • Forward‑looking generic cashflow scaffolding (not yet integrated)

Files Added (Current State)

  • DomainExtensions.fs
    • BusinessProductType DU
    • ProductMetadata record + helper constructors (consumer, tradeCredit, invoiceFactoring)
  • CashflowModel.fs
    • CashflowType DU + CashflowEvent record (future-facing abstraction; not yet wired in)
  • TradeCredit.fs
    • DiscountTerms, createTerms
    • impliedAnnualRateSimple
    • impliedAnnualRateCompounded
  • InvoiceFactoring.fs
    • Invoice, InvoiceAdvance (derive)
    • FactoringParameters.build(Parameters * InvoiceAdvance list)
  • Docs: docs/exampleTradeCreditAndFactoring.fsx
  • README: B2B section added

Design Decisions

Aspect Decision
Namespace boundary All new code under FSharp.Finance.B2B.*
APR handling Reuse Apr.CalculationMethod.UnitedKingdom 2 (placeholder)
Factoring modeling Single repayment per invoice at face value (advance + reserve implicit)
Product metadata Non-regulatory, descriptive only
Cashflow model Present but not integrated yet (reserved for future factoring / reserves modeling)

Trade Credit Rate Formulas

Let d = discountPercent, D = discount deadline day, N = net due day.

Simple annualized (no intra-year compounding):
rate_simple = (d / (1 - d)) * (365 / (N - D))

Naive compounded:
rate_compounded = (1 + d / (1 - d))^(floor(365 / (N - D))) - 1

Comments in code document rationale and limitations.


Documentation Example

docs/exampleTradeCreditAndFactoring.fsx:

  • Demonstrates “2/10 net 30” implied rates
  • Builds factoring parameters for multiple invoices
  • Prints schedule basics & economics
  • Includes disclaimers

Tests (Planned / Needed)

  • TradeCreditTests.fs
    • Assert impliedAnnualRateSimple for 2/10 net 30 ≈ 0.3724 (tolerance ±0.0001m)
  • (Optional follow-up) factoring structural integrity test

Checklist

  • Add B2B source modules
  • Update README
  • Add documentation example
  • Add trade credit unit test

Open Questions

  1. Should this be it's own nuget package, because it's not "Personal", however the same business shares the benefit of current amortisation.
  2. Introduce AprMethod.Disabled in a future minor version for zero-interest cases?
  3. Explicit reserves as separate modeled cashflows later (integrating CashflowModel)?
  4. Future consolidation into a neutral FSharp.Finance.Analytics namespace (backward-compatible duplication)?

Non-Goals (Current Iteration)

  • Operational factoring workflows (collections, dilution)
  • Risk / expected loss modeling
  • Multi-currency support
  • Regulatory classification

Disclaimer

Analytical utilities only. Independent validation required for production or compliance use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant