コード例 #1
0
  @Override
  public String classifyPosition(final Position position) {
    final Security security = resolveSecurity(position);
    if (security instanceof CreditDefaultSwapOptionSecurity) {
      final CreditDefaultSwapOptionSecurity cdsOption = (CreditDefaultSwapOptionSecurity) security;
      final ExternalId underlyingId = cdsOption.getUnderlyingId();
      final Security underlying = _securitySource.getSingle(underlyingId.toBundle());
      final String redCode =
          ((CreditDefaultSwapSecurity) underlying).getReferenceEntity().getValue();
      final Organization organisation = _organizationSource.getOrganizationByRedCode(redCode);
      return organisation.getObligor().getObligorShortName();

    } else if (security instanceof CreditDefaultSwapIndexSecurity) {
      final CreditDefaultSwapIndexSecurity cdsIndex = (CreditDefaultSwapIndexSecurity) security;
      final CreditDefaultSwapIndexDefinitionSecurity definition =
          (CreditDefaultSwapIndexDefinitionSecurity)
              _securitySource.getSingle(ExternalIdBundle.of(cdsIndex.getReferenceEntity()));
      return definition.getName();
    } else if (security instanceof CreditDefaultSwapSecurity) {
      final AbstractCreditDefaultSwapSecurity cds = (AbstractCreditDefaultSwapSecurity) security;
      final String redCode = cds.getReferenceEntity().getValue();
      final Organization organisation = _organizationSource.getOrganizationByRedCode(redCode);
      if (organisation != null) {
        return organisation.getObligor().getObligorShortName();
      } else {
        return redCode;
      }
    }

    return NOT_APPLICABLE;
  }
コード例 #2
0
 @Override
 public Collection<Security> get(ExternalIdBundle bundle, VersionCorrection versionCorrection) {
   ArgumentChecker.notNull(bundle, "bundle");
   // best implementation is to return first matching result
   for (SecuritySource delegateSource : _delegator.getDelegates().values()) {
     Collection<Security> result = delegateSource.get(bundle, versionCorrection);
     if (!result.isEmpty()) {
       return result;
     }
   }
   return _delegator.getDefaultDelegate().get(bundle, versionCorrection);
 }
コード例 #3
0
 @Override
 public Security getSingle(ExternalIdBundle bundle) {
   ArgumentChecker.notNull(bundle, "bundle");
   // best implementation is to return first matching result
   for (SecuritySource delegateSource : _delegator.getDelegates().values()) {
     Security result = delegateSource.getSingle(bundle);
     if (result != null) {
       return result;
     }
   }
   return _delegator.getDefaultDelegate().getSingle(bundle);
 }
コード例 #4
0
 @Override
 public Security getSingle(ExternalIdBundle bundle, VersionCorrection versionCorrection) {
   ArgumentChecker.notNull(bundle, "bundle");
   ArgumentChecker.notNull(versionCorrection, "versionCorrection");
   for (SecuritySource delegateSource : _delegator.getDelegates().values()) {
     Security result = delegateSource.getSingle(bundle, versionCorrection);
     if (result != null) {
       return result;
     }
   }
   return _delegator.getDefaultDelegate().getSingle(bundle, versionCorrection);
 }
コード例 #5
0
 /**
  * Creates an instance specifying the default delegate.
  *
  * @param defaultSource the source to use when no scheme matches, not null
  * @param schemePrefixToSourceMap the map of sources by scheme to switch on, not null
  */
 public DelegatingSecuritySource(
     SecuritySource defaultSource, Map<String, SecuritySource> schemePrefixToSourceMap) {
   _delegator =
       new UniqueIdSchemeDelegator<SecuritySource>(defaultSource, schemePrefixToSourceMap);
   // REVIEW jonathan 2011-08-03 -- this assumes that the delegating source lasts for the lifetime
   // of the engine as we
   // never detach from the underlying change managers.
   AggregatingChangeManager changeManager = new AggregatingChangeManager();
   changeManager.addChangeManager(defaultSource.changeManager());
   for (SecuritySource source : schemePrefixToSourceMap.values()) {
     changeManager.addChangeManager(source.changeManager());
   }
   _changeManager = changeManager;
 }
コード例 #6
0
 @Override
 public List<ExternalId> visitIRFutureOptionSecurity(final IRFutureOptionSecurity security) {
   final FutureSecurity underlyingSecurity =
       (FutureSecurity)
           _securitySource.getSingle(ExternalIdBundle.of(security.getUnderlyingId()));
   return getContractType(underlyingSecurity);
 }
 public static ValueRequirement getValueRequirement(
     SecuritySource secMaster, final UnderlyingType underlying, final Security security) {
   if (security instanceof EquityOptionSecurity) {
     final EquityOptionSecurity option = (EquityOptionSecurity) security;
     switch (underlying) {
       case SPOT_PRICE:
         Security optionUnderlying =
             secMaster.getSecurity(ExternalIdBundle.of(option.getUnderlyingId()));
         return new ValueRequirement(
             MarketDataRequirementNames.MARKET_VALUE,
             ComputationTargetType.SECURITY,
             optionUnderlying.getUniqueId());
       case SPOT_VOLATILITY:
         throw new NotImplementedException(
             "Don't know how to get spot volatility for " + option.getUniqueId());
       case IMPLIED_VOLATILITY:
         throw new NotImplementedException(
             "Don't know how to get implied volatility for " + option.getUniqueId());
       case INTEREST_RATE:
         return new ValueRequirement(
             ValueRequirementNames.YIELD_CURVE,
             ComputationTargetType.PRIMITIVE,
             option.getUniqueId());
       case COST_OF_CARRY:
         throw new NotImplementedException(
             "Don't know how to get cost of carry for " + option.getUniqueId());
       default:
         throw new NotImplementedException(
             "Don't know how to get ValueRequirement for " + underlying);
     }
   }
   throw new NotImplementedException(
       "Can only get ValueRequirements for options (was " + security + ")");
 }
コード例 #8
0
 /**
  * Resolves the security using a security source.
  *
  * @param source the source to use to resolve, not null
  * @param versionCorrection the version-correction, not null
  * @return the resolved security, not null
  * @throws DataNotFoundException if the security could not be resolved
  * @throws RuntimeException if an error occurs while resolving
  */
 public Security resolve(SecuritySource source, VersionCorrection versionCorrection) {
   ObjectId objectId = getObjectId();
   if (objectId != null) {
     Security target = source.getSecurity(objectId, versionCorrection);
     setTarget(target);
     return target;
   }
   ExternalIdBundle bundle = getExternalId();
   if (bundle.size() > 0) {
     Security target = source.getSecurity(bundle, versionCorrection);
     if (target != null) {
       setTarget(target);
       return target;
     }
   }
   throw new DataNotFoundException("Unable to resolve security: " + getBestName());
 }
コード例 #9
0
 @Override
 public List<ExternalId> visitCreditDefaultSwapOptionSecurity(
     final CreditDefaultSwapOptionSecurity security) {
   final CreditDefaultSwapSecurity underlyingCDS =
       (CreditDefaultSwapSecurity)
           _securitySource.getSingle(
               ExternalIdBundle.of(security.getUnderlyingId())); // TODO version
   final ExternalId regionId = underlyingCDS.getRegionId();
   final String securityType = security.getSecurityType();
   return Arrays.asList(
       ExternalId.of(SECURITY_IDENTIFIER, securityType + SEPARATOR + regionId.getValue()));
 }
コード例 #10
0
 public static List<FactorExposureData> decodeFactorExposureData(
     SecuritySource secSource, RawSecurity rawSecurity) {
   FudgeMsgEnvelope msg =
       OpenGammaFudgeContext.getInstance().deserialize(rawSecurity.getRawData());
   SecurityEntryData securityEntryData =
       OpenGammaFudgeContext.getInstance().fromFudgeMsg(SecurityEntryData.class, msg.getMessage());
   RawSecurity underlyingRawSecurity =
       (RawSecurity) secSource.getSingle(securityEntryData.getFactorSetId().toBundle());
   if (underlyingRawSecurity != null) {
     FudgeMsgEnvelope factorIdMsg =
         OpenGammaFudgeContext.getInstance().deserialize(underlyingRawSecurity.getRawData());
     @SuppressWarnings("unchecked")
     List<FactorExposureData> factorExposureDataList =
         OpenGammaFudgeContext.getInstance().fromFudgeMsg(List.class, factorIdMsg.getMessage());
     return factorExposureDataList;
   } else {
     throw new OpenGammaRuntimeException(
         "Couldn't find factor list security " + securityEntryData.getFactorSetId());
   }
 }
コード例 #11
0
 @Override
 public List<ExternalId> visitSwaptionSecurity(final SwaptionSecurity security) {
   final List<ExternalId> result = new ArrayList<>();
   final SwapSecurity underlyingSwap =
       (SwapSecurity)
           _securitySource.getSingle(
               ExternalIdBundle.of(security.getUnderlyingId())); // TODO version
   final SwapLeg payLeg = underlyingSwap.getPayLeg();
   final SwapLeg receiveLeg = underlyingSwap.getReceiveLeg();
   final String securityType = security.getSecurityType();
   if (payLeg.getRegionId().equals(receiveLeg.getRegionId())) {
     return Arrays.asList(
         ExternalId.of(SECURITY_IDENTIFIER, securityType + "_" + payLeg.getRegionId().getValue()));
   }
   result.add(
       ExternalId.of(SECURITY_IDENTIFIER, securityType + "_" + payLeg.getRegionId().getValue()));
   result.add(
       ExternalId.of(
           SECURITY_IDENTIFIER, securityType + "_" + receiveLeg.getRegionId().getValue()));
   return result;
 }
コード例 #12
0
 /**
  * Creates an instance specifying the default delegate.
  *
  * @param defaultSource the source to use when no scheme matches, not null
  */
 public DelegatingSecuritySource(SecuritySource defaultSource) {
   _delegator = new UniqueIdSchemeDelegator<SecuritySource>(defaultSource);
   _changeManager = defaultSource.changeManager();
 }
コード例 #13
0
 public void testGetSecurity_byExternalIdBundleVersionCorrection() {
   final SecuritySource underlying = Mockito.mock(SecuritySource.class);
   final SecuritySource coalescing = new CoalescingSecuritySource(underlying);
   coalescing.get(ExternalIdBundle.EMPTY, VersionCorrection.LATEST);
   Mockito.verify(underlying).get(ExternalIdBundle.EMPTY, VersionCorrection.LATEST);
 }
コード例 #14
0
 public void testGetSecurities_byExternalIdBundle() {
   final SecuritySource underlying = Mockito.mock(SecuritySource.class);
   final SecuritySource coalescing = new CoalescingSecuritySource(underlying);
   coalescing.get(ExternalIdBundle.EMPTY);
   Mockito.verify(underlying).get(ExternalIdBundle.EMPTY);
 }
コード例 #15
0
 public void testGetSecurity_byObjectId() {
   final SecuritySource underlying = Mockito.mock(SecuritySource.class);
   final SecuritySource coalescing = new CoalescingSecuritySource(underlying);
   coalescing.get(ObjectId.of("Test", "Test"), VersionCorrection.LATEST);
   Mockito.verify(underlying).get(ObjectId.of("Test", "Test"), VersionCorrection.LATEST);
 }