def test_structured_calc(mocker): set_session() for priceable in priceables: if priceable.assetClass == AssetClass.Rates: for measure in (risk.IRDelta, risk.IRGamma, risk.IRVega): structured_calc(mocker, priceable, measure) elif priceable.assetClass == AssetClass.FX: for measure in (risk.FXDelta, risk.FXGamma, risk.FXVega): structured_calc(mocker, priceable, measure) values = [{ 'marketDataType': 'IR', 'assetId': 'USD', 'pointClass': 'Swap', 'point': '1y', 'value': 0.01 }, { 'marketDataType': 'IR', 'assetId': 'USD', 'pointClass': 'Swap', 'point': '2y', 'value': 0.015 }] mocker.return_value = [[values] * len(priceables)] with risk.PricingContext(): delta_f = [p.calc(risk.IRDelta) for p in priceables] delta = risk.aggregate_risk(delta_f, threshold=0) assert len(delta) == 2
def test_async_calc(mocker): set_session() results = [[{'value': 0.01 * idx}] for idx in range(len(priceables))] mocker.return_value = [results] with risk.PricingContext(): dollar_price_f = [p.dollar_price() for p in priceables] prices = tuple(f.result() for f in dollar_price_f) assert prices == tuple(0.01 * i for i in range(len(priceables)))