Esempio n. 1
0
        // obtains the data and calculates the grid of results
        private static void calculate(CalculationRunner runner)
        {
            // the trades for which to calculate a P&L series
            IList <Trade> trades = ImmutableList.of(createTrade());

            // the columns, specifying the measures to be calculated
            IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE));

            // use the built-in example historical scenario market data
            ExampleMarketDataBuilder marketDataBuilder = ExampleMarketDataBuilder.ofResource(MARKET_DATA_RESOURCE_ROOT);

            // the complete set of rules for calculating measures
            CalculationFunctions functions = StandardComponents.calculationFunctions();
            CalculationRules     rules     = CalculationRules.of(functions, marketDataBuilder.ratesLookup(LocalDate.of(2015, 4, 23)));

            // load the historical calibrated curves from which we will build our scenarios
            // these curves are provided in the example data environment
            SortedDictionary <LocalDate, RatesCurveGroup> historicalCurves = marketDataBuilder.loadAllRatesCurves();

            // sorted list of dates for the available series of curves
            // the entries in the P&L vector we produce will correspond to these dates
            IList <LocalDate> scenarioDates = new List <LocalDate>(historicalCurves.Keys);

            // build the historical scenarios
            ScenarioDefinition historicalScenarios = buildHistoricalScenarios(historicalCurves, scenarioDates);

            // build a market data snapshot for the valuation date
            // this is the base snapshot which will be perturbed by the scenarios
            LocalDate  valuationDate = LocalDate.of(2015, 4, 23);
            MarketData marketData    = marketDataBuilder.buildSnapshot(valuationDate);

            // the reference data, such as holidays and securities
            ReferenceData refData = ReferenceData.standard();

            // calculate the results
            MarketDataRequirements reqs = MarketDataRequirements.of(rules, trades, columns, refData);
            ScenarioMarketData     scenarioMarketData = marketDataFactory().createMultiScenario(reqs, MarketDataConfig.empty(), marketData, refData, historicalScenarios);
            Results results = runner.calculateMultiScenario(rules, trades, columns, scenarioMarketData, refData);

            // the results contain the one measure requested (Present Value) for each scenario
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.scenario.ScenarioArray<?> scenarioValuations = (com.opengamma.strata.data.scenario.ScenarioArray<?>) results.get(0, 0).getValue();
            ScenarioArray <object> scenarioValuations = (ScenarioArray <object>)results.get(0, 0).Value;

            outputPnl(scenarioDates, scenarioValuations);
        }