All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opengamma.sdk.margin.TradeCurveSensitivity Maven / Gradle / Ivy

There is a newer version: 3.6.4
Show newest version
/*
 * Copyright (C) 2018 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.sdk.margin;

import java.time.Period;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
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.PropertyDefinition;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.joda.beans.impl.direct.DirectPrivateBeanBuilder;

/**
 * The sensitivity of a trade in the portfolio to a single curve.
 */
@BeanDefinition(builderScope = "private", metaScope = "private", factoryName = "of")
public final class TradeCurveSensitivity implements ImmutableBean {

  /**
   * The name of the curve that the sensitivities relate to.
   */
  @PropertyDefinition(validate = "notNull")
  private final String curveName;
  /**
   * The currency of the sensitivities, as an ISO 4217 three letter currency code.
   * This is the currency of the sensitivities of the curve.
   */
  @PropertyDefinition(validate = "notNull")
  private final String currency;
  /**
   * The total sensitivity, calculated as the sum of all the tenor values.
   * This is expressed in the specified currency.
   */
  @PropertyDefinition
  private final double sensitivity;
  /**
   * The per-tenor sensitivity.
   * Values are expressed in the specified currency.
   */
  @PropertyDefinition(validate = "notNull")
  private final Map tenorSensitivity;

  //------------------------- AUTOGENERATED START -------------------------
  /**
   * The meta-bean for {@code TradeCurveSensitivity}.
   * @return the meta-bean, not null
   */
  public static MetaBean meta() {
    return TradeCurveSensitivity.Meta.INSTANCE;
  }

  static {
    MetaBean.register(TradeCurveSensitivity.Meta.INSTANCE);
  }

  /**
   * Obtains an instance.
   * @param curveName  the value of the property, not null
   * @param currency  the value of the property, not null
   * @param sensitivity  the value of the property
   * @param tenorSensitivity  the value of the property, not null
   * @return the instance
   */
  public static TradeCurveSensitivity of(
      String curveName,
      String currency,
      double sensitivity,
      Map tenorSensitivity) {
    return new TradeCurveSensitivity(
      curveName,
      currency,
      sensitivity,
      tenorSensitivity);
  }

  private TradeCurveSensitivity(
      String curveName,
      String currency,
      double sensitivity,
      Map tenorSensitivity) {
    JodaBeanUtils.notNull(curveName, "curveName");
    JodaBeanUtils.notNull(currency, "currency");
    JodaBeanUtils.notNull(tenorSensitivity, "tenorSensitivity");
    this.curveName = curveName;
    this.currency = currency;
    this.sensitivity = sensitivity;
    this.tenorSensitivity = Collections.unmodifiableMap(new HashMap<>(tenorSensitivity));
  }

  @Override
  public MetaBean metaBean() {
    return TradeCurveSensitivity.Meta.INSTANCE;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the name of the curve that the sensitivities relate to.
   * @return the value of the property, not null
   */
  public String getCurveName() {
    return curveName;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the currency of the sensitivities, as an ISO 4217 three letter currency code.
   * This is the currency of the sensitivities of the curve.
   * @return the value of the property, not null
   */
  public String getCurrency() {
    return currency;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the total sensitivity, calculated as the sum of all the tenor values.
   * This is expressed in the specified currency.
   * @return the value of the property
   */
  public double getSensitivity() {
    return sensitivity;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the per-tenor sensitivity.
   * Values are expressed in the specified currency.
   * @return the value of the property, not null
   */
  public Map getTenorSensitivity() {
    return tenorSensitivity;
  }

  //-----------------------------------------------------------------------
  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj != null && obj.getClass() == this.getClass()) {
      TradeCurveSensitivity other = (TradeCurveSensitivity) obj;
      return JodaBeanUtils.equal(curveName, other.curveName) &&
          JodaBeanUtils.equal(currency, other.currency) &&
          JodaBeanUtils.equal(sensitivity, other.sensitivity) &&
          JodaBeanUtils.equal(tenorSensitivity, other.tenorSensitivity);
    }
    return false;
  }

  @Override
  public int hashCode() {
    int hash = getClass().hashCode();
    hash = hash * 31 + JodaBeanUtils.hashCode(curveName);
    hash = hash * 31 + JodaBeanUtils.hashCode(currency);
    hash = hash * 31 + JodaBeanUtils.hashCode(sensitivity);
    hash = hash * 31 + JodaBeanUtils.hashCode(tenorSensitivity);
    return hash;
  }

  @Override
  public String toString() {
    StringBuilder buf = new StringBuilder(160);
    buf.append("TradeCurveSensitivity{");
    buf.append("curveName").append('=').append(curveName).append(',').append(' ');
    buf.append("currency").append('=').append(currency).append(',').append(' ');
    buf.append("sensitivity").append('=').append(sensitivity).append(',').append(' ');
    buf.append("tenorSensitivity").append('=').append(JodaBeanUtils.toString(tenorSensitivity));
    buf.append('}');
    return buf.toString();
  }

  //-----------------------------------------------------------------------
  /**
   * The meta-bean for {@code TradeCurveSensitivity}.
   */
  private 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 curveName} property.
     */
    private final MetaProperty curveName = DirectMetaProperty.ofImmutable(
        this, "curveName", TradeCurveSensitivity.class, String.class);
    /**
     * The meta-property for the {@code currency} property.
     */
    private final MetaProperty currency = DirectMetaProperty.ofImmutable(
        this, "currency", TradeCurveSensitivity.class, String.class);
    /**
     * The meta-property for the {@code sensitivity} property.
     */
    private final MetaProperty sensitivity = DirectMetaProperty.ofImmutable(
        this, "sensitivity", TradeCurveSensitivity.class, Double.TYPE);
    /**
     * The meta-property for the {@code tenorSensitivity} property.
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    private final MetaProperty> tenorSensitivity = DirectMetaProperty.ofImmutable(
        this, "tenorSensitivity", TradeCurveSensitivity.class, (Class) Map.class);
    /**
     * The meta-properties.
     */
    private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
        this, null,
        "curveName",
        "currency",
        "sensitivity",
        "tenorSensitivity");

    /**
     * Restricted constructor.
     */
    private Meta() {
    }

    @Override
    protected MetaProperty metaPropertyGet(String propertyName) {
      switch (propertyName.hashCode()) {
        case 771153946:  // curveName
          return curveName;
        case 575402001:  // currency
          return currency;
        case 564403871:  // sensitivity
          return sensitivity;
        case 334451647:  // tenorSensitivity
          return tenorSensitivity;
      }
      return super.metaPropertyGet(propertyName);
    }

    @Override
    public BeanBuilder builder() {
      return new TradeCurveSensitivity.Builder();
    }

    @Override
    public Class beanType() {
      return TradeCurveSensitivity.class;
    }

    @Override
    public Map> metaPropertyMap() {
      return metaPropertyMap$;
    }

    //-----------------------------------------------------------------------
    @Override
    protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
      switch (propertyName.hashCode()) {
        case 771153946:  // curveName
          return ((TradeCurveSensitivity) bean).getCurveName();
        case 575402001:  // currency
          return ((TradeCurveSensitivity) bean).getCurrency();
        case 564403871:  // sensitivity
          return ((TradeCurveSensitivity) bean).getSensitivity();
        case 334451647:  // tenorSensitivity
          return ((TradeCurveSensitivity) bean).getTenorSensitivity();
      }
      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 TradeCurveSensitivity}.
   */
  private static final class Builder extends DirectPrivateBeanBuilder {

    private String curveName;
    private String currency;
    private double sensitivity;
    private Map tenorSensitivity = Collections.emptyMap();

    /**
     * Restricted constructor.
     */
    private Builder() {
    }

    //-----------------------------------------------------------------------
    @Override
    public Object get(String propertyName) {
      switch (propertyName.hashCode()) {
        case 771153946:  // curveName
          return curveName;
        case 575402001:  // currency
          return currency;
        case 564403871:  // sensitivity
          return sensitivity;
        case 334451647:  // tenorSensitivity
          return tenorSensitivity;
        default:
          throw new NoSuchElementException("Unknown property: " + propertyName);
      }
    }

    @SuppressWarnings("unchecked")
    @Override
    public Builder set(String propertyName, Object newValue) {
      switch (propertyName.hashCode()) {
        case 771153946:  // curveName
          this.curveName = (String) newValue;
          break;
        case 575402001:  // currency
          this.currency = (String) newValue;
          break;
        case 564403871:  // sensitivity
          this.sensitivity = (Double) newValue;
          break;
        case 334451647:  // tenorSensitivity
          this.tenorSensitivity = (Map) newValue;
          break;
        default:
          throw new NoSuchElementException("Unknown property: " + propertyName);
      }
      return this;
    }

    @Override
    public TradeCurveSensitivity build() {
      return new TradeCurveSensitivity(
          curveName,
          currency,
          sensitivity,
          tenorSensitivity);
    }

    //-----------------------------------------------------------------------
    @Override
    public String toString() {
      StringBuilder buf = new StringBuilder(160);
      buf.append("TradeCurveSensitivity.Builder{");
      buf.append("curveName").append('=').append(JodaBeanUtils.toString(curveName)).append(',').append(' ');
      buf.append("currency").append('=').append(JodaBeanUtils.toString(currency)).append(',').append(' ');
      buf.append("sensitivity").append('=').append(JodaBeanUtils.toString(sensitivity)).append(',').append(' ');
      buf.append("tenorSensitivity").append('=').append(JodaBeanUtils.toString(tenorSensitivity));
      buf.append('}');
      return buf.toString();
    }

  }

  //-------------------------- AUTOGENERATED END --------------------------
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy