MarketDataShockDecorator implements MarketDataFn, ScenarioFunction<MarketDataShock, MarketDataShockDecorator> { @Override public <T> Result<T> getValue(Environment env, Security security, FieldName fieldName, Class<T> valueType) { return _delegate.getValue(env, security, fieldName, valueType); } MarketDataShockDecorator(MarketDataFn delegate); @Override Result<Double> getFxRate(Environment env, CurrencyPair currencyPair); @Override Result<Double> getCurveNodeValue(Environment env, CurveNodeWithIdentifier node); @Override Result<Double> getCurveNodeUnderlyingValue(Environment env, PointsCurveNodeWithIdentifier node); @Override Result<Double> getMarketValue(Environment env, Security security); @Override Result<Double> getMarketValue(Environment env, ExternalIdBundle id); @Override Result<T> getValue(Environment env, Security security, FieldName fieldName, Class<T> valueType); @Override Class<MarketDataShock> getArgumentType();  }
@SuppressWarnings("unchecked") @Test public void singleShock() { MarketDataShock shock = MarketDataShock.relativeShift(0.5, MATCHER1); FilteredScenarioDefinition scenarioDef = new FilteredScenarioDefinition(shock); SimpleEnvironment env = new SimpleEnvironment(ZonedDateTime.now(), MARKET_DATA_BUNDLE, scenarioDef); assertEquals(1.5, FN.foo(env, SEC1).getValue(), DELTA); assertEquals(2d, FN.foo(env, SEC2).getValue(), DELTA); }
@Test public void multipleSeparateShocks() { MarketDataShock relativeShift = MarketDataShock.relativeShift(0.5, MATCHER1); MarketDataShock absoluteShift = MarketDataShock.absoluteShift(0.1, MATCHER2); FilteredScenarioDefinition scenarioDef = new FilteredScenarioDefinition(absoluteShift, relativeShift); SimpleEnvironment env = new SimpleEnvironment(ZonedDateTime.now(), MARKET_DATA_BUNDLE, scenarioDef); assertEquals(1.5, FN.foo(env, SEC1).getValue(), DELTA); assertEquals(2.1, FN.foo(env, SEC2).getValue(), DELTA); }
@Test public void multipleShocksOnSameData() { MarketDataShock absoluteShift = MarketDataShock.absoluteShift(0.1, MATCHER1); MarketDataShock relativeShift = MarketDataShock.relativeShift(0.5, MATCHER1); FilteredScenarioDefinition scenarioDef = new FilteredScenarioDefinition(absoluteShift, relativeShift); SimpleEnvironment env = new SimpleEnvironment(ZonedDateTime.now(), MARKET_DATA_BUNDLE, scenarioDef); assertEquals(1.65, FN.foo(env, SEC1).getValue(), DELTA); assertEquals(2d, FN.foo(env, SEC2).getValue(), DELTA); }
@Test public void multipleShocksOnSameDataReversed() { MarketDataShock relativeShift = MarketDataShock.relativeShift(0.5, MATCHER1); MarketDataShock absoluteShift = MarketDataShock.absoluteShift(0.1, MATCHER1); FilteredScenarioDefinition scenarioDef = new FilteredScenarioDefinition(relativeShift, absoluteShift); SimpleEnvironment env = new SimpleEnvironment(ZonedDateTime.now(), MARKET_DATA_BUNDLE, scenarioDef); assertEquals(1.6, FN.foo(env, SEC1).getValue(), DELTA); assertEquals(2d, FN.foo(env, SEC2).getValue(), DELTA); }