Ejemplo n.º 1
0
def model_prices(pars: tuple,
                 args: EvalArgs,
                 model: str,
                 strict=False,
                 check=False,
                 bounds_only=True) -> np.ndarray:
    return optimization.models[model](pars=pars,
                                      args=args.as_tuple(),
                                      strict=strict,
                                      check=check,
                                      bounds_only=bounds_only)
Ejemplo n.º 2
0
def estimate_model(pars: tuple, args: EvalArgs, model: str, metric: str, prices: np.ndarray) -> float:
    """

    :param pars: model parameters
    :param args: market parameters with strikes as args[1]
    :param model: pricing model
    :param metric: quality metric
    :param prices: actual prices

    :return: value of quality metric on passed parameters
    """

    k = args.get_strikes()

    if model not in models.keys():
        raise Exception("Cannot use model " + model)

    if metric not in metrics.keys():
        raise Exception("Cannot use metric " + metric)

    if (type(prices) is not np.ndarray) | (type(k) is not np.ndarray) | (len(prices) != len(k)):
        raise Exception("strikes and prices should be np.arrays with same length")

    return apply_metric(models[model](pars=pars, args=args.as_tuple()), prices, metric)