/** * Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.strata.product.fx; import java.io.Serializable; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import org.joda.beans.Bean; import org.joda.beans.BeanDefinition; import org.joda.beans.ImmutableBean; import org.joda.beans.ImmutableDefaults; import org.joda.beans.JodaBeanUtils; import org.joda.beans.MetaProperty; import org.joda.beans.Property; import org.joda.beans.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.product.ProductTrade; import com.opengamma.strata.product.ResolvableTrade; import com.opengamma.strata.product.TradeInfo; /** * A trade in a Non-Deliverable Forward (NDF). * <p> * An Over-The-Counter (OTC) trade in an {@link FxNdf}. * <p> * An NDF is a financial instrument that returns the difference between a fixed FX rate * agreed at the inception of the trade and the FX rate at maturity. * It is primarily used to handle FX requirements for currencies that have settlement restrictions. * For example, the forward may be between USD and CNY (Chinese Yuan). */ @BeanDefinition public final class FxNdfTrade implements ProductTrade, ResolvableTrade<ResolvedFxNdfTrade>, ImmutableBean, Serializable { /** * The additional trade information, defaulted to an empty instance. * <p> * This allows additional information to be attached to the trade. */ @PropertyDefinition(overrideGet = true) private final TradeInfo info; /** * The product that was agreed when the trade occurred. * <p> * The product captures the contracted financial details of the trade. */ @PropertyDefinition(validate = "notNull", overrideGet = true) private final FxNdf product; //------------------------------------------------------------------------- /** * Obtains an instance of a Non-Deliverable Forward (NDF) trade. * * @param info the trade info * @param product the product * @return the trade */ public static FxNdfTrade of(TradeInfo info, FxNdf product) { return new FxNdfTrade(info, product); } @ImmutableDefaults private static void applyDefaults(Builder builder) { builder.info = TradeInfo.empty(); } //------------------------------------------------------------------------- @Override public ResolvedFxNdfTrade resolve(ReferenceData refData) { return ResolvedFxNdfTrade.of(info, product.resolve(refData)); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code FxNdfTrade}. * @return the meta-bean, not null */ public static FxNdfTrade.Meta meta() { return FxNdfTrade.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(FxNdfTrade.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 FxNdfTrade.Builder builder() { return new FxNdfTrade.Builder(); } private FxNdfTrade( TradeInfo info, FxNdf product) { JodaBeanUtils.notNull(product, "product"); this.info = info; this.product = product; } @Override public FxNdfTrade.Meta metaBean() { return FxNdfTrade.Meta.INSTANCE; } @Override public <R> Property<R> property(String propertyName) { return metaBean().<R>metaProperty(propertyName).createProperty(this); } @Override public Set<String> propertyNames() { return metaBean().metaPropertyMap().keySet(); } //----------------------------------------------------------------------- /** * Gets the additional trade information, defaulted to an empty instance. * <p> * This allows additional information to be attached to the trade. * @return the value of the property */ @Override public TradeInfo getInfo() { return info; } //----------------------------------------------------------------------- /** * Gets the product that was agreed when the trade occurred. * <p> * The product captures the contracted financial details of the trade. * @return the value of the property, not null */ @Override public FxNdf getProduct() { return product; } //----------------------------------------------------------------------- /** * 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()) { FxNdfTrade other = (FxNdfTrade) obj; return JodaBeanUtils.equal(info, other.info) && JodaBeanUtils.equal(product, other.product); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(info); hash = hash * 31 + JodaBeanUtils.hashCode(product); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("FxNdfTrade{"); buf.append("info").append('=').append(info).append(',').append(' '); buf.append("product").append('=').append(JodaBeanUtils.toString(product)); buf.append('}'); return buf.toString(); } //----------------------------------------------------------------------- /** * The meta-bean for {@code FxNdfTrade}. */ 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<TradeInfo> info = DirectMetaProperty.ofImmutable( this, "info", FxNdfTrade.class, TradeInfo.class); /** * The meta-property for the {@code product} property. */ private final MetaProperty<FxNdf> product = DirectMetaProperty.ofImmutable( this, "product", FxNdfTrade.class, FxNdf.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "info", "product"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 3237038: // info return info; case -309474065: // product return product; } return super.metaPropertyGet(propertyName); } @Override public FxNdfTrade.Builder builder() { return new FxNdfTrade.Builder(); } @Override public Class<? extends FxNdfTrade> beanType() { return FxNdfTrade.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code info} property. * @return the meta-property, not null */ public MetaProperty<TradeInfo> info() { return info; } /** * The meta-property for the {@code product} property. * @return the meta-property, not null */ public MetaProperty<FxNdf> product() { return product; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3237038: // info return ((FxNdfTrade) bean).getInfo(); case -309474065: // product return ((FxNdfTrade) bean).getProduct(); } 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 FxNdfTrade}. */ public static final class Builder extends DirectFieldsBeanBuilder<FxNdfTrade> { private TradeInfo info; private FxNdf product; /** * Restricted constructor. */ private Builder() { applyDefaults(this); } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(FxNdfTrade beanToCopy) { this.info = beanToCopy.getInfo(); this.product = beanToCopy.getProduct(); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case 3237038: // info return info; case -309474065: // product return product; 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 = (FxNdf) 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 Builder setString(String propertyName, String value) { setString(meta().metaProperty(propertyName), value); return this; } @Override public Builder setString(MetaProperty<?> property, String value) { super.setString(property, value); return this; } @Override public Builder setAll(Map<String, ? extends Object> propertyValueMap) { super.setAll(propertyValueMap); return this; } @Override public FxNdfTrade build() { return new FxNdfTrade( info, product); } //----------------------------------------------------------------------- /** * Sets the additional trade information, defaulted to an empty instance. * <p> * This allows additional information to be attached to the trade. * @param info the new value * @return this, for chaining, not null */ public Builder info(TradeInfo info) { this.info = info; return this; } /** * Sets the product that was agreed when the trade occurred. * <p> * 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(FxNdf product) { JodaBeanUtils.notNull(product, "product"); this.product = product; return this; } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("FxNdfTrade.Builder{"); buf.append("info").append('=').append(JodaBeanUtils.toString(info)).append(',').append(' '); buf.append("product").append('=').append(JodaBeanUtils.toString(product)); buf.append('}'); return buf.toString(); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }