public virtual void test_parameter_secenarioDefinition() { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<com.opengamma.strata.calc.marketdata.PerturbationMapping<?>> perturbationMapping = new java.util.ArrayList<>(); IList <PerturbationMapping <object> > perturbationMapping = new List <PerturbationMapping <object> >(); int nVolParams = EXP_VOLS.ParameterCount; int nScenarios = 3; PointShiftsBuilder builder = PointShifts.builder(ShiftType.SCALED); for (int i = 0; i < nVolParams; ++i) { object id = EXP_VOLS.getParameterMetadata(i).Identifier; for (int j = 0; j < nScenarios; ++j) { builder.addShift(j, id, Math.Pow(0.9, j)); } } ScenarioPerturbation <ParameterizedData> perturb = builder.build(); perturbationMapping.Add(PerturbationMapping.of(MarketDataFilter.ofId(VOL_ID), perturb)); ScenarioDefinition scenarioDefinition = ScenarioDefinition.ofMappings(perturbationMapping); ScenarioMarketData marketDataCalibrated = StandardComponents.marketDataFactory().createMultiScenario(REQUIREMENTS, SCENARIO_CONFIG, MARKET_DATA, REF_DATA, scenarioDefinition); Results results = CALC_RUNNER.calculateMultiScenario(RULES, TARGETS, COLUMN, marketDataCalibrated, REF_DATA); CurrencyScenarioArray pvs = results.get(0, 0, typeof(CurrencyScenarioArray)).Value; for (int i = 0; i < nScenarios; ++i) { int index = i; BlackFxOptionSmileVolatilities shiftedSmile = EXP_VOLS.withPerturbation((j, v, m) => Math.Pow(0.9, index) * v); CurrencyAmount pv = PRICER.presentValue(OPTION_TRADE.resolve(REF_DATA), EXP_RATES, shiftedSmile).convertedTo(USD, EXP_RATES); assertEquals(pvs.get(i), pv); } }
private static PointShifts buildShifts(IList <Curve> historicalCurves) { PointShiftsBuilder builder = PointShifts.builder(ShiftType.ABSOLUTE); for (int scenarioIndex = 1; scenarioIndex < historicalCurves.Count; scenarioIndex++) { Curve previousCurve = historicalCurves[scenarioIndex - 1]; Curve curve = historicalCurves[scenarioIndex]; // build up the shifts to apply to each node // these are calculated as the actual change in the zero rate at that node between the two scenario dates for (int curveNodeIdx = 0; curveNodeIdx < curve.ParameterCount; curveNodeIdx++) { double zeroRate = curve.getParameter(curveNodeIdx); double previousZeroRate = previousCurve.getParameter(curveNodeIdx); double shift = (zeroRate - previousZeroRate); // the parameter metadata is used to identify a node to apply a perturbation to builder.addShift(scenarioIndex, curve.getParameterMetadata(curveNodeIdx).Identifier, shift); } } return(builder.build()); }