FinancialDerivatives.jl icon indicating copy to clipboard operation
FinancialDerivatives.jl copied to clipboard

Redesing `evaluate` interface for dispatch, modularity and extensibility

Open mvanzulli opened this issue 7 months ago • 1 comments

Motivation

The current package supports a variety of financial models (e.g., Black-Scholes, Heston, Vasicek) and instruments (e.g., European Options, American Options, FX Options), but tightly couples them via a shared evaluate function. This design limits flexibility and maintainability, making it difficult to:

  1. Add new pricing models without changing existing instrument code
  2. Add new financial instruments without altering model implementations
  3. Handle diverse market data inputs in a consistent way
  4. Introduce model calibration or validation workflows
  5. Test components independently

Proposal: Abstract Interfaces

To decouple components and improve extensibility, we propose defining a set of abstract interfaces:

abstract type FinancialInstrument end
abstract type PricingModel end
abstract type PricingEngine end
abstract type MarketData end

Required Methods

All models and instruments should implement:

required_parameters(::Type{T}) where T <: Union{FinancialInstrument, PricingModel}
validate_parameters(x::Union{FinancialInstrument, PricingModel})
price(engine::PricingEngine, instrument::FinancialInstrument, model::PricingModel, market_data::MarketData)

Type Hierarchy

Instruments

  • Options: EuropeanOption, AmericanOption, BarrierOption, BinaryOption, FXOption, etc.
  • Forwards/Futures: EquityForward, FXForward, InterestRateFuture, etc.
  • Swaps: InterestRateSwap, CrossCurrencySwap, EquitySwap
  • Bonds: FixedRateBond, FloatingRateBond, ZeroCouponBond
  • Credit Derivatives: CreditDefaultSwap, CreditSpreadOption

Market Data

  • EquityMarketData
  • InterestRateMarketData
  • FXMarketData

Pricing Engines

  • BlackScholesEngine
  • HestonEngine
  • BinomialEngine
  • MonteCarloEngine
  • FiniteDifferenceEngine

Models

  • BlackScholesModel
  • HestonModel
  • BinomialModel
  • CoxRossRubinsteinModel
  • JarrowRuddModel
  • LeisenReimerModel

Benefits

  • Modularity: Models and instruments are decoupled, enabling easier maintenance and extension.

  • Testability: Components can be tested independently.

  • Consistency: Unified interface for handling market data and validation.

  • Extensibility: New capabilities can be added easily, such as:

    • Model calibration
    • Sensitivity and risk analysis
    • Integration with external market data feeds
    • Support for custom pricing engines

mvanzulli avatar May 18 '25 23:05 mvanzulli