MibianLib

repository·master·Indexed 43 days ago

https://github.com/yassinemaaroufi/mibianlib

An open-source Python library for options pricing. It provides implementations for the Black-Scholes (BS), Garman-Kohlhagen (GK), and Merton (Me) models to price European options on stocks and currencies, including calculations for implied volatility, Greeks (delta, theta, rho, vega, gamma), and put-call parity.

Tokens
1.2K
Snippets
3
Records
3
Agent score
5%

What's inside MibianLib

  1. Price European options on dividend-paying stocks using Merton (Me)

    master

    Use the mibian.Me class to price European options on stocks that pay dividends.

    Constructor Arguments: Pass a list containing [underlyingPrice, strikePrice, interestRate, annualDividends, daysToExpiration] followed by optional keyword arguments:

    • volatility: The asset volatility.
    • callPrice: The current market price of the call option.
    • putPrice: The current market price of the put option.

    Available Attributes/Methods:

    • callPrice, putPrice: Option prices.
    • callDelta, putDelta: Option deltas.
    • callDelta2, putDelta2: Dual deltas.
    • callTheta, putTheta: Option theta.
    • callRho, putRho: Option rho.
    • vega: Option vega.
    • gamma: Option gamma.
    • impliedVolatility: Returns the implied volatility if callPrice or putPrice is provided.
    • putCallParity: Returns the put-call parity if both callPrice and putPrice are provided.
    import mibian
    
    # Pricing with volatility
    c = mibian.Me([52, 50, 1, 1, 30], volatility=20)
    print(c.callPrice)
    print(c.callDelta)
    
    # Calculating implied volatility
    c = mibian.Me([52, 50, 1, 1, 30], callPrice=0.0359)
    print(c.impliedVolatility)
  2. Price European options on stocks using Black-Scholes (BS)

    master

    Use the mibian.BS class to price European options on stocks that do not pay dividends.

    Constructor Arguments: Pass a list containing [underlyingPrice, strikePrice, interestRate, daysToExpiration] followed by optional keyword arguments:

    • volatility: The asset volatility.
    • callPrice: The current market price of the call option (used to calculate implied volatility).
    • putPrice: The current market price of the put option (used to calculate implied volatility).

    Available Attributes/Methods:

    • callPrice, putPrice: Option prices.
    • callDelta, putDelta: Option deltas.
    • callDelta2, putDelta2: Dual deltas.
    • callTheta, putTheta: Option theta.
    • callRho, putRho: Option rho.
    • vega: Option vega.
    • gamma: Option gamma.
    • impliedVolatility: Returns the implied volatility if callPrice or putPrice is provided.
    • putCallParity: Returns the put-call parity if both callPrice and putPrice are provided.
    import mibian
    
    # Pricing with volatility
    c = mibian.BS([1.4565, 1.45, 1, 30], volatility=20)
    print(c.callPrice)
    print(c.putPrice)
    print(c.callDelta)
    
    # Calculating implied volatility from call price
    c = mibian.BS([1.4565, 1.45, 1, 30], callPrice=0.0359)
    print(c.impliedVolatility)
    
    # Calculating put-call parity
    c = mibian.BS([1.4565, 1.45, 1, 30], callPrice=0.0359, putPrice=0.0306)
    print(c.putCallParity)
  3. Price European options on currencies using Garman-Kohlhagen (GK)

    master

    Use the mibian.GK class to price European options on currencies.

    Constructor Arguments: Pass a list containing [underlyingPrice, strikePrice, domesticRate, foreignRate, daysToExpiration] followed by optional keyword arguments:

    • volatility: The asset volatility.
    • callPrice: The current market price of the call option.
    • putPrice: The current market price of the put option.

    Available Attributes/Methods:

    • callPrice, putPrice: Option prices.
    • callDelta, putDelta: Option deltas.
    • callDelta2, putDelta2: Dual deltas.
    • callTheta, putTheta: Option theta.
    • callRhoD, putRhoD: Domestic rho.
    • callRhoF, putRhoF: Foreign rho.
    • vega: Option vega.
    • gamma: Option gamma.
    • impliedVolatility: Returns the implied volatility if callPrice or putPrice is provided.
    • putCallParity: Returns the put-call parity if both callPrice and putPrice are provided.
    import mibian
    
    # Pricing with volatility
    c = mibian.GK([1.4565, 1.45, 1, 2, 30], volatility=20)
    print(c.callPrice)
    print(c.callRhoD)
    print(c.callRhoF)
    
    # Calculating implied volatility
    c = mibian.GK([1.4565, 1.45, 1, 2, 30], callPrice=0.0359)
    print(c.impliedVolatility)