tensorquant.pricers package
Submodules
tensorquant.pricers.black module
- class tensorquant.pricers.black.BlackScholesPricer(dividend_model: str = 'continuous', use_implied_repo: bool = True)[source]
Bases:
Pricer- calculate_price(product: VanillaOption, market_env: MarketEnvironment) Tensor[source]
Price a VanillaOption using Black-Scholes (European) or Bjerksund-Stensland 1993 (American).
Delegates market-data extraction to
_build_inputs(). Intermediatetf.Variableinputs are stored onselfso that an externalGradientTape(managed byPricer.price()) can compute greeks.- Parameters:
product (VanillaOption) – The option to be priced.
market_env (MarketEnvironment) – The market environment providing access to market data (curves, spots, volatilities).
- Returns:
The NPV of the option.
- Return type:
tf.Tensor
- tensorquant.pricers.black.bjerksund_stensland_calc(spot_price: Tensor, strike: Tensor, riskfree_rate: Tensor, volatility: Tensor, time_to_maturity: Tensor, dividend_yield: Tensor, option_type: OptionType) Tensor[source]
American option price via the Bjerksund-Stensland (1993) approximation.
- Handles calls directly and puts via put-call symmetry:
AmPut(S, K, r, b, σ, T) = AmCall(K, S, r-b, -b, σ, T)
- Parameters:
spot_price – Spot (or spot-net for discrete-dividend model).
strike – Strike price.
riskfree_rate – Continuously compounded risk-free rate.
volatility – Implied volatility.
time_to_maturity – Time to expiry in year fractions.
dividend_yield – Continuous dividend yield
q(0 for discrete model).option_type –
OptionType(CallorPut).
- Returns:
American option price.
- Return type:
tf.Tensor
- tensorquant.pricers.black.blackscholes_calc(spot_price: Tensor, strike: Tensor, riskfree_rate: Tensor, volatility: Tensor, time_to_maturity: Tensor, dividend_yield: Tensor, option_type: OptionType) Tensor[source]
European Black-Scholes price for a call or put.
Uses the unified
φformulation so that a single expression handles both option types without branching:price = φ · [S·exp(-q·T)·N(φ·d1) - K·exp(-r·T)·N(φ·d2)]
where φ = +1 for calls and φ = -1 for puts.
- Parameters:
spot_price – Spot (or dividend-adjusted spot for discrete model).
strike – Strike price.
riskfree_rate – Continuously compounded risk-free rate
r.volatility – Implied volatility
σ.time_to_maturity – Time to expiry in year fractions
T.dividend_yield – Continuous dividend yield
q(repo included).option_type –
OptionType—Call(+1) orPut(-1).
- Returns:
Option price.
- Return type:
tf.Tensor
tensorquant.pricers.deposit module
- class tensorquant.pricers.deposit.DepositPricer[source]
Bases:
Pricer- calculate_price(product: Deposit, market_env: MarketEnvironment) float[source]
Price a Deposit using discount curve.
- Parameters:
product (Deposit) – The deposit to be priced.
market_env (MarketEnvironment) – The market environment providing access to market data (curves).
- Returns:
The NPV of the deposit.
- Return type:
float
- Raises:
TypeError – If the product is not a Deposit.
ValueError – If the discount curve is not found.
tensorquant.pricers.factory module
tensorquant.pricers.fixedflow module
Pricing di cash flow fissi
- class tensorquant.pricers.fixedflow.FixedCouponDiscounting(coupon: FixedCoupon)[source]
Bases:
object
tensorquant.pricers.floatingflow module
- class tensorquant.pricers.floatingflow.FloatingCouponDiscounting(coupon: FloatingCoupon)[source]
Bases:
object
- class tensorquant.pricers.floatingflow.FloatingLegDiscounting(leg: FloatingRateLeg)[source]
Bases:
object
- class tensorquant.pricers.floatingflow.OisCouponDiscounting(coupon: FloatingCoupon)[source]
Bases:
object
- class tensorquant.pricers.floatingflow.OisLegDiscounting(leg: FloatingRateLeg)[source]
Bases:
object
tensorquant.pricers.fradiscounting module
- class tensorquant.pricers.fradiscounting.FraPricer[source]
Bases:
Pricer- calculate_price(product: Fra, market_env: MarketEnvironment) float[source]
Price a Forward Rate Agreement (FRA).
- Parameters:
product (Fra) – The FRA to be priced.
market_env (MarketEnvironment) – The market environment providing access to market data (curves).
- Returns:
The NPV of the FRA.
- Return type:
float
- Raises:
TypeError – If the product is not a Fra.
ValueError – If the discount or forward curve is not found.
tensorquant.pricers.pricer module
- class tensorquant.pricers.pricer.Pricer[source]
Bases:
ABCAbstract base class for pricing financial products.
This abstract class defines the interface for pricing financial products. Concrete implementations must provide a method for calculating the price of a product based on the trade date and market curves.
- calculate_price()[source]
Abstract method to be implemented by subclasses to calculate the price of a product.
- price()[source]
Calculates the price of a product and optionally returns the gradient if autodiff is enabled.
- abstract calculate_price(product, market_env: MarketEnvironment)[source]
Abstract method to calculate the price of a financial product.
- Parameters:
product (Product) – The financial product to be priced.
market_env (MarketEnvironment) – The market environment providing access to market data (curves, spots, volatilities).
- Returns:
The calculated price of the product.
- Return type:
float
Notes
This method must be implemented by any subclass of Pricer.
- price(product: Product, market_env: MarketEnvironment, autodiff: bool = False)[source]
Calculates the price of a financial product, with optional automatic differentiation.
- Parameters:
product (Product) – The financial product to be priced.
market_env (MarketEnvironment) – The market environment providing access to market data (curves, spots, volatilities).
autodiff (bool, optional) – Whether to compute gradients using TensorFlow’s autodiff. Defaults to False.
- property tape
tensorquant.pricers.swapdiscounting module
- class tensorquant.pricers.swapdiscounting.OisPricer[source]
Bases:
Pricer- calculate_price(product: Ois, market_env: MarketEnvironment)[source]
Price an Overnight Indexed Swap (OIS).
- Parameters:
product (Ois) – The OIS to be priced.
market_env (MarketEnvironment) – The market environment providing access to market data (curves).
- Returns:
The NPV of the OIS.
- Return type:
float
- Raises:
TypeError – If the product is not an Ois.
ValueError – If the discount curve is not found.
- class tensorquant.pricers.swapdiscounting.SwapPricer[source]
Bases:
Pricer- calculate_price(product: Swap, market_env: MarketEnvironment)[source]
Price a plain vanilla interest-rate swap.
- Parameters:
product (Swap) – The swap to be priced.
market_env (MarketEnvironment) – The market environment providing access to market data (curves).
- Returns:
The NPV of the swap.
- Return type:
float
- Raises:
TypeError – If the product is not a Swap.
ValueError – If the discount or estimation curve is not found.