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

Add LegalEntityId #1762

Merged
merged 1 commit into from
Jul 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.google.common.collect.ImmutableSet;
import com.opengamma.strata.basics.ReferenceData;
import com.opengamma.strata.basics.Resolvable;
import com.opengamma.strata.basics.StandardId;
import com.opengamma.strata.basics.currency.Currency;
import com.opengamma.strata.calc.Measure;
import com.opengamma.strata.calc.runner.CalculationFunction;
Expand All @@ -27,6 +26,7 @@
import com.opengamma.strata.measure.Measures;
import com.opengamma.strata.measure.rate.RatesMarketDataLookup;
import com.opengamma.strata.measure.rate.RatesScenarioMarketData;
import com.opengamma.strata.product.LegalEntityId;
import com.opengamma.strata.product.SecuritizedProductPortfolioItem;
import com.opengamma.strata.product.SecurityId;
import com.opengamma.strata.product.bond.CapitalIndexedBond;
Expand Down Expand Up @@ -132,7 +132,7 @@ public FunctionRequirements requirements(
CapitalIndexedBond product = target.getProduct();
Currency currency = product.getCurrency();
SecurityId securityId = product.getSecurityId();
StandardId legalEntityId = product.getLegalEntityId();
LegalEntityId legalEntityId = product.getLegalEntityId();

// use lookup to build requirements
RatesMarketDataLookup ratesLookup = parameters.getParameter(RatesMarketDataLookup.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.opengamma.strata.basics.StandardId;
import com.opengamma.strata.basics.currency.Currency;
import com.opengamma.strata.calc.CalculationRules;
import com.opengamma.strata.calc.runner.CalculationParameter;
Expand All @@ -41,6 +40,7 @@
import com.opengamma.strata.market.curve.LegalEntityGroup;
import com.opengamma.strata.market.curve.RepoGroup;
import com.opengamma.strata.pricer.bond.LegalEntityDiscountingProvider;
import com.opengamma.strata.product.LegalEntityId;
import com.opengamma.strata.product.SecurityId;

/**
Expand All @@ -57,27 +57,35 @@ final class DefaultLegalEntityDiscountingMarketDataLookup
implements LegalEntityDiscountingMarketDataLookup, ImmutableBean, Serializable {

/**
* The groups used to find a repo curve.
* The groups used to find a repo curve by security.
* <p>
* This maps either the security ID or the legal entity ID to a group.
* This maps the security ID to a group.
* The group is used to find the curve in {@code repoCurves}.
*/
@PropertyDefinition(validate = "notNull")
private final ImmutableMap<StandardId, RepoGroup> repoCurveGroups;
private final ImmutableMap<SecurityId, RepoGroup> repoCurveSecurityGroups;
/**
* The groups used to find a repo curve by legal entity.
* <p>
* This maps the legal entity ID to a group.
* The group is used to find the curve in {@code repoCurves}.
*/
@PropertyDefinition(validate = "notNull")
private final ImmutableMap<LegalEntityId, RepoGroup> repoCurveGroups;
/**
* The repo curves, keyed by group and currency.
* The curve data, predicting the future, associated with each repo group and currency.
*/
@PropertyDefinition(validate = "notNull")
private final ImmutableMap<Pair<RepoGroup, Currency>, CurveId> repoCurves;
/**
* The groups used to find an issuer curve.
* The groups used to find an issuer curve by legal entity.
* <p>
* This maps the legal entity ID to a group.
* The group is used to find the curve in {@code issuerCurves}.
*/
@PropertyDefinition(validate = "notNull")
private final ImmutableMap<StandardId, LegalEntityGroup> issuerCurveGroups;
private final ImmutableMap<LegalEntityId, LegalEntityGroup> issuerCurveGroups;
/**
* The issuer curves, keyed by group and currency.
* The curve data, predicting the future, associated with each legal entity group and currency.
Expand All @@ -98,22 +106,24 @@ final class DefaultLegalEntityDiscountingMarketDataLookup
* The first part maps the issuer ID to a group, and the second part maps the
* group and currency to the identifier of the curve.
*
* @param repoCurveGroups the repo curve groups, mapping security or issuer ID to group
* @param repoCurveSecurityGroups the per security repo curve group overrides, mapping security ID to group
* @param repoCurveGroups the repo curve groups, mapping issuer ID to group
* @param repoCurveIds the repo curve identifiers, keyed by security ID or issuer ID and currency
* @param issuerCurveGroups the issuer curve groups, mapping issuer ID to group
* @param issuerCurveIds the issuer curves identifiers, keyed by issuer ID and currency
* @param obsSource the source of market data for quotes and other observable market data
* @return the rates lookup containing the specified curves
*/
public static <T extends NamedMarketDataId<Curve>> DefaultLegalEntityDiscountingMarketDataLookup of(
Map<StandardId, RepoGroup> repoCurveGroups,
Map<SecurityId, RepoGroup> repoCurveSecurityGroups,
Map<LegalEntityId, RepoGroup> repoCurveGroups,
Map<Pair<RepoGroup, Currency>, CurveId> repoCurveIds,
Map<StandardId, LegalEntityGroup> issuerCurveGroups,
Map<LegalEntityId, LegalEntityGroup> issuerCurveGroups,
Map<Pair<LegalEntityGroup, Currency>, CurveId> issuerCurveIds,
ObservableSource obsSource) {

return new DefaultLegalEntityDiscountingMarketDataLookup(
repoCurveGroups, repoCurveIds, issuerCurveGroups, issuerCurveIds, obsSource);
repoCurveSecurityGroups, repoCurveGroups, repoCurveIds, issuerCurveGroups, issuerCurveIds, obsSource);
}

/**
Expand All @@ -131,17 +141,18 @@ public static <T extends NamedMarketDataId<Curve>> DefaultLegalEntityDiscounting
* @return the rates lookup containing the specified curves
*/
public static DefaultLegalEntityDiscountingMarketDataLookup of(
Map<StandardId, RepoGroup> repoCurveGroups,
Map<LegalEntityId, RepoGroup> repoCurveGroups,
Map<Pair<RepoGroup, Currency>, CurveId> repoCurveIds,
ObservableSource obsSource) {

return new DefaultLegalEntityDiscountingMarketDataLookup(
repoCurveGroups, repoCurveIds, ImmutableMap.of(), ImmutableMap.of(), obsSource);
ImmutableMap.of(), repoCurveGroups, repoCurveIds, ImmutableMap.of(), ImmutableMap.of(), obsSource);
}

@ImmutableValidator
private void validate() {
Set<RepoGroup> uniqueRepoGroups = new HashSet<>(repoCurveGroups.values());
uniqueRepoGroups.addAll(repoCurveSecurityGroups.values());
Set<RepoGroup> uniqueRepoCurves = repoCurves.keySet().stream().map(p -> p.getFirst()).collect(toImmutableSet());
if (!uniqueRepoCurves.containsAll(uniqueRepoGroups)) {
throw new IllegalArgumentException(
Expand All @@ -159,9 +170,9 @@ private void validate() {

//-------------------------------------------------------------------------
@Override
public FunctionRequirements requirements(SecurityId securityId, StandardId issuerId, Currency currency) {
public FunctionRequirements requirements(SecurityId securityId, LegalEntityId issuerId, Currency currency) {
// repo
RepoGroup repoKey = repoCurveGroups.get(securityId.getStandardId());
RepoGroup repoKey = repoCurveSecurityGroups.get(securityId);
if (repoKey == null) {
repoKey = repoCurveGroups.get(issuerId);
}
Expand Down Expand Up @@ -194,7 +205,7 @@ public FunctionRequirements requirements(SecurityId securityId, StandardId issue
}

@Override
public FunctionRequirements requirements(StandardId issuerId, Currency currency) {
public FunctionRequirements requirements(LegalEntityId issuerId, Currency currency) {
// repo
RepoGroup repoKey = repoCurveGroups.get(issuerId);
if (repoKey == null) {
Expand Down Expand Up @@ -229,6 +240,7 @@ public LegalEntityDiscountingProvider discountingProvider(MarketData marketData)
DefaultLegalEntityDiscountingMarketDataLookup.class,
MethodHandles.lookup(),
new String[] {
"repoCurveSecurityGroups",
"repoCurveGroups",
"repoCurves",
"issuerCurveGroups",
Expand All @@ -238,6 +250,7 @@ public LegalEntityDiscountingProvider discountingProvider(MarketData marketData)
ImmutableMap.of(),
ImmutableMap.of(),
ImmutableMap.of(),
ImmutableMap.of(),
null);

/**
Expand All @@ -258,16 +271,19 @@ public static TypedMetaBean<DefaultLegalEntityDiscountingMarketDataLookup> meta(
private static final long serialVersionUID = 1L;

private DefaultLegalEntityDiscountingMarketDataLookup(
Map<StandardId, RepoGroup> repoCurveGroups,
Map<SecurityId, RepoGroup> repoCurveSecurityGroups,
Map<LegalEntityId, RepoGroup> repoCurveGroups,
Map<Pair<RepoGroup, Currency>, CurveId> repoCurves,
Map<StandardId, LegalEntityGroup> issuerCurveGroups,
Map<LegalEntityId, LegalEntityGroup> issuerCurveGroups,
Map<Pair<LegalEntityGroup, Currency>, CurveId> issuerCurves,
ObservableSource observableSource) {
JodaBeanUtils.notNull(repoCurveSecurityGroups, "repoCurveSecurityGroups");
JodaBeanUtils.notNull(repoCurveGroups, "repoCurveGroups");
JodaBeanUtils.notNull(repoCurves, "repoCurves");
JodaBeanUtils.notNull(issuerCurveGroups, "issuerCurveGroups");
JodaBeanUtils.notNull(issuerCurves, "issuerCurves");
JodaBeanUtils.notNull(observableSource, "observableSource");
this.repoCurveSecurityGroups = ImmutableMap.copyOf(repoCurveSecurityGroups);
this.repoCurveGroups = ImmutableMap.copyOf(repoCurveGroups);
this.repoCurves = ImmutableMap.copyOf(repoCurves);
this.issuerCurveGroups = ImmutableMap.copyOf(issuerCurveGroups);
Expand All @@ -283,13 +299,25 @@ public TypedMetaBean<DefaultLegalEntityDiscountingMarketDataLookup> metaBean() {

//-----------------------------------------------------------------------
/**
* Gets the groups used to find a repo curve.
* Gets the groups used to find a repo curve by security.
* <p>
* This maps either the security ID or the legal entity ID to a group.
* This maps the security ID to a group.
* The group is used to find the curve in {@code repoCurves}.
* @return the value of the property, not null
*/
public ImmutableMap<SecurityId, RepoGroup> getRepoCurveSecurityGroups() {
return repoCurveSecurityGroups;
}

//-----------------------------------------------------------------------
/**
* Gets the groups used to find a repo curve by legal entity.
* <p>
* This maps the legal entity ID to a group.
* The group is used to find the curve in {@code repoCurves}.
* @return the value of the property, not null
*/
public ImmutableMap<StandardId, RepoGroup> getRepoCurveGroups() {
public ImmutableMap<LegalEntityId, RepoGroup> getRepoCurveGroups() {
return repoCurveGroups;
}

Expand All @@ -305,13 +333,13 @@ public ImmutableMap<Pair<RepoGroup, Currency>, CurveId> getRepoCurves() {

//-----------------------------------------------------------------------
/**
* Gets the groups used to find an issuer curve.
* Gets the groups used to find an issuer curve by legal entity.
* <p>
* This maps the legal entity ID to a group.
* The group is used to find the curve in {@code issuerCurves}.
* @return the value of the property, not null
*/
public ImmutableMap<StandardId, LegalEntityGroup> getIssuerCurveGroups() {
public ImmutableMap<LegalEntityId, LegalEntityGroup> getIssuerCurveGroups() {
return issuerCurveGroups;
}

Expand Down Expand Up @@ -342,7 +370,8 @@ public boolean equals(Object obj) {
}
if (obj != null && obj.getClass() == this.getClass()) {
DefaultLegalEntityDiscountingMarketDataLookup other = (DefaultLegalEntityDiscountingMarketDataLookup) obj;
return JodaBeanUtils.equal(repoCurveGroups, other.repoCurveGroups) &&
return JodaBeanUtils.equal(repoCurveSecurityGroups, other.repoCurveSecurityGroups) &&
JodaBeanUtils.equal(repoCurveGroups, other.repoCurveGroups) &&
JodaBeanUtils.equal(repoCurves, other.repoCurves) &&
JodaBeanUtils.equal(issuerCurveGroups, other.issuerCurveGroups) &&
JodaBeanUtils.equal(issuerCurves, other.issuerCurves) &&
Expand All @@ -354,6 +383,7 @@ public boolean equals(Object obj) {
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(repoCurveSecurityGroups);
hash = hash * 31 + JodaBeanUtils.hashCode(repoCurveGroups);
hash = hash * 31 + JodaBeanUtils.hashCode(repoCurves);
hash = hash * 31 + JodaBeanUtils.hashCode(issuerCurveGroups);
Expand All @@ -364,8 +394,9 @@ public int hashCode() {

@Override
public String toString() {
StringBuilder buf = new StringBuilder(192);
StringBuilder buf = new StringBuilder(224);
buf.append("DefaultLegalEntityDiscountingMarketDataLookup{");
buf.append("repoCurveSecurityGroups").append('=').append(repoCurveSecurityGroups).append(',').append(' ');
buf.append("repoCurveGroups").append('=').append(repoCurveGroups).append(',').append(' ');
buf.append("repoCurves").append('=').append(repoCurves).append(',').append(' ');
buf.append("issuerCurveGroups").append('=').append(issuerCurveGroups).append(',').append(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.light.LightMetaBean;

import com.opengamma.strata.basics.StandardId;
import com.opengamma.strata.basics.currency.Currency;
import com.opengamma.strata.collect.ArgChecker;
import com.opengamma.strata.collect.tuple.Pair;
Expand All @@ -44,6 +43,7 @@
import com.opengamma.strata.pricer.bond.LegalEntityDiscountingProvider;
import com.opengamma.strata.pricer.bond.RepoCurveDiscountFactors;
import com.opengamma.strata.pricer.bond.RepoCurveZeroRateSensitivity;
import com.opengamma.strata.product.LegalEntityId;
import com.opengamma.strata.product.SecurityId;

/**
Expand Down Expand Up @@ -101,8 +101,8 @@ public LocalDate getValuationDate() {

//-------------------------------------------------------------------------
@Override
public RepoCurveDiscountFactors repoCurveDiscountFactors(SecurityId securityId, StandardId issuerId, Currency currency) {
RepoGroup repoGroup = lookup.getRepoCurveGroups().get(securityId.getStandardId());
public RepoCurveDiscountFactors repoCurveDiscountFactors(SecurityId securityId, LegalEntityId issuerId, Currency currency) {
RepoGroup repoGroup = lookup.getRepoCurveSecurityGroups().get(securityId);
if (repoGroup == null) {
repoGroup = lookup.getRepoCurveGroups().get(issuerId);
if (repoGroup == null) {
Expand All @@ -113,7 +113,7 @@ public RepoCurveDiscountFactors repoCurveDiscountFactors(SecurityId securityId,
}

@Override
public RepoCurveDiscountFactors repoCurveDiscountFactors(StandardId issuerId, Currency currency) {
public RepoCurveDiscountFactors repoCurveDiscountFactors(LegalEntityId issuerId, Currency currency) {
RepoGroup repoGroup = lookup.getRepoCurveGroups().get(issuerId);
if (repoGroup == null) {
throw new MarketDataNotFoundException("Unable to find repo curve mapping for ID: " + issuerId);
Expand All @@ -134,7 +134,7 @@ private RepoCurveDiscountFactors repoCurveDiscountFactors(RepoGroup repoGroup, C

//-------------------------------------------------------------------------
@Override
public IssuerCurveDiscountFactors issuerCurveDiscountFactors(StandardId issuerId, Currency currency) {
public IssuerCurveDiscountFactors issuerCurveDiscountFactors(LegalEntityId issuerId, Currency currency) {
LegalEntityGroup legalEntityGroup = lookup.getIssuerCurveGroups().get(issuerId);
if (legalEntityGroup == null) {
throw new MarketDataNotFoundException("Unable to find issuer curve mapping for ID: " + issuerId);
Expand Down Expand Up @@ -208,6 +208,7 @@ public ImmutableLegalEntityDiscountingProvider toImmutableLegalEntityDiscounting
// build result
return ImmutableLegalEntityDiscountingProvider.builder()
.valuationDate(getValuationDate())
.repoCurveSecurityGroups(lookup.getRepoCurveSecurityGroups())
.repoCurveGroups(lookup.getRepoCurveGroups())
.repoCurves(repoCurves)
.issuerCurveGroups(lookup.getIssuerCurveGroups())
Expand Down
Loading