Пример #1
0
        //-------------------------------------------------------------------------
        public virtual void test_summarize()
        {
            BillTrade            trade    = sut_yield();
            PortfolioItemSummary expected = PortfolioItemSummary.builder().id(TRADE_INFO.Id.orElse(null)).portfolioItemType(PortfolioItemType.TRADE).productType(ProductType.BILL).currencies(Currency.USD).description("Bill2019-05-23 x 123").build();

            assertEquals(trade.summarize(), expected);
        }
Пример #2
0
        /// <summary>
        /// Generates a Bill trade instance where the price is computed from the traded yield.
        /// </summary>
        /// <param name="info">  the additional trade information </param>
        /// <param name="product">  the bill that was traded </param>
        /// <param name="quantity">  the quantity that was traded </param>
        /// <param name="yield">  the yield at which the bill was traded </param>
        /// <returns>  the instance </returns>
        public static BillTrade ofYield(TradeInfo info, Bill product, double quantity, double yield)
        {
            ArgChecker.isTrue(info.SettlementDate.Present, "Bill trades from yield need a settlement date");
            LocalDate settlementDate = info.SettlementDate.get();
            double    price          = product.priceFromYield(yield, settlementDate);

            return(BillTrade.builder().info(info).product(product).quantity(quantity).price(price).build());
        }
Пример #3
0
        public virtual void test_withPrice()
        {
            BillTrade @base    = sut_yield();
            double    price    = 135d;
            BillTrade computed = @base.withPrice(price);
            BillTrade expected = BillTrade.builder().info(TRADE_INFO).product(PRODUCT).quantity(QUANTITY).price(price).build();

            assertEquals(computed, expected);
        }
Пример #4
0
        //-------------------------------------------------------------------------
        public virtual void test_withQuantity()
        {
            BillTrade @base    = sut_price();
            double    quantity = 75343d;
            BillTrade computed = @base.withQuantity(quantity);
            BillTrade expected = BillTrade.builder().info(TRADE_INFO).product(PRODUCT).quantity(quantity).price(PRICE).build();

            assertEquals(computed, expected);
        }
        //-------------------------------------------------------------------------
        public virtual void test_createProduct()
        {
            BillSecurity @base           = BillSecurity.builder().dayCount(DAY_COUNT).info(INFO).legalEntityId(LEGAL_ENTITY).notional(NOTIONAL).settlementDateOffset(SETTLE).yieldConvention(YIELD_CONVENTION).build();
            Bill         expectedProduct = Bill.builder().dayCount(DAY_COUNT).securityId(SECURITY_ID).dayCount(DAY_COUNT).legalEntityId(LEGAL_ENTITY).notional(NOTIONAL).settlementDateOffset(SETTLE).yieldConvention(YIELD_CONVENTION).build();

            assertEquals(@base.createProduct(ReferenceData.empty()), expectedProduct);
            TradeInfo tradeInfo     = TradeInfo.of(date(2016, 6, 30));
            BillTrade expectedTrade = BillTrade.builder().info(tradeInfo).product(expectedProduct).quantity(100).price(1.235).build();

            assertEquals(@base.createTrade(tradeInfo, 100, 1.235, ReferenceData.empty()), expectedTrade);
        }
Пример #6
0
        public virtual void test_builder_price()
        {
            BillTrade test = sut_price();

            assertEquals(test.Product, PRODUCT);
            assertEquals(test.Info, TRADE_INFO);
            assertEquals(test.Quantity, QUANTITY);
            assertEquals(test.Price, PRICE, TOLERANCE_PRICE);
            assertEquals(test.withInfo(TRADE_INFO).Info, TRADE_INFO);
            assertEquals(test.withQuantity(129).Quantity, 129d, 0d);
            assertEquals(test.withPrice(129).Price, 129d, 0d);
        }
Пример #7
0
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         BillTrade other = (BillTrade)obj;
         return(JodaBeanUtils.equal(info, other.info) && JodaBeanUtils.equal(product, other.product) && JodaBeanUtils.equal(quantity, other.quantity) && JodaBeanUtils.equal(price, other.price));
     }
     return(false);
 }
Пример #8
0
        //-------------------------------------------------------------------------
        public virtual void test_ofYield()
        {
            BillTrade test = sut_yield();

            assertEquals(test.Product, PRODUCT);
            assertEquals(test.Info, TRADE_INFO);
            assertEquals(test.Quantity, QUANTITY);
            double price = 1.0d - YIELD * PRODUCT.DayCount.relativeYearFraction(SETTLEMENT_DATE, PRODUCT.Notional.Date.Unadjusted);

            assertEquals(test.Price, price, TOLERANCE_PRICE);
            assertEquals(test.withInfo(TRADE_INFO).Info, TRADE_INFO);
            assertEquals(test.withQuantity(129).Quantity, 129d, 0d);
            assertEquals(test.withPrice(129).Price, 129d, 0d);
        }
Пример #9
0
 public virtual void test_of_yield_settledate()
 {
     assertThrows(() => BillTrade.ofYield(TradeInfo.builder().tradeDate(TRADE_DATE).build(), PRODUCT, QUANTITY, YIELD), typeof(System.ArgumentException));
 }
Пример #10
0
 public virtual void test_settle_or_trade()
 {
     assertThrows(() => BillTrade.builder().info(TradeInfo.empty()).product(PRODUCT).quantity(QUANTITY).price(PRICE).build(), typeof(System.ArgumentException));
 }
Пример #11
0
 public virtual void test_price()
 {
     assertThrows(() => BillTrade.builder().info(TRADE_INFO).product(PRODUCT).quantity(QUANTITY).build(), typeof(System.ArgumentException));
 }
Пример #12
0
 internal static BillTrade sut2()
 {
     return(BillTrade.builder().info(TRADE_INFO2).product(PRODUCT2).quantity(100L).price(PRICE2).build());
 }
Пример #13
0
 internal static BillTrade sut_price()
 {
     return(BillTrade.ofPrice(TRADE_INFO, PRODUCT, QUANTITY, PRICE));
 }
Пример #14
0
 //-------------------------------------------------------------------------
 internal static BillTrade sut_yield()
 {
     return(BillTrade.ofYield(TRADE_INFO, PRODUCT, QUANTITY, YIELD));
 }
Пример #15
0
 /// <summary>
 /// Generates a Bill trade instance from the price.
 /// </summary>
 /// <param name="info">  the additional trade information </param>
 /// <param name="product">  the bill that was traded </param>
 /// <param name="quantity">  the quantity that was traded </param>
 /// <param name="price">  the price at which the bill was traded </param>
 /// <returns>  the instance </returns>
 public static BillTrade ofPrice(TradeInfo info, Bill product, double quantity, double price)
 {
     return(BillTrade.builder().info(info).product(product).quantity(quantity).price(price).build());
 }