![JAR search and dependency download from the Maven repository](/logo.png)
com.opengamma.strata.product.swaption.SwaptionTrade Maven / Gradle / Ivy
Show all versions of strata-product Show documentation
/*
* Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.product.swaption;
import java.io.Serializable;
import java.util.Map;
import java.util.NoSuchElementException;
import org.joda.beans.Bean;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.ImmutableDefaults;
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.direct.DirectFieldsBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import com.opengamma.strata.basics.ReferenceData;
import com.opengamma.strata.basics.currency.AdjustablePayment;
import com.opengamma.strata.basics.currency.Payment;
import com.opengamma.strata.product.PortfolioItemInfo;
import com.opengamma.strata.product.PortfolioItemSummary;
import com.opengamma.strata.product.ProductTrade;
import com.opengamma.strata.product.ProductType;
import com.opengamma.strata.product.ResolvableTrade;
import com.opengamma.strata.product.TradeInfo;
import com.opengamma.strata.product.common.SummarizerUtils;
/**
* A trade in an option on an underlying swap.
*
* An Over-The-Counter (OTC) trade in a {@link Swaption}.
*
* A swaption is a financial instrument that provides the option to enter into a swap at a future date.
* The option is European, exercised only on the exercise date.
*/
@BeanDefinition
public final class SwaptionTrade
implements ProductTrade, ResolvableTrade, ImmutableBean, Serializable {
/**
* The additional trade information, defaulted to an empty instance.
*
* This allows additional information to be attached to the trade.
*/
@PropertyDefinition(validate = "notNull", overrideGet = true)
private final TradeInfo info;
/**
* The swaption product that was agreed when the trade occurred.
*
* The product captures the contracted financial details of the trade.
*/
@PropertyDefinition(validate = "notNull", overrideGet = true)
private final Swaption product;
/**
* The premium of the swaption.
*
* The premium sign should be compatible with the product Long/Short flag.
* This means that the premium is negative for long and positive for short.
*/
@PropertyDefinition(validate = "notNull")
private final AdjustablePayment premium;
//-------------------------------------------------------------------------
/**
* Obtains an instance of a Swaption trade with a fixed payment.
*
* @param info the trade info
* @param product the product
* @param premium the premium
* @return the trade
*/
public static SwaptionTrade of(TradeInfo info, Swaption product, Payment premium) {
return new SwaptionTrade(info, product, AdjustablePayment.of(premium));
}
/**
* Obtains an instance of a Swaption trade with an adjustable payment.
*
* @param info the trade info
* @param product the product
* @param premium the premium
* @return the trade
*/
public static SwaptionTrade of(TradeInfo info, Swaption product, AdjustablePayment premium) {
return new SwaptionTrade(info, product, premium);
}
@ImmutableDefaults
private static void applyDefaults(Builder builder) {
builder.info = TradeInfo.empty();
}
//-------------------------------------------------------------------------
@Override
public SwaptionTrade withInfo(PortfolioItemInfo info) {
return new SwaptionTrade(TradeInfo.from(info), product, premium);
}
//-------------------------------------------------------------------------
@Override
public PortfolioItemSummary summarize() {
// Long 5Y USD 2mm Rec USD-LIBOR-6M / Pay 1% : 21Jan18
String swapDesc = product.getUnderlying().summaryDescription();
swapDesc = swapDesc.contains(":") ? swapDesc.substring(0, swapDesc.lastIndexOf(':')).trim() : swapDesc;
StringBuilder buf = new StringBuilder(96);
buf.append(product.getLongShort());
buf.append(' ');
buf.append(swapDesc);
buf.append(" : ");
buf.append(SummarizerUtils.date(product.getExpiryDate().getUnadjusted()));
return SummarizerUtils.summary(this, ProductType.SWAPTION, buf.toString(), product.getCurrency());
}
@Override
public ResolvedSwaptionTrade resolve(ReferenceData refData) {
return ResolvedSwaptionTrade.builder()
.info(info)
.product(product.resolve(refData))
.premium(premium.resolve(refData))
.build();
}
//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code SwaptionTrade}.
* @return the meta-bean, not null
*/
public static SwaptionTrade.Meta meta() {
return SwaptionTrade.Meta.INSTANCE;
}
static {
MetaBean.register(SwaptionTrade.Meta.INSTANCE);
}
/**
* The serialization version id.
*/
private static final long serialVersionUID = 1L;
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static SwaptionTrade.Builder builder() {
return new SwaptionTrade.Builder();
}
private SwaptionTrade(
TradeInfo info,
Swaption product,
AdjustablePayment premium) {
JodaBeanUtils.notNull(info, "info");
JodaBeanUtils.notNull(product, "product");
JodaBeanUtils.notNull(premium, "premium");
this.info = info;
this.product = product;
this.premium = premium;
}
@Override
public SwaptionTrade.Meta metaBean() {
return SwaptionTrade.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the additional trade information, defaulted to an empty instance.
*
* This allows additional information to be attached to the trade.
* @return the value of the property, not null
*/
@Override
public TradeInfo getInfo() {
return info;
}
//-----------------------------------------------------------------------
/**
* Gets the swaption product that was agreed when the trade occurred.
*
* The product captures the contracted financial details of the trade.
* @return the value of the property, not null
*/
@Override
public Swaption getProduct() {
return product;
}
//-----------------------------------------------------------------------
/**
* Gets the premium of the swaption.
*
* The premium sign should be compatible with the product Long/Short flag.
* This means that the premium is negative for long and positive for short.
* @return the value of the property, not null
*/
public AdjustablePayment getPremium() {
return premium;
}
//-----------------------------------------------------------------------
/**
* Returns a builder that allows this bean to be mutated.
* @return the mutable builder, not null
*/
public Builder toBuilder() {
return new Builder(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
SwaptionTrade other = (SwaptionTrade) obj;
return JodaBeanUtils.equal(info, other.info) &&
JodaBeanUtils.equal(product, other.product) &&
JodaBeanUtils.equal(premium, other.premium);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(info);
hash = hash * 31 + JodaBeanUtils.hashCode(product);
hash = hash * 31 + JodaBeanUtils.hashCode(premium);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("SwaptionTrade{");
buf.append("info").append('=').append(JodaBeanUtils.toString(info)).append(',').append(' ');
buf.append("product").append('=').append(JodaBeanUtils.toString(product)).append(',').append(' ');
buf.append("premium").append('=').append(JodaBeanUtils.toString(premium));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code SwaptionTrade}.
*/
public static final class Meta extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code info} property.
*/
private final MetaProperty info = DirectMetaProperty.ofImmutable(
this, "info", SwaptionTrade.class, TradeInfo.class);
/**
* The meta-property for the {@code product} property.
*/
private final MetaProperty product = DirectMetaProperty.ofImmutable(
this, "product", SwaptionTrade.class, Swaption.class);
/**
* The meta-property for the {@code premium} property.
*/
private final MetaProperty premium = DirectMetaProperty.ofImmutable(
this, "premium", SwaptionTrade.class, AdjustablePayment.class);
/**
* The meta-properties.
*/
private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"info",
"product",
"premium");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 3237038: // info
return info;
case -309474065: // product
return product;
case -318452137: // premium
return premium;
}
return super.metaPropertyGet(propertyName);
}
@Override
public SwaptionTrade.Builder builder() {
return new SwaptionTrade.Builder();
}
@Override
public Class extends SwaptionTrade> beanType() {
return SwaptionTrade.class;
}
@Override
public Map> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code info} property.
* @return the meta-property, not null
*/
public MetaProperty info() {
return info;
}
/**
* The meta-property for the {@code product} property.
* @return the meta-property, not null
*/
public MetaProperty product() {
return product;
}
/**
* The meta-property for the {@code premium} property.
* @return the meta-property, not null
*/
public MetaProperty premium() {
return premium;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 3237038: // info
return ((SwaptionTrade) bean).getInfo();
case -309474065: // product
return ((SwaptionTrade) bean).getProduct();
case -318452137: // premium
return ((SwaptionTrade) bean).getPremium();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
metaProperty(propertyName);
if (quiet) {
return;
}
throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
}
}
//-----------------------------------------------------------------------
/**
* The bean-builder for {@code SwaptionTrade}.
*/
public static final class Builder extends DirectFieldsBeanBuilder {
private TradeInfo info;
private Swaption product;
private AdjustablePayment premium;
/**
* Restricted constructor.
*/
private Builder() {
applyDefaults(this);
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
private Builder(SwaptionTrade beanToCopy) {
this.info = beanToCopy.getInfo();
this.product = beanToCopy.getProduct();
this.premium = beanToCopy.getPremium();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 3237038: // info
return info;
case -309474065: // product
return product;
case -318452137: // premium
return premium;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 3237038: // info
this.info = (TradeInfo) newValue;
break;
case -309474065: // product
this.product = (Swaption) newValue;
break;
case -318452137: // premium
this.premium = (AdjustablePayment) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public Builder set(MetaProperty> property, Object value) {
super.set(property, value);
return this;
}
@Override
public SwaptionTrade build() {
return new SwaptionTrade(
info,
product,
premium);
}
//-----------------------------------------------------------------------
/**
* Sets the additional trade information, defaulted to an empty instance.
*
* This allows additional information to be attached to the trade.
* @param info the new value, not null
* @return this, for chaining, not null
*/
public Builder info(TradeInfo info) {
JodaBeanUtils.notNull(info, "info");
this.info = info;
return this;
}
/**
* Sets the swaption product that was agreed when the trade occurred.
*
* The product captures the contracted financial details of the trade.
* @param product the new value, not null
* @return this, for chaining, not null
*/
public Builder product(Swaption product) {
JodaBeanUtils.notNull(product, "product");
this.product = product;
return this;
}
/**
* Sets the premium of the swaption.
*
* The premium sign should be compatible with the product Long/Short flag.
* This means that the premium is negative for long and positive for short.
* @param premium the new value, not null
* @return this, for chaining, not null
*/
public Builder premium(AdjustablePayment premium) {
JodaBeanUtils.notNull(premium, "premium");
this.premium = premium;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("SwaptionTrade.Builder{");
buf.append("info").append('=').append(JodaBeanUtils.toString(info)).append(',').append(' ');
buf.append("product").append('=').append(JodaBeanUtils.toString(product)).append(',').append(' ');
buf.append("premium").append('=').append(JodaBeanUtils.toString(premium));
buf.append('}');
return buf.toString();
}
}
//-------------------------- AUTOGENERATED END --------------------------
}