Ejemplo n.º 1
0
        public virtual void test_quote_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 nScenarios = 3;

            foreach (KeyValuePair <QuoteId, double> entry in MARKET_QUOTES.entrySet())
            {
                DoubleArray shifts = DoubleArray.of(nScenarios, n => Math.Pow(0.9, n));
                ScenarioPerturbation <double> perturb = GenericDoubleShifts.of(ShiftType.SCALED, shifts);
                perturbationMapping.Add(PerturbationMapping.of(MarketDataFilter.ofId(entry.Key), 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)
            {
                ImmutableMap.Builder <QuoteId, double> builder = ImmutableMap.builder();
                foreach (KeyValuePair <QuoteId, double> entry in MARKET_QUOTES.entrySet())
                {
                    builder.put(entry.Key, entry.Value * Math.Pow(0.9, i));
                }
                ImmutableMarketData shiftedMarketData           = ImmutableMarketData.builder(VALUATION_DATE).addValueMap(builder.build()).addValueMap(MARKET_FX_QUOTES).build();
                MarketData          shiftedMarketDataCalibrated = StandardComponents.marketDataFactory().create(REQUIREMENTS, CONFIG, shiftedMarketData, REF_DATA);
                Results             shiftedResults = CALC_RUNNER.calculate(RULES, TARGETS, COLUMN, shiftedMarketDataCalibrated, REF_DATA);
                CurrencyAmount      pv             = shiftedResults.get(0, 0, typeof(CurrencyAmount)).Value;
                assertEquals(pvs.get(i), pv);
            }
        }
Ejemplo n.º 2
0
        public virtual void test_builtData()
        {
//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 nScenarios = 3;

            foreach (KeyValuePair <QuoteId, double> entry in MARKET_QUOTES.entrySet())
            {
                DoubleArray shifts = DoubleArray.of(nScenarios, n => Math.Pow(0.9, n));
                ScenarioPerturbation <double> perturb = GenericDoubleShifts.of(ShiftType.SCALED, shifts);
                perturbationMapping.Add(PerturbationMapping.of(MarketDataFilter.ofId(entry.Key), perturb));
            }
            ScenarioDefinition    scenarioDefinition   = ScenarioDefinition.ofMappings(perturbationMapping);
            ImmutableMarketData   dataWithSurface      = ImmutableMarketData.builder(VALUATION_DATE).addValueMap(MARKET_QUOTES).addValueMap(MARKET_FX_QUOTES).addValue(VOL_ID, EXP_VOLS).addValue(RatesCurveGroupId.of(CURVE_GROUP_NAME), RatesCurveGroup.ofCurves(CURVE_GROUP_DEFINITION, EXP_RATES.toImmutableRatesProvider().DiscountCurves.values())).build();
            ScenarioMarketData    marketDataCalibrated = StandardComponents.marketDataFactory().createMultiScenario(REQUIREMENTS, SCENARIO_CONFIG, dataWithSurface, REF_DATA, scenarioDefinition);
            Results               results  = CALC_RUNNER.calculateMultiScenario(RULES, TARGETS, COLUMN, marketDataCalibrated, REF_DATA);
            CurrencyScenarioArray computed = results.get(0, 0, typeof(CurrencyScenarioArray)).Value;
            CurrencyAmount        expected = PRICER.presentValue(OPTION_TRADE.resolve(REF_DATA), EXP_RATES, EXP_VOLS).convertedTo(USD, EXP_RATES);

            // dependency graph is absent, thus scenarios are not created
            assertTrue(computed.ScenarioCount == 1);
            assertEquals(computed.get(0), expected);
        }