Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security quantity trade #1667

Merged
merged 2 commits into from Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -35,7 +35,7 @@
*/
@BeanDefinition(constructorScope = "package")
public final class GenericSecurityTrade
implements Trade, SecurityQuantity, ImmutableBean, Serializable {
implements SecurityQuantityTrade, ImmutableBean, Serializable {

/**
* The additional trade information, defaulted to an empty instance.
Expand All @@ -62,7 +62,7 @@ public final class GenericSecurityTrade
* <p>
* This is the price agreed when the trade occurred.
*/
@PropertyDefinition
@PropertyDefinition(overrideGet = true)
private final double price;

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -97,18 +97,21 @@ public PortfolioItemSummary summarize() {
return SummarizerUtils.summary(this, ProductType.SECURITY, description, getCurrency());
}

/**
* Gets the security identifier.
* <p>
* This identifier uniquely identifies the security within the system.
*
* @return the security identifier
*/
@Override
public SecurityId getSecurityId() {
return security.getSecurityId();
}

@Override
public GenericSecurityTrade withQuantity(double quantity) {
return new GenericSecurityTrade(info, security, quantity, price);
}

@Override
public GenericSecurityTrade withPrice(double price) {
return new GenericSecurityTrade(info, security, quantity, price);
}

/**
* Gets the currency of the trade.
* <p>
Expand Down Expand Up @@ -211,6 +214,7 @@ public double getQuantity() {
* This is the price agreed when the trade occurred.
* @return the value of the property
*/
@Override
public double getPrice() {
return price;
}
Expand Down
Expand Up @@ -24,7 +24,7 @@
* Implementations of this interface must be immutable beans.
*/
public interface SecuritizedProductTrade
extends ProductTrade, SecurityQuantity {
extends ProductTrade, SecurityQuantityTrade {

/**
* Gets the product of the security that was traded.
Expand All @@ -45,13 +45,22 @@ public interface SecuritizedProductTrade
public abstract double getQuantity();

/**
* Gets the price that was traded.
* <p>
* This is the unit price agreed when the trade occurred.
* Returns an instance with the specified quantity.
*
* @return the price
* @param quantity the new quantity
* @return the instance with the specified quantity
*/
public abstract double getPrice();
@Override
public abstract SecuritizedProductTrade withQuantity(double quantity);

/**
* Returns an instance with the specified price.
*
* @param price the new price
* @return the instance with the specified price
*/
@Override
public abstract SecuritizedProductTrade withPrice(double price);

//-------------------------------------------------------------------------
/**
Expand Down
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2018 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.product;

/**
* A trade that is based on security, quantity and price.
* <p>
* If the trade is directly based on a securitized product, the trade type is {@link SecuritizedProductTrade}.
* If not, the financial instrument involved in the trade is represented in alternative form, e.g., {@link Security}.
* See individual implementations for more details.
*/
public interface SecurityQuantityTrade
extends Trade, SecurityQuantity {

/**
* Gets the price that was traded.
* <p>
* This is the unit price agreed when the trade occurred.
*
* @return the price
*/
public abstract double getPrice();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, a withPrice() would make sense


/**
* Returns an instance with the specified quantity.
*
* @param quantity the new quantity
* @return the instance with the specified quantity
*/
public abstract SecurityQuantityTrade withQuantity(double quantity);

/**
* Returns an instance with the specified price.
*
* @param price the new price
* @return the instance with the specified price
*/
public abstract SecurityQuantityTrade withPrice(double price);

}
Expand Up @@ -38,7 +38,7 @@
*/
@BeanDefinition(constructorScope = "package")
public final class SecurityTrade
implements Trade, SecurityQuantity, ImmutableBean, Serializable {
implements SecurityQuantityTrade, ImmutableBean, Serializable {

/**
* The additional trade information, defaulted to an empty instance.
Expand Down Expand Up @@ -66,7 +66,7 @@ public final class SecurityTrade
* <p>
* This is the price agreed when the trade occurred.
*/
@PropertyDefinition
@PropertyDefinition(overrideGet = true)
private final double price;

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -101,6 +101,16 @@ public PortfolioItemSummary summarize() {
return SummarizerUtils.summary(this, ProductType.SECURITY, description);
}

@Override
public SecurityTrade withQuantity(double quantity) {
return new SecurityTrade(info, securityId, quantity, price);
}

@Override
public SecurityTrade withPrice(double price) {
return new SecurityTrade(info, securityId, quantity, price);
}

/**
* Resolves the security identifier using the specified reference data.
* <p>
Expand Down Expand Up @@ -207,6 +217,7 @@ public double getQuantity() {
* This is the price agreed when the trade occurred.
* @return the value of the property
*/
@Override
public double getPrice() {
return price;
}
Expand Down
Expand Up @@ -97,6 +97,16 @@ public ResolvedBondFutureOptionTrade resolve(ReferenceData refData) {
return new ResolvedBondFutureOptionTrade(info, resolved, quantity, price);
}

@Override
public BondFutureOptionTrade withQuantity(double quantity) {
return new BondFutureOptionTrade(info, product, quantity, price);
}

@Override
public BondFutureOptionTrade withPrice(double price) {
return new BondFutureOptionTrade(info, product, quantity, price);
}

//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code BondFutureOptionTrade}.
Expand Down
Expand Up @@ -96,6 +96,16 @@ public ResolvedBondFutureTrade resolve(ReferenceData refData) {
return new ResolvedBondFutureTrade(info, resolved, quantity, price);
}

@Override
public BondFutureTrade withQuantity(double quantity) {
return new BondFutureTrade(info, product, quantity, price);
}

@Override
public BondFutureTrade withPrice(double price) {
return new BondFutureTrade(info, product, quantity, price);
}

//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code BondFutureTrade}.
Expand Down
Expand Up @@ -137,6 +137,16 @@ public ResolvedCapitalIndexedBondTrade resolve(ReferenceData refData) {
.build();
}

@Override
public CapitalIndexedBondTrade withQuantity(double quantity) {
return new CapitalIndexedBondTrade(info, product, quantity, price);
}

@Override
public CapitalIndexedBondTrade withPrice(double price) {
return new CapitalIndexedBondTrade(info, product, quantity, price);
}

// calculates the settlement date from the trade date if necessary
private TradeInfo calculateSettlementDate(ReferenceData refData) {
if (info.getSettlementDate().isPresent()) {
Expand Down
Expand Up @@ -99,6 +99,16 @@ public ResolvedFixedCouponBondTrade resolve(ReferenceData refData) {
return new ResolvedFixedCouponBondTrade(completedInfo, resolved, quantity, price);
}

@Override
public FixedCouponBondTrade withQuantity(double quantity) {
return new FixedCouponBondTrade(info, product, quantity, price);
}

@Override
public FixedCouponBondTrade withPrice(double price) {
return new FixedCouponBondTrade(info, product, quantity, price);
}

// calculates the settlement date from the trade date if necessary
private TradeInfo calculateSettlementDate(ReferenceData refData) {
if (info.getSettlementDate().isPresent()) {
Expand Down
Expand Up @@ -103,6 +103,16 @@ public ResolvedDsfTrade resolve(ReferenceData refData) {
return new ResolvedDsfTrade(info, resolved, quantity, price);
}

@Override
public DsfTrade withQuantity(double quantity) {
return new DsfTrade(info, product, quantity, price);
}

@Override
public DsfTrade withPrice(double price) {
return new DsfTrade(info, product, quantity, price);
}

//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code DsfTrade}.
Expand Down
Expand Up @@ -26,8 +26,7 @@
import com.opengamma.strata.product.PortfolioItemSummary;
import com.opengamma.strata.product.ProductType;
import com.opengamma.strata.product.SecurityId;
import com.opengamma.strata.product.SecurityQuantity;
import com.opengamma.strata.product.Trade;
import com.opengamma.strata.product.SecurityQuantityTrade;
import com.opengamma.strata.product.TradeInfo;
import com.opengamma.strata.product.common.SummarizerUtils;

Expand All @@ -38,7 +37,7 @@
*/
@BeanDefinition
public final class EtdFutureTrade
implements Trade, SecurityQuantity, ImmutableBean, Serializable {
implements SecurityQuantityTrade, ImmutableBean, Serializable {

/**
* The additional trade information, defaulted to an empty instance.
Expand All @@ -65,7 +64,7 @@ public final class EtdFutureTrade
* <p>
* This is the price agreed when the trade occurred.
*/
@PropertyDefinition
@PropertyDefinition(overrideGet = true)
private final double price;

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -102,18 +101,21 @@ public PortfolioItemSummary summarize() {
return SummarizerUtils.summary(this, ProductType.ETD_FUTURE, description, getCurrency());
}

/**
* Gets the security identifier.
* <p>
* This identifier uniquely identifies the security within the system.
*
* @return the security identifier
*/
@Override
public SecurityId getSecurityId() {
return security.getSecurityId();
}

@Override
public EtdFutureTrade withQuantity(double quantity) {
return new EtdFutureTrade(info, security, quantity, price);
}

@Override
public EtdFutureTrade withPrice(double price) {
return new EtdFutureTrade(info, security, quantity, price);
}

/**
* Gets the currency of the trade.
* <p>
Expand Down Expand Up @@ -209,6 +211,7 @@ public double getQuantity() {
* This is the price agreed when the trade occurred.
* @return the value of the property
*/
@Override
public double getPrice() {
return price;
}
Expand Down
Expand Up @@ -26,8 +26,7 @@
import com.opengamma.strata.product.PortfolioItemSummary;
import com.opengamma.strata.product.ProductType;
import com.opengamma.strata.product.SecurityId;
import com.opengamma.strata.product.SecurityQuantity;
import com.opengamma.strata.product.Trade;
import com.opengamma.strata.product.SecurityQuantityTrade;
import com.opengamma.strata.product.TradeInfo;
import com.opengamma.strata.product.common.SummarizerUtils;

Expand All @@ -38,7 +37,7 @@
*/
@BeanDefinition
public final class EtdOptionTrade
implements Trade, SecurityQuantity, ImmutableBean, Serializable {
implements SecurityQuantityTrade, ImmutableBean, Serializable {

/**
* The additional trade information, defaulted to an empty instance.
Expand All @@ -65,7 +64,7 @@ public final class EtdOptionTrade
* <p>
* This is the price agreed when the trade occurred.
*/
@PropertyDefinition
@PropertyDefinition(overrideGet = true)
private final double price;

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -102,18 +101,21 @@ public PortfolioItemSummary summarize() {
return SummarizerUtils.summary(this, ProductType.ETD_OPTION, description, getCurrency());
}

/**
* Gets the security identifier.
* <p>
* This identifier uniquely identifies the security within the system.
*
* @return the security identifier
*/
@Override
public SecurityId getSecurityId() {
return security.getSecurityId();
}

@Override
public EtdOptionTrade withQuantity(double quantity) {
return new EtdOptionTrade(info, security, quantity, price);
}

@Override
public EtdOptionTrade withPrice(double price) {
return new EtdOptionTrade(info, security, quantity, price);
}

/**
* Gets the currency of the trade.
* <p>
Expand Down Expand Up @@ -209,6 +211,7 @@ public double getQuantity() {
* This is the price agreed when the trade occurred.
* @return the value of the property
*/
@Override
public double getPrice() {
return price;
}
Expand Down