com.opengamma.sdk.margin.TradeCurveSensitivity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-margin Show documentation
Show all versions of sdk-margin Show documentation
OpenGamma SDK - Provides access to the Margin service
/*
* 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