// create a trade private static Trade createTrade2(ReferenceData refData) { SecurityId secId = SecurityId.of("OG-Future", "Ibor-USD-LIBOR-3M-Jun15"); IborFutureTrade trade = IborFutureConventions.USD_LIBOR_3M_QUARTERLY_IMM.createTrade(LocalDate.of(2014, 9, 12), secId, Period.ofMonths(1), 3, 10, 1_000_000, 0.9996, refData); return(trade.toBuilder().info(TradeInfo.builder().id(StandardId.of("example", "1")).addAttribute(AttributeType.DESCRIPTION, "Jun15 IMM Ibor Future").counterparty(StandardId.of("example", "A")).tradeDate(LocalDate.of(2014, 9, 12)).settlementDate(LocalDate.of(2014, 9, 14)).build()).quantity(20).price(0.9997).build()); }
// calculate the last fixing date private LocalDate calculateLastFixingDate(LocalDate valuationDate, ReferenceData refData) { SecurityId secId = SecurityId.of(rateId.StandardId); // quote must also be security IborFutureTrade trade = template.createTrade(valuationDate, secId, 1, 1, 1, refData); return(trade.Product.FixingDate); }
/// <summary> /// Creates an identifier for an ETD option instrument. /// <para> /// This takes into account the expiry of the underlying instrument. If the underlying expiry /// is the same as the expiry of the option, the identifier is the same as the normal one. /// Otherwise, the underlying expiry is added after the option expiry. For example: /// {@code 'OG-ETD~O-ECAG-OGBS-201706-P1.50-U201709'}. /// /// </para> /// </summary> /// <param name="exchangeId"> the MIC code of the exchange where the instruments are traded </param> /// <param name="contractCode"> the code supplied by the exchange for use in clearing and margining, such as in SPAN </param> /// <param name="expiryMonth"> the month of expiry </param> /// <param name="variant"> the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param> /// <param name="version"> the non-negative version, zero by default </param> /// <param name="putCall"> the Put/Call flag </param> /// <param name="strikePrice"> the strike price </param> /// <param name="underlyingExpiryMonth"> the expiry of the underlying instrument, such as a future, may be null </param> /// <returns> the identifier </returns> public static SecurityId optionId(ExchangeId exchangeId, EtdContractCode contractCode, YearMonth expiryMonth, EtdVariant variant, int version, PutCall putCall, double strikePrice, YearMonth underlyingExpiryMonth) { ArgChecker.notNull(exchangeId, "exchangeId"); ArgChecker.notNull(contractCode, "contractCode"); ArgChecker.notNull(expiryMonth, "expiryMonth"); ArgChecker.notNull(variant, "variant"); ArgChecker.notNull(putCall, "putCall"); string putCallStr = putCall == PutCall.PUT ? "P" : "C"; string versionCode = version > 0 ? "V" + version + SEPARATOR : ""; NumberFormat f = NumberFormat.getIntegerInstance(Locale.ENGLISH); f.GroupingUsed = false; f.MaximumFractionDigits = 8; string strikeStr = f.format(strikePrice).replace('-', 'M'); string underlying = ""; if (underlyingExpiryMonth != null && !underlyingExpiryMonth.Equals(expiryMonth)) { underlying = SEPARATOR + "U" + underlyingExpiryMonth.format(YM_FORMAT); } string id = (new StringBuilder(40)).Append(OPT_PREFIX).Append(exchangeId).Append(SEPARATOR).Append(contractCode).Append(SEPARATOR).Append(expiryMonth.format(YM_FORMAT)).Append(variant.Code).Append(SEPARATOR).Append(versionCode).Append(putCallStr).Append(strikeStr).Append(underlying).ToString(); return(SecurityId.of(ETD_SCHEME, id)); }
//----------------------------------------------------------------------- // create a trade private static Trade createTrade1(ReferenceData refData) { Swap swap = FixedIborSwapConventions.USD_FIXED_6M_LIBOR_3M.createTrade(LocalDate.of(2015, 3, 18), Tenor.TENOR_5Y, BuySell.SELL, 1, 0.02, refData).Product; Dsf product = Dsf.builder().securityId(SecurityId.of("OG-Future", "CME-F1U-Mar15")).lastTradeDate(LocalDate.of(2015, 3, 16)).deliveryDate(LocalDate.of(2015, 3, 18)).notional(100_000).underlyingSwap(swap).build(); return(DsfTrade.builder().info(TradeInfo.builder().id(StandardId.of("example", "1")).addAttribute(AttributeType.DESCRIPTION, "CME-5Y-DSF Mar15").counterparty(StandardId.of("mn", "Dealer G")).tradeDate(LocalDate.of(2015, 3, 18)).settlementDate(LocalDate.of(2015, 3, 18)).build()).product(product).quantity(20).price(1.0075).build()); }
public IborFutureTrade trade(double quantity, MarketData marketData, ReferenceData refData) { LocalDate valuationDate = marketData.ValuationDate; double price = marketPrice(marketData) + additionalSpread; SecurityId secId = SecurityId.of(rateId.StandardId); // quote must also be security return(template.createTrade(valuationDate, secId, quantity, 1d, price, refData)); }
private static Trade trade() { SecurityInfo info = SecurityInfo.of(SecurityId.of("OG-Test", "1"), 20, CurrencyAmount.of(USD, 10)); GenericSecurity security = GenericSecurity.of(info); TradeInfo tradeInfo = TradeInfo.builder().counterparty(StandardId.of("cpty", "a")).build(); return(GenericSecurityTrade.builder().info(tradeInfo).security(security).quantity(123).price(456).build()); }
//------------------------------------------------------------------------- public virtual void test_summary_position() { StandardId id = StandardId.of("X", "Y"); SecurityPosition position = SecurityPosition.builder().securityId(SecurityId.of("A", "B")).longQuantity(123).info(PositionInfo.of(id)).build(); string description = "desc"; PortfolioItemSummary expected = PortfolioItemSummary.of(id, PortfolioItemType.POSITION, ProductType.SECURITY, ImmutableSet.of(GBP), description); assertEquals(SummarizerUtils.summary(position, ProductType.SECURITY, description, GBP), expected); }
public virtual void test_trade() { IborFutureCurveNode node = IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); double price = 0.99; MarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, price).build(); IborFutureTrade trade = node.trade(1d, marketData, REF_DATA); IborFutureTrade expected = TEMPLATE.createTrade(VAL_DATE, SecurityId.of(STANDARD_ID), 1L, 1.0, price + SPREAD, REF_DATA); assertEquals(trade, expected); }
//------------------------------------------------------------------------- public virtual void createFutureAutoId() { EtdFutureSecurity security = FUTURE_CONTRACT.createFuture(YearMonth.of(2015, 6), EtdVariant.MONTHLY); assertThat(security.SecurityId).isEqualTo(SecurityId.of(EtdIdUtils.ETD_SCHEME, "F-ECAG-FOO-201506")); assertThat(security.Expiry).isEqualTo(YearMonth.of(2015, 6)); assertThat(security.ContractSpecId).isEqualTo(FUTURE_CONTRACT.Id); assertThat(security.Variant).isEqualTo(EtdVariant.MONTHLY); assertThat(security.Info.PriceInfo).isEqualTo(FUTURE_CONTRACT.PriceInfo); }
/// <summary> /// Creates an identifier for an ETD future instrument. /// <para> /// A typical monthly ETD will have the format: /// {@code 'OG-ETD~O-ECAG-OGBS-201706'}. /// </para> /// <para> /// A more complex flex ETD (12th of the month, Physical settlement) will have the format: /// {@code 'OG-ETD~O-ECAG-OGBS-20170612E'}. /// /// </para> /// </summary> /// <param name="exchangeId"> the MIC code of the exchange where the instruments are traded </param> /// <param name="contractCode"> the code supplied by the exchange for use in clearing and margining, such as in SPAN </param> /// <param name="expiryMonth"> the month of expiry </param> /// <param name="variant"> the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param> /// <returns> the identifier </returns> public static SecurityId futureId(ExchangeId exchangeId, EtdContractCode contractCode, YearMonth expiryMonth, EtdVariant variant) { ArgChecker.notNull(exchangeId, "exchangeId"); ArgChecker.notNull(contractCode, "contractCode"); ArgChecker.notNull(expiryMonth, "expiryMonth"); ArgChecker.isTrue(expiryMonth.Year >= 1000 && expiryMonth.Year <= 9999, "Invalid expiry year: ", expiryMonth); ArgChecker.notNull(variant, "variant"); string id = (new StringBuilder(40)).Append(FUT_PREFIX).Append(exchangeId).Append(SEPARATOR).Append(contractCode).Append(SEPARATOR).Append(expiryMonth.format(YM_FORMAT)).Append(variant.Code).ToString(); return(SecurityId.of(ETD_SCHEME, id)); }
//------------------------------------------------------------------------- public virtual void test_createTrade() { IborFutureTemplate @base = IborFutureTemplate.of(YEAR_MONTH, CONVENTION); LocalDate date = LocalDate.of(2015, 10, 20); double quantity = 3; double price = 0.99; double notional = 100.0; SecurityId secId = SecurityId.of("OG-Future", "GBP-LIBOR-3M-Jun16"); IborFutureTrade trade = @base.createTrade(date, secId, quantity, notional, price, REF_DATA); IborFutureTrade expected = CONVENTION.createTrade(date, secId, YEAR_MONTH, quantity, notional, price, REF_DATA); assertEquals(trade, expected); }
//------------------------------------------------------------------------- public virtual void createOptionWithUnderlyingAutoId() { EtdOptionSecurity security = OPTION_CONTRACT.createOption(YearMonth.of(2015, 6), EtdVariant.MONTHLY, 0, PutCall.CALL, 123.45, YearMonth.of(2015, 9)); assertThat(security.SecurityId).isEqualTo(SecurityId.of(EtdIdUtils.ETD_SCHEME, "O-IFEN-BAR-201506-C123.45-U201509")); assertThat(security.Expiry).isEqualTo(YearMonth.of(2015, 6)); assertThat(security.ContractSpecId).isEqualTo(OPTION_CONTRACT.Id); assertThat(security.Variant).isEqualTo(EtdVariant.MONTHLY); assertThat(security.PutCall).isEqualTo(PutCall.CALL); assertThat(security.StrikePrice).isEqualTo(123.45); assertThat(security.UnderlyingExpiryMonth).hasValue(YearMonth.of(2015, 9)); assertThat(security.Info.PriceInfo).isEqualTo(OPTION_CONTRACT.PriceInfo); }
public virtual void test_toTrade() { LocalDate date = LocalDate.of(2015, 10, 20); Period start = Period.ofMonths(2); int number = 2; // Future should be 20 Dec 15 + 2 IMM = effective 15-Jun-2016, fixing 13-Jun-2016 IborFutureConvention convention = ImmutableIborFutureConvention.of(USD_LIBOR_3M, QUARTERLY_IMM); double quantity = 3; double price = 0.99; SecurityId secId = SecurityId.of("OG-Future", "GBP-LIBOR-3M-Jun16"); IborFutureTrade trade = convention.createTrade(date, secId, start, number, quantity, NOTIONAL_1M, price, REF_DATA); assertEquals(trade.Product.FixingDate, LocalDate.of(2016, 6, 13)); assertEquals(trade.Product.Index, USD_LIBOR_3M); assertEquals(trade.Product.Notional, NOTIONAL_1M); assertEquals(trade.Product.AccrualFactor, 0.25); assertEquals(trade.Quantity, quantity); assertEquals(trade.Price, price); }
static BondFuturesJpyEnd2EndTest() { for (int i = 0; i < NB_UND_BONDS; ++i) { PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE[i], MATURITY_DATE[i], Frequency.P6M, BUSINESS_ADJUST, StubConvention.SHORT_INITIAL, false); FixedCouponBond product = FixedCouponBond.builder().securityId(SecurityId.of(BOND_SECURITY_ID[i])).dayCount(DAY_COUNT).fixedRate(UND_RATES[i] * ONE_PERCENT).legalEntityId(ISSUER_ID).currency(JPY).notional(NOTIONAL).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS).yieldConvention(YIELD_CONVENTION).build(); UND_BOND[i] = product; } UND_BOND_SEP = new FixedCouponBond[NB_UND_BONDS - 2]; Array.Copy(UND_BOND, 2, UND_BOND_SEP, 0, NB_UND_BONDS - 2); UND_BOND_JUN = new FixedCouponBond[NB_UND_BONDS - 1]; Array.Copy(UND_BOND, 1, UND_BOND_JUN, 0, NB_UND_BONDS - 1); double[] timeIssuer = new double[] { 0.25136612021857924, 0.4972677595628415, 1.0139980537465378, 2.013998053746538, 2.857833670184894, 3.857833670184894, 4.860655737704918, 5.857833670184894, 7.104409012650647, 7.857833670184894, 8.857923497267759, 9.863313122239688, 14.857833670184894, 19.857833670184895, 29.857833670184895, 39.11262819073284 }; double[] rateIssuer = new double[] { -0.0013117084834668065, -0.0010851901424876163, -0.0020906775838723216, -0.0022137102045172784, -0.0022695678374162888, -0.0023424568490920798, -0.0021603059162879916, -0.0021667343131861225, -0.0018285921969274823, -0.001355094018965514, -6.763044056712535E-4, 1.9555294306801752E-4, 0.003944125562941363, 0.008054233458390252, 0.012276105941434846, 0.013537766297065804 }; double[] timeRepo = new double[] { 0.00273224043715847, 0.01912568306010929, 0.040983606557377046, 0.05737704918032787, 0.07923497267759563, 0.2459016393442623, 0.4972677595628415, 1.0002994236095515 }; double[] rateRepo = new double[] { 2.599662058772748E-4, -8.403529976927196E-4, -0.0010105103936934236, -0.0011506617573950931, -0.0012708071334455143, -0.00146106683851595, -0.0014710815100096722, -0.001481096281798276 }; CurveMetadata metaIssuer = Curves.zeroRates(ISSUER_CURVE_NAME, ACT_ACT_ISDA); InterpolatedNodalCurve curveIssuer = InterpolatedNodalCurve.of(metaIssuer, DoubleArray.copyOf(timeIssuer), DoubleArray.copyOf(rateIssuer), INTERPOLATOR); DiscountFactors dscIssuer = ZeroRateDiscountFactors.of(JPY, VALUATION, curveIssuer); CurveMetadata metaRepo = Curves.zeroRates(REPO_CURVE_NAME, ACT_ACT_ISDA); InterpolatedNodalCurve curve = InterpolatedNodalCurve.of(metaRepo, DoubleArray.copyOf(timeRepo), DoubleArray.copyOf(rateRepo), INTERPOLATOR); DiscountFactors dscRepo = ZeroRateDiscountFactors.of(JPY, VALUATION, curve); LED_PROVIDER = ImmutableLegalEntityDiscountingProvider.builder().issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, JPY), dscIssuer)).issuerCurveGroups(ImmutableMap.of(ISSUER_ID, GROUP_ISSUER)).repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO, JPY), dscRepo)).repoCurveGroups(ImmutableMap.of(ISSUER_ID, GROUP_REPO)).build(); }
static BondFutureTest() { for (int i = 0; i < NB_BOND; ++i) { LocalDate endDate = START_DATE[i].plus(BOND_TENOR[i]); PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE[i], endDate, Frequency.P6M, BUSINESS_ADJUST, StubConvention.SHORT_INITIAL, false); FixedCouponBond product = FixedCouponBond.builder().securityId(SecurityId.of("OG-Test", "Bond " + i)).dayCount(DAY_COUNT).fixedRate(RATE[i]).legalEntityId(ISSUER_ID).currency(USD).notional(NOTIONAL).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS).yieldConvention(YIELD_CONVENTION).exCouponPeriod(EX_COUPON).build(); BOND_PRODUCT[i] = product; RESOLVED_BASKET[i] = product.resolve(REF_DATA); } }
//------------------------------------------------------------------------- public virtual void coverage() { BillSecurity test1 = BillSecurity.builder().dayCount(DAY_COUNT).info(INFO).legalEntityId(LEGAL_ENTITY).notional(NOTIONAL).settlementDateOffset(SETTLE).yieldConvention(YIELD_CONVENTION).build(); coverImmutableBean(test1); BillSecurity test2 = BillSecurity.builder().dayCount(DayCounts.ACT_365F).info(SecurityInfo.of(SecurityId.of("OG-Test", "ID2"), PRICE_INFO)).legalEntityId(LegalEntityId.of("OG-Ticker", "LE2")).notional(AdjustablePayment.of(CurrencyAmount.of(CCY, 10), MATURITY_DATE_ADJ)).settlementDateOffset(DaysAdjustment.ofBusinessDays(2, EUTA, BUSINESS_ADJUST)).yieldConvention(BillYieldConvention.INTEREST_AT_MATURITY).build(); coverBeanEquals(test1, test2); }
internal static EtdOptionSecurity sut2() { return(EtdOptionSecurity.builder().info(SecurityInfo.of(SecurityId.of("B", "C"), SecurityPriceInfo.of(Currency.EUR, 10))).contractSpecId(EtdContractSpecId.of("test", "234")).expiry(YearMonth.of(2017, 9)).variant(EtdVariant.ofWeekly(2)).version(4).putCall(PutCall.CALL).strikePrice(3).underlyingExpiryMonth(YearMonth.of(2017, 12)).build()); }
//------------------------------------------------------------------------- internal static EtdOptionSecurity sut() { return(EtdOptionSecurity.builder().info(SecurityInfo.of(SecurityId.of("A", "B"), SecurityPriceInfo.of(Currency.GBP, 100))).contractSpecId(EtdContractSpecId.of("test", "123")).expiry(YearMonth.of(2017, 6)).putCall(PutCall.PUT).strikePrice(2).build()); }
//------------------------------------------------------------------------- internal static EtdFutureSecurity sut() { return(EtdFutureSecurity.builder().info(SecurityInfo.of(SecurityId.of("A", "B"), SecurityPriceInfo.of(Currency.GBP, 100))).contractSpecId(EtdContractSpecId.of("test", "123")).expiry(YearMonth.of(2017, 6)).build()); }
//------------------------------------------------------------------------- public virtual void coverage() { ResolvedOvernightFuture test1 = ResolvedOvernightFuture.builder().currency(USD).accrualFactor(ACCRUAL_FACTOR_1M).lastTradeDate(LAST_TRADE_DATE).overnightRate(RATE_COMPUTATION).notional(NOTIONAL).rounding(ROUNDING).securityId(SECURITY_ID).build(); coverImmutableBean(test1); ResolvedOvernightFuture test2 = ResolvedOvernightFuture.builder().currency(GBP).accrualFactor(0.25).lastTradeDate(date(2018, 9, 28)).overnightRate(OvernightRateComputation.of(GBP_SONIA, date(2018, 9, 1), date(2018, 9, 30), 0, OvernightAccrualMethod.AVERAGED_DAILY, REF_DATA)).notional(1.0e8).securityId(SecurityId.of("OG-Test", "OnFuture2")).build(); coverBeanEquals(test1, test2); }
internal static EtdFutureSecurity sut2() { return(EtdFutureSecurity.builder().info(SecurityInfo.of(SecurityId.of("B", "C"), SecurityPriceInfo.of(Currency.EUR, 10))).contractSpecId(EtdContractSpecId.of("test", "234")).expiry(YearMonth.of(2017, 9)).variant(EtdVariant.ofWeekly(2)).build()); }