Skip to content

Calculators

  • In this package: finmc.calc contains calculators that can be used with any finmc model.
  • Outside this package: qablet-contracts defines a large selection of financial derivative contracts that can be priced using finmc models. Also see project qatwalk that leverages the selection of contracts in qablet-contract with the selection of models in finmc.

finmc.calc

Utility to calculate prices of european contracts from a MC Simulation model.

finmc.calc.option.opt_price_mc

Calculate the price of a Vanilla European Option using MC Simulation.

Parameters:

Name Type Description Default
strike float

The strike price of the option.

required
maturity float

The time to maturity of the option in years.

required
option_type str

The type of the option. Either "Call" or "Put".

required
asset_name str

The name of the asset.

required
model MCBase

The model used to simulate the asset price.

required

Returns:

Type Description
float

The price of the option.

Examples:

>>> price = opt_price_mc(K, T, "Call", "SPX", model)
Source code in finmc\calc\option.py
def opt_price_mc(
    strike: float,
    maturity: float,
    option_type: str,
    asset_name: str,
    model: MCBase,
) -> float:
    """Calculate the price of a Vanilla European Option using MC Simulation.

    Args:
        strike: The strike price of the option.
        maturity: The time to maturity of the option in years.
        option_type: The type of the option. Either "Call" or "Put".
        asset_name: The name of the asset.
        model: The model used to simulate the asset price.

    Returns:
        The price of the option.

    Examples:
        >>> price = opt_price_mc(K, T, "Call", "SPX", model)
    """

    model.reset()
    model.advance(maturity)
    expiration_spots = model.get_value(asset_name)
    df = model.get_df()

    if option_type == "Call":
        price = np.maximum(expiration_spots - strike, 0).mean() * df
    else:
        price = np.maximum(strike - expiration_spots, 0).mean() * df
    return price

Utility to calculate prices of bonds from a MC Simulation model.

finmc.calc.bond.zcb_price_mc

Calculate the price of a Zero Coupon Bond using MC Simulation.

Parameters:

Name Type Description Default
maturity float

The time to maturity of the bond in years.

required
asset_name str

The name of the asset.

required
model MCBase

The model used to simulate the asset price.

required

Returns:

Type Description
float

The price of the zero coupon bond.

Examples:

>>> price = zcb_price_mc(T, "USD", model)
Source code in finmc\calc\bond.py
def zcb_price_mc(
    maturity: float,
    asset_name: str,
    model: MCBase,
) -> float:
    """Calculate the price of a Zero Coupon Bond using MC Simulation.

    Args:
        maturity: The time to maturity of the bond in years.
        asset_name: The name of the asset.
        model: The model used to simulate the asset price.

    Returns:
        The price of the zero coupon bond.

    Examples:
        >>> price = zcb_price_mc(T, "USD", model)
    """

    model.reset()
    model.advance(maturity)
    df = model.get_df()

    if model.dataset.get("BASE") == asset_name:
        return df.mean()
    else:
        spots = model.get_value(asset_name)
        return (spots * df).mean()