/// <summary>
        /// Tests the combinedWith method when the other set of market data is not an instance of ImmutableScenarioMarketData
        /// </summary>
        public virtual void test_combinedWithDifferentImpl()
        {
            LocalDateDoubleTimeSeries timeSeries1 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 1).put(date(2011, 3, 9), 2).put(date(2011, 3, 10), 3).build();

            LocalDateDoubleTimeSeries timeSeries2 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 10).put(date(2011, 3, 9), 20).put(date(2011, 3, 10), 30).build();

            LocalDateDoubleTimeSeries timeSeries2a = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 1000).put(date(2011, 3, 9), 2000).put(date(2011, 3, 10), 3000).build();

            LocalDateDoubleTimeSeries timeSeries3 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 100).put(date(2011, 3, 9), 200).put(date(2011, 3, 10), 300).build();

            MarketData marketData = ImmutableMarketData.builder(LocalDate.of(2011, 3, 8)).addTimeSeries(TEST_ID1, timeSeries1).addTimeSeries(TEST_ID2, timeSeries2).addValue(TEST_ID1, 1.1).addValue(TEST_ID2, 1.2).build();

            RepeatedScenarioMarketData repeatedScenarioMarketData = RepeatedScenarioMarketData.of(3, marketData);

            ImmutableScenarioMarketData immutableScenarioMarketData = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addTimeSeries(TEST_ID2, timeSeries2a).addTimeSeries(TEST_ID3, timeSeries3).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(2.0, 2.1, 2.2)).addBox(TEST_ID3, MarketDataBox.ofScenarioValues(3.0, 3.1, 3.2)).build();

            ScenarioMarketData combinedData = immutableScenarioMarketData.combinedWith(repeatedScenarioMarketData);

            assertThat(combinedData.ScenarioCount).isEqualTo(3);
            assertThat(combinedData.getValue(TEST_ID1).getValue(0)).isEqualTo(1.1);
            assertThat(combinedData.getValue(TEST_ID1).getValue(2)).isEqualTo(1.1);
            assertThat(combinedData.getValue(TEST_ID1).getValue(3)).isEqualTo(1.1);
            assertThat(combinedData.getValue(TEST_ID2)).isEqualTo(MarketDataBox.ofScenarioValues(2.0, 2.1, 2.2));
            assertThat(combinedData.getValue(TEST_ID3)).isEqualTo(MarketDataBox.ofScenarioValues(3.0, 3.1, 3.2));
            assertThat(combinedData.getTimeSeries(TEST_ID1)).isEqualTo(timeSeries1);
            assertThat(combinedData.getTimeSeries(TEST_ID2)).isEqualTo(timeSeries2a);
            assertThat(combinedData.getTimeSeries(TEST_ID3)).isEqualTo(timeSeries3);
        }
        public virtual void test_combinedWithIncompatibleScenarioCount()
        {
            ImmutableScenarioMarketData marketData1 = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addBox(TEST_ID1, MarketDataBox.ofScenarioValues(1.0, 1.1, 1.2)).build();

            ImmutableScenarioMarketData marketData2 = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(1.0, 1.1)).build();

            assertThrowsIllegalArg(() => marketData1.combinedWith(marketData2), ".* same number of scenarios .* 3 and 2");
        }
        public virtual void test_combinedWithOtherHasOneScenario()
        {
            ImmutableScenarioMarketData marketData1 = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(1.0, 1.1)).build();

            ImmutableScenarioMarketData marketData2 = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addBox(TEST_ID1, MarketDataBox.ofSingleValue(1.0)).build();

            ImmutableScenarioMarketData expected = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addBox(TEST_ID1, MarketDataBox.ofSingleValue(1.0)).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(1.0, 1.1)).build();

            assertThat(marketData1.combinedWith(marketData2)).isEqualTo(expected);
        }
Example #4
0
        public virtual void specifySource()
        {
            ObservableSource   testSource = ObservableSource.of("test");
            ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addValue(FxRateId.of(Currency.GBP, Currency.USD), FxRate.of(Currency.GBP, Currency.USD, 1.4d)).addValue(FxRateId.of(Currency.GBP, Currency.USD, testSource), FxRate.of(Currency.GBP, Currency.USD, 1.41d)).build();

            ScenarioFxRateProvider defaultRateProvider = ScenarioFxRateProvider.of(marketData);
            ScenarioFxRateProvider sourceRateProvider  = ScenarioFxRateProvider.of(marketData, testSource);

            assertThat(defaultRateProvider.fxRate(Currency.GBP, Currency.USD, 0)).isEqualTo(1.4d);
            assertThat(sourceRateProvider.fxRate(Currency.GBP, Currency.USD, 0)).isEqualTo(1.41d);
        }
        public virtual void test_addBadScenarioCount()
        {
            FxRateId eurGbpId    = FxRateId.of(Currency.EUR, Currency.GBP);
            FxRateId eurUsdId    = FxRateId.of(Currency.EUR, Currency.USD);
            FxRate   eurGbpRate1 = FxRate.of(Currency.EUR, Currency.GBP, 0.8);
            FxRate   eurGbpRate2 = FxRate.of(Currency.EUR, Currency.GBP, 0.9);
            FxRate   eurGbpRate3 = FxRate.of(Currency.EUR, Currency.GBP, 0.95);
            FxRate   eurUsdRate1 = FxRate.of(Currency.EUR, Currency.USD, 1.1);
            FxRate   eurUsdRate2 = FxRate.of(Currency.EUR, Currency.USD, 1.2);

            ImmutableScenarioMarketDataBuilder builder = ImmutableScenarioMarketData.builder(VAL_DATE).addBox(eurGbpId, MarketDataBox.ofScenarioValues(eurGbpRate1, eurGbpRate2, eurGbpRate3));

            assertThrowsIllegalArg(() => builder.addBox(eurUsdId, MarketDataBox.ofScenarioValues(eurUsdRate1, eurUsdRate2)));
        }
        public virtual void test_addSingleAndBox()
        {
            FxRateId eurGbpId    = FxRateId.of(Currency.EUR, Currency.GBP);
            FxRateId eurUsdId    = FxRateId.of(Currency.EUR, Currency.USD);
            FxRate   eurGbpRate  = FxRate.of(Currency.EUR, Currency.GBP, 0.8);
            FxRate   eurUsdRate1 = FxRate.of(Currency.EUR, Currency.USD, 1.1);
            FxRate   eurUsdRate2 = FxRate.of(Currency.EUR, Currency.USD, 1.2);

            ImmutableScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addValue(eurGbpId, eurGbpRate).addBox(eurUsdId, MarketDataBox.ofScenarioValues(eurUsdRate1, eurUsdRate2)).build();

            assertEquals(marketData.ScenarioCount, 2);
            assertEquals(marketData.Ids, ImmutableSet.of(eurGbpId, eurUsdId));
            assertEquals(marketData.getValue(eurGbpId), MarketDataBox.ofSingleValue(eurGbpRate));
            assertEquals(marketData.getValue(eurUsdId), MarketDataBox.ofScenarioValues(eurUsdRate1, eurUsdRate2));
        }
        //-------------------------------------------------------------------------
        public virtual void test_addScenarioValueMap()
        {
            FxRateId            eurGbpId    = FxRateId.of(Currency.EUR, Currency.GBP);
            FxRateId            eurUsdId    = FxRateId.of(Currency.EUR, Currency.USD);
            FxRateScenarioArray eurGbpRates = FxRateScenarioArray.of(Currency.EUR, Currency.GBP, DoubleArray.of(0.79, 0.8, 0.81));
            FxRateScenarioArray eurUsdRates = FxRateScenarioArray.of(Currency.EUR, Currency.USD, DoubleArray.of(1.09, 1.1, 1.11));
            IDictionary <FxRateId, FxRateScenarioArray> values = ImmutableMap.of(eurGbpId, eurGbpRates, eurUsdId, eurUsdRates);

            ImmutableScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addScenarioValueMap(values).build();

            assertEquals(marketData.ScenarioCount, 3);
            assertEquals(marketData.Ids, ImmutableSet.of(eurGbpId, eurUsdId));
            assertEquals(marketData.getValue(eurGbpId), MarketDataBox.ofScenarioValue(eurGbpRates));
            assertEquals(marketData.getValue(eurUsdId), MarketDataBox.ofScenarioValue(eurUsdRates));
        }
        //-------------------------------------------------------------------------
        public virtual void test_addValueMap()
        {
            FxRateId eurGbpId   = FxRateId.of(Currency.EUR, Currency.GBP);
            FxRateId eurUsdId   = FxRateId.of(Currency.EUR, Currency.USD);
            FxRate   eurGbpRate = FxRate.of(Currency.EUR, Currency.GBP, 0.8);
            FxRate   eurUsdRate = FxRate.of(Currency.EUR, Currency.USD, 1.1);
            IDictionary <FxRateId, FxRate> values = ImmutableMap.of(eurGbpId, eurGbpRate, eurUsdId, eurUsdRate);

            ImmutableScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addValueMap(values).build();

            assertEquals(marketData.ScenarioCount, 1);
            assertEquals(marketData.Ids, ImmutableSet.of(eurGbpId, eurUsdId));
            assertEquals(marketData.getValue(eurGbpId), MarketDataBox.ofSingleValue(eurGbpRate));
            assertEquals(marketData.getValue(eurUsdId), MarketDataBox.ofSingleValue(eurUsdRate));
        }
Example #9
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, MarketDataBox<?>> dataMap = com.google.common.collect.ImmutableMap.of(ID1, BOX1);
            IDictionary <MarketDataId <object>, MarketDataBox <object> > dataMap = ImmutableMap.of(ID1, BOX1);
            IDictionary <ObservableId, LocalDateDoubleTimeSeries>        tsMap   = ImmutableMap.of(ID1, TIME_SERIES);
            ImmutableScenarioMarketData test = ImmutableScenarioMarketData.of(2, VAL_DATE, dataMap, tsMap);

            coverImmutableBean(test);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, MarketDataBox<?>> dataMap2 = com.google.common.collect.ImmutableMap.of(ID2, BOX2);
            IDictionary <MarketDataId <object>, MarketDataBox <object> > dataMap2 = ImmutableMap.of(ID2, BOX2);
            IDictionary <ObservableId, LocalDateDoubleTimeSeries>        tsMap2   = ImmutableMap.of(ID2, TIME_SERIES);
            ImmutableScenarioMarketData test2 = ImmutableScenarioMarketData.of(1, VAL_DATE.plusDays(1), dataMap2, tsMap2);

            coverBeanEquals(test, test2);
        }
Example #10
0
        /// <summary>
        /// Returns set of market data which combines the data from this set of data with another set.
        /// <para>
        /// If the same item of data is available in both sets, it will be taken from this set.
        /// </para>
        /// <para>
        /// Both sets of data must contain the same number of scenarios, or one of them must have one scenario.
        /// If one of the sets of data has one scenario, the combined set will have the scenario count
        /// of the other set.
        /// </para>
        /// <para>
        /// The valuation dates are taken from this set of data.
        ///
        /// </para>
        /// </summary>
        /// <param name="other">  another set of market data </param>
        /// <returns> a set of market data combining the data in this set with the data in the other </returns>
        public ImmutableScenarioMarketData combinedWith(ImmutableScenarioMarketData other)
        {
            if (scenarioCount != 1 && other.scenarioCount != 1 && scenarioCount != other.scenarioCount)
            {
                throw new System.ArgumentException(Messages.format("When merging scenario market data, both sets of data must have the same number of scenarios or " + "at least one of them must have one scenario. Number of scenarios: {} and {}", scenarioCount, other.scenarioCount));
            }
            int mergedCount = Math.Max(scenarioCount, other.scenarioCount);
            // Use HashMap because it allows values to be overwritten. ImmutableMap builders throw an exception if a value
            // is added using a key which is already present
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, MarketDataBox<?>> values = new java.util.HashMap<>(other.values);
            IDictionary <MarketDataId <object>, MarketDataBox <object> > values = new Dictionary <MarketDataId <object>, MarketDataBox <object> >(other.values);

//JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'putAll' method:
            values.putAll(this.values);
            IDictionary <ObservableId, LocalDateDoubleTimeSeries> timeSeries = new Dictionary <ObservableId, LocalDateDoubleTimeSeries>(other.timeSeries);

//JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'putAll' method:
            timeSeries.putAll(this.timeSeries);
            return(new ImmutableScenarioMarketData(mergedCount, valuationDate, values, timeSeries));
        }
        public virtual void test_combinedWith()
        {
            LocalDateDoubleTimeSeries timeSeries1 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 1).put(date(2011, 3, 9), 2).put(date(2011, 3, 10), 3).build();

            LocalDateDoubleTimeSeries timeSeries2 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 10).put(date(2011, 3, 9), 20).put(date(2011, 3, 10), 30).build();

            LocalDateDoubleTimeSeries timeSeries2a = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 1000).put(date(2011, 3, 9), 2000).put(date(2011, 3, 10), 3000).build();

            LocalDateDoubleTimeSeries timeSeries3 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 100).put(date(2011, 3, 9), 200).put(date(2011, 3, 10), 300).build();

            ImmutableScenarioMarketData marketData1 = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addTimeSeries(TEST_ID1, timeSeries1).addTimeSeries(TEST_ID2, timeSeries2).addBox(TEST_ID1, MarketDataBox.ofScenarioValues(1.0, 1.1, 1.2)).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(2.0, 2.1, 2.2)).build();

            ImmutableScenarioMarketData marketData2 = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 10)).addTimeSeries(TEST_ID2, timeSeries2a).addTimeSeries(TEST_ID3, timeSeries3).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(21.0, 21.1, 21.2)).addBox(TEST_ID3, MarketDataBox.ofScenarioValues(3.0, 3.1, 3.2)).build();

            // marketData1 values should be in the combined data when the same ID is present in both
            ImmutableScenarioMarketData expected = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addTimeSeries(TEST_ID1, timeSeries1).addTimeSeries(TEST_ID2, timeSeries2).addTimeSeries(TEST_ID3, timeSeries3).addBox(TEST_ID1, MarketDataBox.ofScenarioValues(1.0, 1.1, 1.2)).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(2.0, 2.1, 2.2)).addBox(TEST_ID3, MarketDataBox.ofScenarioValues(3.0, 3.1, 3.2)).build();

            ScenarioMarketData combined = marketData1.combinedWith(marketData2);

            assertThat(combined).isEqualTo(expected);
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            ExtendedScenarioMarketData <string> test = ExtendedScenarioMarketData.of(ID1, VAL1, BASE_DATA);

            coverImmutableBean(test);
            ExtendedScenarioMarketData <string> test2 = ExtendedScenarioMarketData.of(ID2, VAL2, ImmutableScenarioMarketData.of(3, VAL_DATE, ImmutableMap.of(), ImmutableMap.of()));

            coverBeanEquals(test, test2);
        }
        private static ImmutableScenarioMarketData baseData()
        {
            IDictionary <ObservableId, LocalDateDoubleTimeSeries> timeSeriesMap = ImmutableMap.of(ID4, TIME_SERIES);

            return(ImmutableScenarioMarketData.builder(VAL_DATE).addBox(ID1, VAL1).addBox(ID2, VAL2).addTimeSeriesMap(timeSeriesMap).build());
        }
Example #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeClass public void setUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void setUp()
        {
            ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addValue(FxRateId.of(Currency.GBP, Currency.USD), FxRate.of(Currency.GBP, Currency.USD, 1.4d)).build();

            fxRateProvider = ScenarioFxRateProvider.of(marketData);
        }
        //-------------------------------------------------------------------------
        public virtual void addNothing()
        {
            ImmutableScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).build();

            assertEquals(marketData.ScenarioCount, 1);
        }