Ejemplo n.º 1
0
 def get(self, underlying_id):
     db_underlying = db_session.query(Underlying).get(underlying_id)
     underlying_price = get_underlying_price(db_underlying)
     result = {
         "underlying_id": underlying_id,
         "market_price": underlying_price,
         "timestamp": datetime.now()
     }
     return jsonify(result)
Ejemplo n.º 2
0
def get_curve_settings(vol_curve_id):
    db_vol_curve = db_session.query(VolCurve).get(vol_curve_id)
    underlying_price = get_underlying_price_from_request(request)
    if underlying_price is None:
        underlying_price = get_underlying_price(db_vol_curve.expiry.underlying)
    vol_curve_settings = db_vol_curve.get_input_settings(underlying_price)
    input_sensitivities = calc_normalization_sensitivities_to_inputs(db_vol_curve.expiry, underlying_price)
    for input_name in vol_curve_settings:
        vol_curve_settings[input_name]["sensitivity"] = input_sensitivities.get(input_name, 0.0)
    vol_curve_settings["portfolio_symbol_id"] = db_vol_curve.expiry.portfolio_symbol_id
    vol_curve_settings["expiry_id"] = db_vol_curve.expiry_id
    vol_curve_settings["vol_curve_id"] = db_vol_curve.id
    return jsonify(vol_curve_settings)
Ejemplo n.º 3
0
def get_underlying_risk(underlying_id):
    db_underlying = db_session.query(Underlying).get(underlying_id)
    underlying_price = get_underlying_price_from_request(request)
    if underlying_price is None:
        underlying_price = get_underlying_price(db_underlying)
    underlying_risk = calc_underlying_risk(db_underlying, underlying_price)
    underlying_risk["account_id"] = underlying_risk.index.get_level_values("account_id")
    underlying_risk["position_type"] = underlying_risk.index.get_level_values("position_type")
    results = {
        "underlying_id": underlying_id,
        "underlying_price": underlying_price,
        "results": underlying_risk.to_json(orient="records")
    }
    return jsonify(results)
Ejemplo n.º 4
0
def get_risk(expiry_id):
    db_expiry = db_session.query(Expiry).get(expiry_id)
    underlying_price = get_underlying_price_from_request(request)
    if underlying_price is None:
        underlying_price = get_underlying_price(db_expiry.underlying)
    expiry_risk = calc_expiry_risk(db_expiry, underlying_price)
    expiry_risk["account_id"] = expiry_risk.index.get_level_values("account_id")
    expiry_risk["position_type"] = expiry_risk.index.get_level_values("position_type")
    results = {
        "expiry_id": expiry_id,
        "underlying_price": underlying_price,
        "results": expiry_risk.to_json(orient="records")
    }
    return jsonify(results)