//-------------------------------------------------------------------------
        public virtual void test_summarize()
        {
            GenericSecurityPosition trade    = sut();
            PortfolioItemSummary    expected = PortfolioItemSummary.builder().id(POSITION_INFO.Id.orElse(null)).portfolioItemType(PortfolioItemType.POSITION).productType(ProductType.SECURITY).currencies(SECURITY.Currency).description("1 x 100").build();

            assertEquals(trade.summarize(), expected);
        }
Exemplo n.º 2
0
        //-------------------------------------------------------------------------
        public virtual void test_resolveTarget()
        {
            SecurityPosition        position         = sut();
            GenericSecurity         resolvedSecurity = GenericSecurity.of(SecurityInfo.of(SECURITY_ID, 1, CurrencyAmount.of(USD, 0.01)));
            ImmutableReferenceData  refData          = ImmutableReferenceData.of(SECURITY_ID, resolvedSecurity);
            GenericSecurityPosition expected         = GenericSecurityPosition.ofLongShort(POSITION_INFO, resolvedSecurity, LONG_QUANTITY, SHORT_QUANTITY);

            assertEquals(position.resolveTarget(refData), expected);
        }
        public virtual void test_ofLongShort_withInfo()
        {
            GenericSecurityPosition test = GenericSecurityPosition.ofLongShort(POSITION_INFO, SECURITY, LONG_QUANTITY, SHORT_QUANTITY);

            assertEquals(test.Info, POSITION_INFO);
            assertEquals(test.Security, SECURITY);
            assertEquals(test.LongQuantity, LONG_QUANTITY);
            assertEquals(test.ShortQuantity, SHORT_QUANTITY);
            assertEquals(test.Quantity, QUANTITY);
        }
        public virtual void test_ofLongShort_noInfo()
        {
            GenericSecurityPosition test = GenericSecurityPosition.ofLongShort(SECURITY, LONG_QUANTITY, SHORT_QUANTITY);

            assertEquals(test.Info, PositionInfo.empty());
            assertEquals(test.Security, SECURITY);
            assertEquals(test.LongQuantity, LONG_QUANTITY);
            assertEquals(test.ShortQuantity, SHORT_QUANTITY);
            assertEquals(test.Quantity, QUANTITY);
        }
        public virtual void test_ofNet_withInfo_negative()
        {
            GenericSecurityPosition test = GenericSecurityPosition.ofNet(POSITION_INFO, SECURITY, -100d);

            assertEquals(test.Info, POSITION_INFO);
            assertEquals(test.Security, SECURITY);
            assertEquals(test.LongQuantity, 0d);
            assertEquals(test.ShortQuantity, 100d);
            assertEquals(test.Quantity, -100d);
        }
        public virtual void test_builder()
        {
            GenericSecurityPosition test = sut();

            assertEquals(test.Info, POSITION_INFO);
            assertEquals(test.Security, SECURITY);
            assertEquals(test.LongQuantity, LONG_QUANTITY);
            assertEquals(test.ShortQuantity, SHORT_QUANTITY);
            assertEquals(test.Quantity, QUANTITY);
        }
Exemplo n.º 7
0
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         GenericSecurityPosition other = (GenericSecurityPosition)obj;
         return(JodaBeanUtils.equal(info, other.info) && JodaBeanUtils.equal(security, other.security) && JodaBeanUtils.equal(longQuantity, other.longQuantity) && JodaBeanUtils.equal(shortQuantity, other.shortQuantity));
     }
     return(false);
 }
        //-------------------------------------------------------------------------
        public virtual void test_ofNet_noInfo()
        {
            GenericSecurityPosition test = GenericSecurityPosition.ofNet(SECURITY, QUANTITY);

            assertEquals(test.Info, PositionInfo.empty());
            assertEquals(test.Security, SECURITY);
            assertEquals(test.LongQuantity, QUANTITY);
            assertEquals(test.ShortQuantity, 0d);
            assertEquals(test.Quantity, QUANTITY);
            assertEquals(test.Product, SECURITY);
            assertEquals(test.SecurityId, SECURITY.SecurityId);
            assertEquals(test.Currency, SECURITY.Currency);
            assertEquals(test.withInfo(POSITION_INFO).Info, POSITION_INFO);
            assertEquals(test.withQuantity(129).Quantity, 129d, 0d);
            assertEquals(test.withQuantity(-129).Quantity, -129d, 0d);
        }
Exemplo n.º 9
0
 public GenericSecurityPosition withQuantity(double quantity)
 {
     return(GenericSecurityPosition.ofNet(info, security, quantity));
 }
Exemplo n.º 10
0
        //-------------------------------------------------------------------------
        public virtual void test_of()
        {
            GenericSecurity test = sut();

            assertEquals(test.Info, INFO);
            assertEquals(test.SecurityId, INFO.Id);
            assertEquals(test.Currency, INFO.PriceInfo.Currency);
            assertEquals(test.UnderlyingIds, ImmutableSet.of());
            assertEquals(test, GenericSecurity.of(INFO));
            assertEquals(test.createProduct(ReferenceData.empty()), test);
            assertEquals(test.createTrade(TradeInfo.empty(), 1, 2, ReferenceData.empty()), GenericSecurityTrade.of(TradeInfo.empty(), GenericSecurity.of(INFO), 1, 2));
            assertEquals(test.createPosition(PositionInfo.empty(), 1, ReferenceData.empty()), GenericSecurityPosition.ofNet(PositionInfo.empty(), GenericSecurity.of(INFO), 1));
            assertEquals(test.createPosition(PositionInfo.empty(), 1, 2, ReferenceData.empty()), GenericSecurityPosition.ofLongShort(PositionInfo.empty(), GenericSecurity.of(INFO), 1, 2));
        }
 internal static GenericSecurityPosition sut2()
 {
     return(GenericSecurityPosition.builder().info(PositionInfo.empty()).security(SECURITY2).longQuantity(LONG_QUANTITY2).shortQuantity(SHORT_QUANTITY2).build());
 }
 //-------------------------------------------------------------------------
 internal static GenericSecurityPosition sut()
 {
     return(GenericSecurityPosition.builder().info(POSITION_INFO).security(SECURITY).longQuantity(LONG_QUANTITY).shortQuantity(SHORT_QUANTITY).build());
 }
 public GenericSecurityPosition createPosition(PositionInfo positionInfo, double longQuantity, double shortQuantity, ReferenceData refData)
 {
     return(GenericSecurityPosition.ofLongShort(positionInfo, this, longQuantity, shortQuantity));
 }
 public GenericSecurityPosition createPosition(PositionInfo tradeInfo, double quantity, ReferenceData refData)
 {
     return(GenericSecurityPosition.ofNet(tradeInfo, this, quantity));
 }