Multiasset Monte-Carlo Models

class BsmNdMc(sigma, cor=None, intr=0.0, divr=0.0, rn_seed=None, antithetic=True)[source]

Monte-Carlo simulation of multiasset (N-d) BSM (geometric Brownian Motion)

Examples

>>> import pyfeng as pf
>>> spot = np.ones(4)*100
>>> sigma = np.ones(4)*0.4
>>> texp = 5
>>> payoff = lambda x: np.fmax(np.mean(x,axis=1) - strike, 0) # Basket option
>>> strikes = np.arange(80, 121, 10)
>>> m = pf.BsmNdMc(sigma, cor=0.5, rn_seed=1234)
>>> m.simulate(n_path=20000, tobs=[texp])
>>> p = []
>>> for strike in strikes:
>>>    p.append(m.price_european(spot, texp, payoff))
>>> np.array(p)
array([36.31612946, 31.80861014, 27.91269315, 24.55319506, 21.62677625])
delta(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

delta_numeric(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

forward(spot, texp)

Forward price

Parameters
  • spot – spot price

  • texp – time to expiry

Returns

forward price

gamma(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

gamma_numeric(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

impvol(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

impvol_brentq(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

params_kw()

Model parameters in dictionary

pdf_numeric(strike, spot, texp, cp=- 1, h=0.001)

Probability density functin (PDF) at strike

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

probability densitiy

price(strike, spot, texp, cp=1)

Call/put option price.

Parameters
  • strike – strike price.

  • spot – spot (or forward) prices for assets. Asset dimension should be the last, e.g. (n_asset, ) or (N, n_asset)

  • texp – time to expiry.

  • cp – 1/-1 for call/put option.

Returns

option price

price_european(spot, texp, payoff)[source]

The European price of that payoff at the expiry.

Parameters
  • spot – array of spot prices

  • texp – time-to-expiry

  • payoff – payoff function applicable to the time-slice of price path

Returns

The MC price of the payoff

simulate(tobs, n_path, store=True)[source]

Simulate the price paths and store in the class. The initial prices are normalized to 0 and spot should be multiplied later.

Parameters
  • tobs – array of observation times

  • n_path – number of paths to simulate

  • store – if True (default), store path, tobs, and n_path in the class

Returns

price path (time, path, asset) if store is False

theta(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

theta_numeric(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

vanna(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vanna_numeric(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vega(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vega_numeric(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

volga(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

volga_numeric(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

class NormNdMc(sigma, cor=None, intr=0.0, divr=0.0, rn_seed=None, antithetic=True)[source]

Monte-Carlo simulation of multiasset (N-d) Normal/Bachelier model (arithmetic Brownian Motion)

Examples

>>> import pyfeng as pf
>>> spot = np.ones(4)*100
>>> sigma = np.ones(4)*0.4
>>> texp = 5
>>> payoff = lambda x: np.fmax(np.mean(x,axis=1) - strike, 0) # Basket option
>>> strikes = np.arange(80, 121, 10)
>>> m = pf.NormNdMc(sigma*spot, cor=0.5, rn_seed=1234)
>>> m.simulate(tobs=[texp], n_path=20000)
>>> p = []
>>> for strike in strikes:
>>>    p.append(m.price_european(spot, texp, payoff))
>>> np.array(p)
array([39.42304794, 33.60383167, 28.32667559, 23.60383167, 19.42304794])
delta(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

delta_numeric(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

forward(spot, texp)

Forward price

Parameters
  • spot – spot price

  • texp – time to expiry

Returns

forward price

gamma(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

gamma_numeric(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

impvol(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

impvol_brentq(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

params_kw()

Model parameters in dictionary

pdf_numeric(strike, spot, texp, cp=- 1, h=0.001)

Probability density functin (PDF) at strike

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

probability densitiy

price(strike, spot, texp, cp=1)

Call/put option price.

Parameters
  • strike – strike price.

  • spot – spot (or forward) prices for assets. Asset dimension should be the last, e.g. (n_asset, ) or (N, n_asset)

  • texp – time to expiry.

  • cp – 1/-1 for call/put option.

Returns

option price

price_european(spot, texp, payoff)[source]

The European price of that payoff at the expiry.

Parameters
  • spot – array of spot prices

  • texp – time-to-expiry

  • payoff – payoff function applicable to the time-slice of price path

Returns

The MC price of the payoff

simulate(tobs, n_path, store=True)[source]

Simulate the price paths and store in the class. The initial prices are normalized to 0 and spot should be added later.

Parameters
  • tobs – array of observation times

  • n_path – number of paths to simulate

  • store – if True (default), store path, tobs, and n_path in the class

Returns

price path (time, path, asset) if store is False

theta(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

theta_numeric(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

vanna(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vanna_numeric(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vega(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vega_numeric(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

volga(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

volga_numeric(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value