### Calculate Option Greeks using MibianLib Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Demonstrates how to calculate various option Greeks (Delta, Theta, Rho, Vega, Gamma) and prices for European options using the MibianLib library. It shows how to instantiate the Me model with market parameters and access the calculated Greek values as object properties. ```python import mibian # Parameters: [underlyingPrice, strikePrice, interestRate, annualDividends, daysToExpiration] c = mibian.Me([52, 50, 1, 1, 30]) print(f"Call Price: {c.callPrice}") print(f"Put Price: {c.putPrice}") print(f"Call Delta: {c.callDelta}") print(f"Put Delta: {c.putDelta}") print(f"Call Theta: {c.callTheta}") print(f"Put Theta: {c.putTheta}") print(f"Call Rho: {c.callRho}") print(f"Put Rho: {c.putRho}") print(f"Vega: {c.vega}") print(f"Gamma: {c.gamma}") print(f"Call Dual Delta: {c.callDelta2}") print(f"Put Dual Delta: {c.putDelta2}") ``` -------------------------------- ### Calculate Put-Call Parity using MibianLib Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Demonstrates the calculation of put-call parity using MibianLib. This relationship is fundamental in options pricing and helps verify the consistency of option prices. ```python import mibian c = mibian.Me([52, 50, 1, 1, 30], callPrice=2.8984579845404852, putPrice=0.93950583663422549) print(f"Put-Call Parity: {c.putCallParity}") ``` -------------------------------- ### POST /calculate-option-metrics Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Calculate option prices and Greeks based on underlying price, strike, interest rate, dividends, and time to expiration. ```APIDOC ## POST /calculate-option-metrics ### Description Calculates various option metrics including price, delta, theta, rho, vega, and gamma based on provided market parameters. ### Method POST ### Endpoint /calculate-option-metrics ### Parameters #### Request Body - **underlyingPrice** (float) - Required - Current price of the underlying asset - **strikePrice** (float) - Required - Strike price of the option - **interestRate** (float) - Required - Annual risk-free interest rate - **annualDividends** (float) - Required - Annual dividend yield - **daysToExpiration** (int) - Required - Days remaining until expiration ### Request Example { "underlyingPrice": 52, "strikePrice": 50, "interestRate": 1, "annualDividends": 1, "daysToExpiration": 30 } ### Response #### Success Response (200) - **callPrice** (float) - Theoretical call price - **putPrice** (float) - Theoretical put price - **callDelta** (float) - Sensitivity of call price to underlying - **vega** (float) - Sensitivity to volatility - **gamma** (float) - Rate of change in delta #### Response Example { "callPrice": 2.898, "putPrice": 0.939, "callDelta": 0.686, "vega": 0.052 } ``` -------------------------------- ### Calculate Implied Volatility using MibianLib Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Shows how to calculate the implied volatility of an option using MibianLib, given either the call price or the put price. This is useful for determining the market's expectation of future volatility. ```python import mibian # Calculate implied volatility from call price c = mibian.Me([52, 50, 1, 1, 30], callPrice=3) print(f"Implied Volatility (from call): {c.impliedVolatility}") # Calculate implied volatility from put price c = mibian.Me([52, 50, 1, 1, 30], putPrice=0.84) print(f"Implied Volatility (from put): {c.impliedVolatility}") ``` -------------------------------- ### Standalone Implied Volatility Calculation in MibianLib Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Illustrates how to use the standalone `impliedVolatility` function in MibianLib to calculate implied volatility for different option pricing models (Black-Scholes, Garman-Kohlhagen, Merton). This function uses a bisection method for estimation. ```python import mibian # Calculate implied volatility for Black-Scholes model iv = mibian.impliedVolatility('BS', [81, 80, 6, 60], callPrice=4.84) print(f"Implied Volatility: {iv}") # Calculate implied volatility from put price iv = mibian.impliedVolatility('BS', [81, 80, 6, 60], putPrice=3.05) print(f"Implied Volatility: {iv}") # Calculate implied volatility for Garman-Kohlhagen model iv = mibian.impliedVolatility('GK', [1.4565, 1.45, 1, 2, 30], callPrice=0.0359) print(f"Implied Volatility: {iv}") # Calculate implied volatility for Merton model iv = mibian.impliedVolatility('Me', [52, 50, 1, 1, 30], callPrice=3) print(f"Implied Volatility: {iv}") ``` -------------------------------- ### Calculate Black-Scholes Option Prices and Greeks (Python) Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Calculates European option prices and Greeks (delta, gamma, theta, vega, rho) for stocks without dividends using the Black-Scholes model. It takes market parameters and volatility as input. It can also calculate implied volatility from known option prices. Requires SciPy. ```Python import mibian # Calculate option prices and Greeks with known volatility c = mibian.BS([81, 80, 6, 60], volatility=30) # Parameters: [underlyingPrice, strikePrice, interestRate, daysToExpiration] print(f"Call Price: {c.callPrice}") # 4.8422936422068901 print(f"Put Price: {c.putPrice}") # 3.0571309465072147 print(f"Call Delta: {c.callDelta}") # 0.5963986247019829 print(f"Put Delta: {c.putDelta}") # -0.4036013752980171 print(f"Call Theta: {c.callTheta}") # -0.038938157820841104 print(f"Put Theta: {c.putTheta}") # -0.025916540729723249 print(f"Call Rho: {c.callRho}") # 0.07145095061696502 print(f"Put Rho: {c.putRho}") # -0.05876522029421359 print(f"Vega: {c.vega}") # 0.12717225103657845 print(f"Gamma: {c.gamma}") # 0.039304536595328565 print(f"Call Dual Delta: {c.callDelta2}") print(f"Put Dual Delta: {c.putDelta2}") # Calculate implied volatility from call price c = mibian.BS([52, 60, 5, 30], callPrice=3) print(f"Implied Volatility (from call): {c.impliedVolatility}") # 95.703125 # Calculate implied volatility from put price c = mibian.BS([52, 60, 5, 30], putPrice=7.86) print(f"Implied Volatility (from put): {c.impliedVolatility}") # 29.78515625 # Calculate put-call parity c = mibian.BS([81, 80, 6, 60], callPrice=4.8422936422068901, putPrice=3.0571309465072147) print(f"Put-Call Parity: {c.putCallParity}") # 0.02254482311879258 ``` -------------------------------- ### Calculate Garman-Kohlhagen Option Prices and Greeks (Python) Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Calculates European currency option prices and Greeks using the Garman-Kohlhagen model. This model extends Black-Scholes by incorporating domestic and foreign interest rates. It accepts market parameters and volatility as input and can also compute implied volatility from known option prices. Requires SciPy. ```Python import mibian # Calculate currency option prices and Greeks with known volatility c = mibian.GK([1.4565, 1.45, 1, 2, 30], volatility=20) # Parameters: [underlyingPrice, strikePrice, domesticRate, foreignRate, daysToExpiration] print(f"Call Price: {c.callPrice}") # 0.03591379198404554 print(f"Put Price: {c.putPrice}") # 0.030614780580200285 print(f"Call Delta: {c.callDelta}") # 0.53590471276326945 print(f"Put Delta: {c.putDelta}") # -0.46245280197803584 print(f"Call Theta: {c.callTheta}") # -0.00052962585114210519 print(f"Put Theta: {c.putTheta}") # -0.00056964220851379096 print(f"Call Domestic Rho: {c.callRhoD}") # 0.00061202582642930648 print(f"Put Domestic Rho: {c.putRhoD}") # -0.00057877585205030923 print(f"Call Foreign Rho: {c.callRhoF}") # -0.00064154401162167267 print(f"Put Foreign Rho: {c.putRhoF}") # 0.00055361301869671985 print(f"Vega: {c.vega}") # 0.16560340559332973 print(f"Gamma: {c.gamma}") # 4.7488658326126272 print(f"Call Dual Delta: {c.callDelta2}") print(f"Put Dual Delta: {c.putDelta2}") # Calculate implied volatility from call price c = mibian.GK([1.4565, 1.45, 1, 2, 30], callPrice=0.021) print(f"Implied Volatility (from call): {c.impliedVolatility}") # 10.7421875 # Calculate implied volatility from put price c = mibian.GK([1.4565, 1.45, 1, 2, 30], putPrice=0.0306) print(f"Implied Volatility (from put): {c.impliedVolatility}") # 20.01953125 # Calculate put-call parity c = mibian.GK([1.4565, 1.45, 1, 2, 30], callPrice=0.036133685584059827, putPrice=0.030851333789832069) print(f"Put-Call Parity: {c.putCallParity}") # -3.433431599675352e-05 ``` -------------------------------- ### Calculate Merton Option Prices and Greeks (Python) Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Calculates European option prices and Greeks for dividend-paying stocks using the Merton model. This model is an extension of Black-Scholes that incorporates a continuous dividend yield. It takes market parameters and volatility as input. Requires SciPy. ```Python import mibian # Calculate option prices and Greeks with known volatility c = mibian.Me([52, 50, 1, 1, 30], volatility=30) ``` -------------------------------- ### POST /calculate-implied-volatility Source: https://context7.com/yassinemaaroufi/mibianlib/llms.txt Estimates the implied volatility of an option using the bisection method based on a given market price. ```APIDOC ## POST /calculate-implied-volatility ### Description Computes the implied volatility for a specific model (BS, GK, or Me) given the market price of the option. ### Method POST ### Endpoint /calculate-implied-volatility ### Parameters #### Request Body - **modelType** (string) - Required - Model to use: 'BS', 'GK', or 'Me' - **params** (array) - Required - List of [underlyingPrice, strikePrice, interestRate, daysToExpiration] - **callPrice** (float) - Optional - Market price of the call - **putPrice** (float) - Optional - Market price of the put ### Request Example { "modelType": "BS", "params": [81, 80, 6, 60], "callPrice": 4.84 } ### Response #### Success Response (200) - **impliedVolatility** (float) - The calculated implied volatility #### Response Example { "impliedVolatility": 31.25 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.