//------------------------------------------------------------------------- public virtual void test_parse_future() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "F-ECAG-FGBL"); EtdContractSpec contract = EtdContractSpec.builder().id(specId).type(EtdType.FUTURE).exchangeId(ExchangeIds.ECAG).contractCode(FGBL).description("Dummy").priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)).build(); ReferenceData refData = ImmutableReferenceData.of(specId, contract); PositionCsvLoader test = PositionCsvLoader.of(refData); ValueWithFailures <IList <EtdFuturePosition> > trades = test.parse(ImmutableList.of(FILE.CharSource), typeof(EtdFuturePosition)); IList <EtdFuturePosition> filtered = trades.Value; assertEquals(filtered.Count, 4); EtdFuturePosition expected1 = EtdFuturePosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123421")).build()).security(EtdFutureSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofMonthly())).longQuantity(15d).shortQuantity(2d).build(); assertBeanEquals(expected1, filtered[0]); EtdFuturePosition expected2 = EtdFuturePosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123422")).build()).security(EtdFutureSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofFlexFuture(13, EtdSettlementType.CASH))).longQuantity(0d).shortQuantity(13d).build(); assertBeanEquals(expected2, filtered[1]); EtdFuturePosition expected3 = EtdFuturePosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123423")).build()).security(EtdFutureSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofWeekly(2))).longQuantity(0d).shortQuantity(20d).build(); assertBeanEquals(expected3, filtered[2]); EtdFuturePosition expected4 = EtdFuturePosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123424")).build()).security(EtdFutureSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofDaily(3))).longQuantity(30d).shortQuantity(0d).build(); assertBeanEquals(expected4, filtered[3]); }
// obtains the data and calculates the grid of results private static void calculate(CalculationRunner runner) { // the trades that will have measures calculated IList <Trade> trades = ImmutableList.of(createFutureTrade1(), createFutureTrade2(), createOptionTrade1(), createOptionTrade2()); // the columns, specifying the measures to be calculated IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE)); // use the built-in example market data LocalDate valuationDate = LocalDate.of(2014, 1, 22); ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder(); MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate); // the complete set of rules for calculating measures CalculationFunctions functions = StandardComponents.calculationFunctions(); CalculationRules rules = CalculationRules.of(functions); // the reference data, such as holidays and securities //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.basics.ReferenceData refData = com.opengamma.strata.basics.ImmutableReferenceData.of(com.google.common.collect.ImmutableMap.of<com.opengamma.strata.basics.ReferenceDataId<?>, Object>(FGBL_MAR14_ID, FGBL_MAR14, OGBL_MAR14_C150_ID, OGBL_MAR14_C150, ED_MAR14_ID, ED_MAR14)); ReferenceData refData = ImmutableReferenceData.of(ImmutableMap.of <ReferenceDataId <object>, object>(FGBL_MAR14_ID, FGBL_MAR14, OGBL_MAR14_C150_ID, OGBL_MAR14_C150, ED_MAR14_ID, ED_MAR14)); // calculate the results Results results = runner.calculate(rules, trades, columns, marketData, refData); // use the report runner to transform the engine results into a trade report ReportCalculationResults calculationResults = ReportCalculationResults.of(valuationDate, trades, columns, results, functions, refData); TradeReportTemplate reportTemplate = ExampleData.loadTradeReportTemplate("security-report-template"); TradeReport tradeReport = TradeReport.of(calculationResults, reportTemplate); tradeReport.writeAsciiTable(System.out); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testImmutableReferenceDataWithMergedHolidays() public virtual void testImmutableReferenceDataWithMergedHolidays() { HolidayCalendar hc = HolidayCalendars.FRI_SAT.combinedWith(HolidayCalendars.SAT_SUN); ImmutableReferenceData referenceData = ImmutableReferenceData.of(hc.Id, hc); LocalDate date = BusinessDayAdjustment.of(BusinessDayConventions.PRECEDING, hc.Id).adjust(LocalDate.of(2016, 8, 20), referenceData); assertEquals(LocalDate.of(2016, 8, 18), date); }
public virtual void test_ofBusinessDays3_adjust() { ImmutableHolidayCalendar cal = ImmutableHolidayCalendar.of(WED_THU, ImmutableList.of(), WEDNESDAY, THURSDAY); ReferenceData refData = ImmutableReferenceData.of(ImmutableMap.of(WED_THU, cal)).combinedWith(REF_DATA); DaysAdjustment test = DaysAdjustment.ofBusinessDays(3, SAT_SUN, BDA_FOLLOW_WED_THU); LocalDate @base = date(2014, 8, 15); // Fri assertEquals(test.adjust(@base, refData), date(2014, 8, 22)); // Fri (3 days gives Wed, following moves to Fri) assertEquals(test.resolve(refData).adjust(@base), date(2014, 8, 22)); // Fri (3 days gives Wed, following moves to Fri) }
//------------------------------------------------------------------------- public virtual void test_resolve_single() { HolidayCalendarId gb = HolidayCalendarId.of("GB"); HolidayCalendarId eu = HolidayCalendarId.of("EU"); HolidayCalendar gbCal = HolidayCalendars.SAT_SUN; ReferenceData refData = ImmutableReferenceData.of(gb, gbCal); assertEquals(gb.resolve(refData), gbCal); assertThrows(() => eu.resolve(refData), typeof(ReferenceDataNotFoundException)); assertEquals(refData.getValue(gb), gbCal); }
//------------------------------------------------------------------------- public virtual void test_defaulting() { ReferenceData @base = ImmutableReferenceData.of(ImmutableMap.of(HolidayCalendarIds.FRI_SAT, HolidayCalendars.FRI_SAT)); ReferenceData test = HolidayCalendars.defaultingReferenceData(@base); assertEquals(test.getValue(HolidayCalendarIds.FRI_SAT), HolidayCalendars.FRI_SAT); assertEquals(test.getValue(HolidayCalendarIds.GBLO), DEFAULTED_GBLO); assertEquals(test.containsValue(HolidayCalendarIds.FRI_SAT), true); assertEquals(test.containsValue(HolidayCalendarIds.GBLO), true); assertEquals(test.containsValue(new TestingReferenceDataId("1")), false); }
public virtual void test_resolve_combined_direct() { HolidayCalendarId gb = HolidayCalendarId.of("GB"); HolidayCalendar gbCal = HolidayCalendars.SAT_SUN; HolidayCalendarId eu = HolidayCalendarId.of("EU"); HolidayCalendar euCal = HolidayCalendars.FRI_SAT; HolidayCalendarId combined = gb.combinedWith(eu); HolidayCalendar combinedCal = euCal.combinedWith(gbCal); ReferenceData refData = ImmutableReferenceData.of(ImmutableMap.of(combined, combinedCal)); assertEquals(combined.resolve(refData), combinedCal); assertEquals(refData.getValue(combined), combinedCal); }
public virtual void test_load_invalidNoQuantity() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "F-ECAG-FGBL"); EtdContractSpec contract = EtdContractSpec.builder().id(specId).type(EtdType.FUTURE).exchangeId(ExchangeIds.ECAG).contractCode(FGBL).description("Dummy").priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)).build(); ReferenceData refData = ImmutableReferenceData.of(specId, contract); PositionCsvLoader test = PositionCsvLoader.of(refData); ValueWithFailures <IList <Position> > trades = test.parse(ImmutableList.of(CharSource.wrap("Strata Position Type,Exchange,Contract Code,Expiry\nFUT,ECAG,FGBL,2017-06"))); assertEquals(trades.Failures.size(), 1); FailureItem failure = trades.Failures.get(0); assertEquals(failure.Reason, FailureReason.PARSING); assertEquals(failure.Message, "CSV file position could not be parsed at line 2: " + "Security must contain a quantity column, either 'Quantity' or 'Long Quantity' and 'Short Quantity'"); }
public virtual void test_defaulting_combinedWith() { ReferenceData base1 = ImmutableReferenceData.of(ImmutableMap.of(HolidayCalendarIds.THU_FRI, HolidayCalendars.THU_FRI)); ReferenceData base2 = ImmutableReferenceData.of(ImmutableMap.of(HolidayCalendarIds.THU_FRI, HolidayCalendars.FRI_SAT, HolidayCalendarIds.FRI_SAT, HolidayCalendars.FRI_SAT)); ReferenceData testDefaulted = HolidayCalendars.defaultingReferenceData(base1); assertEquals(testDefaulted.getValue(HolidayCalendarIds.THU_FRI), HolidayCalendars.THU_FRI); assertEquals(testDefaulted.getValue(HolidayCalendarIds.FRI_SAT), DEFAULTED_FRI_SAT); assertEquals(testDefaulted.getValue(HolidayCalendarIds.GBLO), DEFAULTED_GBLO); ReferenceData testCombined = testDefaulted.combinedWith(base2); assertEquals(testCombined.getValue(HolidayCalendarIds.THU_FRI), HolidayCalendars.THU_FRI); // test1 takes precedence assertEquals(testCombined.getValue(HolidayCalendarIds.FRI_SAT), HolidayCalendars.FRI_SAT); // from test2 assertEquals(testCombined.getValue(HolidayCalendarIds.GBLO), DEFAULTED_GBLO); // from default ReferenceData testCombinedRevered = base2.combinedWith(testDefaulted); assertEquals(testCombinedRevered.getValue(HolidayCalendarIds.THU_FRI), HolidayCalendars.FRI_SAT); // test2 takes precedence assertEquals(testCombinedRevered.getValue(HolidayCalendarIds.FRI_SAT), HolidayCalendars.FRI_SAT); // from test2 assertEquals(testCombinedRevered.getValue(HolidayCalendarIds.GBLO), DEFAULTED_GBLO); // from default }
//------------------------------------------------------------------------- public virtual void test_parse_option() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "O-ECAG-OGBL"); EtdContractSpec contract = EtdContractSpec.builder().id(specId).type(EtdType.OPTION).exchangeId(ExchangeIds.ECAG).contractCode(OGBL).description("Dummy").priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)).build(); ReferenceData refData = ImmutableReferenceData.of(specId, contract); PositionCsvLoader test = PositionCsvLoader.of(refData); ValueWithFailures <IList <EtdOptionPosition> > trades = test.parse(ImmutableList.of(FILE.CharSource), typeof(EtdOptionPosition)); IList <EtdOptionPosition> filtered = trades.Value; assertEquals(filtered.Count, 3); EtdOptionPosition expected1 = EtdOptionPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123431")).build()).security(EtdOptionSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofMonthly(), 0, PutCall.PUT, 3d, YearMonth.of(2017, 9))).longQuantity(15d).shortQuantity(2d).build(); assertBeanEquals(expected1, filtered[0]); EtdOptionPosition expected2 = EtdOptionPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123432")).build()).security(EtdOptionSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofFlexOption(13, EtdSettlementType.CASH, EtdOptionType.AMERICAN), 0, PutCall.CALL, 4d)).longQuantity(0d).shortQuantity(13d).build(); assertBeanEquals(expected2, filtered[1]); EtdOptionPosition expected3 = EtdOptionPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123433")).build()).security(EtdOptionSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofWeekly(2), 0, PutCall.PUT, 5.1d)).longQuantity(0d).shortQuantity(20d).build(); assertBeanEquals(expected3, filtered[2]); }