Package com.opengamma.core.marketdatasnapshot.impl

Examples of com.opengamma.core.marketdatasnapshot.impl.ManageableMarketDataSnapshot


  @Override
  protected MarketDataSnapshotDocument insert(final MarketDataSnapshotDocument document) {
    ArgumentChecker.notNull(document.getSnapshot(), "document.snapshot");
    ArgumentChecker.notNull(document.getName(), "document.name");
   
    final ManageableMarketDataSnapshot marketDataSnaphshot = document.getSnapshot();
    final long docId = nextId("snp_snapshot_seq");
    final long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId);
    // set the uniqueId (needs to go in Fudge message)
    final UniqueId uniqueId = createUniqueId(docOid, docId);
    marketDataSnaphshot.setUniqueId(uniqueId);
    document.setUniqueId(uniqueId);
   
    // the arguments for inserting into the marketDataSnaphshot table
    FudgeMsgEnvelope env = FUDGE_CONTEXT.toFudgeMsg(marketDataSnaphshot);
    byte[] bytes = FUDGE_CONTEXT.toByteArray(env.getMessage());
View Full Code Here


      final Timestamp versionTo = rs.getTimestamp("VER_TO_INSTANT");
      final Timestamp correctionFrom = rs.getTimestamp("CORR_FROM_INSTANT");
      final Timestamp correctionTo = rs.getTimestamp("CORR_TO_INSTANT");
      UniqueId uniqueId = createUniqueId(docOid, docId);
     
      ManageableMarketDataSnapshot marketDataSnapshot;
      //PLAT-1378
      if (_includeData) {
        LobHandler lob = getDialect().getLobHandler();
        byte[] bytes = lob.getBlobAsBytes(rs, "DETAIL");
        marketDataSnapshot = FUDGE_CONTEXT.readObject(ManageableMarketDataSnapshot.class,
            new ByteArrayInputStream(bytes));
        if (!_includeData) {
          marketDataSnapshot.setGlobalValues(null);
          marketDataSnapshot.setYieldCurves(null);
        }
      } else {
        marketDataSnapshot = new ManageableMarketDataSnapshot();
        marketDataSnapshot.setName(rs.getString("NAME"));
        marketDataSnapshot.setUniqueId(uniqueId);
      }
      MarketDataSnapshotDocument doc = new MarketDataSnapshotDocument();
      doc.setUniqueId(uniqueId);
      doc.setVersionFromInstant(DbDateUtils.fromSqlTimestamp(versionFrom));
      doc.setVersionToInstant(DbDateUtils.fromSqlTimestampNullFarFuture(versionTo));
View Full Code Here

*/
@Test(groups = TestGroup.UNIT)
public class MarketDataSnapshotListResourceTest {

  private static MarketDataSnapshotDocument createSnapshot(String basisViewName, String name, UniqueId uid) {
    ManageableMarketDataSnapshot snapshot = new ManageableMarketDataSnapshot();
    snapshot.setBasisViewName(basisViewName);
    snapshot.setName(name);
    snapshot.setUniqueId(uid);
    return new MarketDataSnapshotDocument(snapshot);
  }
View Full Code Here

  }

  //-------------------------------------------------------------------------
  @Test
  public void test_example() throws Exception {
    final ManageableMarketDataSnapshot marketDataSnapshot = new ManageableMarketDataSnapshot();
    marketDataSnapshot.setName("Test");

    final HashMap<YieldCurveKey, YieldCurveSnapshot> yieldCurves = new HashMap<YieldCurveKey, YieldCurveSnapshot>();

    final ManageableUnstructuredMarketDataSnapshot globalValues = new ManageableUnstructuredMarketDataSnapshot();
    marketDataSnapshot.setGlobalValues(globalValues);
    marketDataSnapshot.setYieldCurves(yieldCurves);

    final MarketDataSnapshotDocument addDoc = new MarketDataSnapshotDocument(marketDataSnapshot);
    final MarketDataSnapshotDocument added = _snpMaster.add(addDoc);

    final MarketDataSnapshotDocument loaded = _snpMaster.get(added.getUniqueId());
View Full Code Here

  }

  //-------------------------------------------------------------------------
  @Test
  public void test_complex_example() throws Exception {
    final ManageableMarketDataSnapshot snapshot1 = new ManageableMarketDataSnapshot();
    snapshot1.setName("Test");
    final ManageableUnstructuredMarketDataSnapshot globalValues = new ManageableUnstructuredMarketDataSnapshot();
    snapshot1.setGlobalValues(globalValues);

    final HashMap<YieldCurveKey, YieldCurveSnapshot> yieldCurves = new HashMap<YieldCurveKey, YieldCurveSnapshot>();

    final ExternalIdBundle specA = ExternalId.of("XXX", "AAA").toBundle();
    final ExternalIdBundle specB = ExternalIdBundle.of(ExternalId.of("XXX", "B1"), ExternalId.of("XXX", "B2"));

    globalValues.putValue(specA, "X", new ValueSnapshot(Double.valueOf(12), null));
    globalValues.putValue(specA, "Y", new ValueSnapshot(Double.valueOf(1), null));
    globalValues.putValue(specA, "Z", new ValueSnapshot(null, null));
    globalValues.putValue(specB, "X", new ValueSnapshot(Double.valueOf(12), Double.valueOf(11)));

    final ManageableYieldCurveSnapshot manageableYieldCurveSnapshot = new ManageableYieldCurveSnapshot();
    manageableYieldCurveSnapshot.setValuationTime(Instant.now());
    manageableYieldCurveSnapshot.setValues(globalValues);
    yieldCurves.put(new YieldCurveKey(Currency.GBP, "Default"), manageableYieldCurveSnapshot);

    snapshot1.setYieldCurves(yieldCurves);

    final HashMap<Pair<Tenor, Tenor>, ValueSnapshot> strikes = new HashMap<Pair<Tenor, Tenor>, ValueSnapshot>();
    strikes.put(Pair.of(Tenor.DAY, Tenor.WORKING_WEEK), new ValueSnapshot(12.0, 12.0));
    strikes.put(Pair.of(Tenor.DAY, Tenor.WORKING_WEEK), null);

    final HashMap<VolatilityCubeKey, VolatilityCubeSnapshot> volCubes = new HashMap<VolatilityCubeKey, VolatilityCubeSnapshot>();
    final ManageableVolatilityCubeSnapshot volCube = new ManageableVolatilityCubeSnapshot();

    volCube.setOtherValues(globalValues);
    volCube.setValues(new HashMap<VolatilityPoint, ValueSnapshot>());
    volCube.setStrikes(strikes);
    volCube.getValues().put(new VolatilityPoint(Tenor.DAY, Tenor.YEAR, -1), new ValueSnapshot(null, null));

    volCubes.put(new VolatilityCubeKey(Currency.USD, "Default"), volCube);
    snapshot1.setVolatilityCubes(volCubes);

    MarketDataSnapshotDocument doc1 = new MarketDataSnapshotDocument(snapshot1);
    doc1 = _snpMaster.add(doc1);

    final ManageableMarketDataSnapshot snapshot2 = new ManageableMarketDataSnapshot();
    snapshot2.setName("SS 2");
    MarketDataSnapshotDocument doc2 = new MarketDataSnapshotDocument(snapshot2);
    doc2 = _snpMaster.add(doc2);

    final MarketDataSnapshotDocument doc1Loaded = _snpMaster.get(doc1.getUniqueId());
    assertEquivalent(doc1, doc1Loaded);
View Full Code Here

    assertEquals(1, result3.getDocuments().size());
    assertEquals(doc1.getUniqueId(), result3.getFirstDocument().getUniqueId());
  }

  private void assertEquivalent(final MarketDataSnapshotDocument added, final MarketDataSnapshotDocument loaded) {
    final ManageableMarketDataSnapshot addedSnapshot = added.getSnapshot();
    final ManageableMarketDataSnapshot loadedSnapshot = loaded.getSnapshot();
    assertEquivalent(addedSnapshot, loadedSnapshot);
  }
View Full Code Here

    final Map<YieldCurveKey, YieldCurveSnapshot> yieldCurves = _yieldCurveSnapper.getValues(results, graphs, viewCycle);
    final Map<CurveKey, CurveSnapshot> curves = _curveSnapper.getValues(results, graphs, viewCycle);
    final Map<VolatilitySurfaceKey, VolatilitySurfaceSnapshot> surfaces = _volatilitySurfaceSnapper.getValues(results, graphs, viewCycle);
    final Map<VolatilityCubeKey, VolatilityCubeSnapshot> cubes = _volatilityCubeSnapper.getValues(results, graphs, viewCycle);

    final ManageableMarketDataSnapshot ret = new ManageableMarketDataSnapshot();
    ret.setBasisViewName(basisViewName);
    ret.setGlobalValues(globalValues);
    ret.setYieldCurves(yieldCurves);
    ret.setCurves(curves);
    ret.setVolatilitySurfaces(surfaces);
    ret.setVolatilityCubes(cubes);
    return ret;
  }
View Full Code Here

    String snapshotName = "Sameday spread";
    MarketDataSnapshotSearchRequest marketDataSnapshotSearchRequest = new MarketDataSnapshotSearchRequest();
    marketDataSnapshotSearchRequest.setName(snapshotName);
    MarketDataSnapshotSearchResult marketDataSnapshotSearchResult = getToolContext().getMarketDataSnapshotMaster().search(marketDataSnapshotSearchRequest);
    ManageableMarketDataSnapshot snapshot = marketDataSnapshotSearchResult.getFirstSnapshot();

    PortfolioSearchRequest portfolioSearchRequest = new PortfolioSearchRequest();
    portfolioSearchRequest.setName("CDSOpts");
    //portfolioSearchRequest.setName("Standard CDS Portfolio");
    List<ManageablePortfolio> portfolios = getToolContext().getPortfolioMaster().search(portfolioSearchRequest).getPortfolios();
    for (ManageablePortfolio portfolio : portfolios) {

      List<ObjectId> positionIds = portfolio.getRootNode().getPositionIds();
      List<UniqueId> positionUids = newArrayList();
      for (ObjectId positionId : positionIds) {
        positionUids.add(positionId.atLatestVersion());
      }
      Map<UniqueId, PositionDocument> positions = getToolContext().getPositionMaster().get(positionUids);

      // Ticker, RedCode, Currency, Term, Seniority, RestructuringClause
      final List<ExternalId> cdsArgs = newArrayList();


      final SecureRandom random = new SecureRandom();
      for (PositionDocument positionDocument : positions.values()) {
        ManageablePosition position = positionDocument.getValue();

        ManageableSecurityLink link = position.getSecurityLink();
        SecuritySearchRequest ssr = new SecuritySearchRequest();
        ssr.addExternalIds(link.getExternalIds());
        SecuritySearchResult securitySearchResult = getToolContext().getSecurityMaster().search(ssr);
        Security security = securitySearchResult.getFirstSecurity();
        //Security security = position.getSecurity();
        if (security != null && security instanceof CreditDefaultSwapOptionSecurity) {
          CreditDefaultSwapOptionSecurity cdsOption = (CreditDefaultSwapOptionSecurity) security;
          CreditDefaultSwapSecurity cds = (CreditDefaultSwapSecurity) this.getToolContext().getSecuritySource().getSingle(
              cdsOption.getUnderlyingId().toBundle());

          String curveDefinitionID = "SAMEDAY_" + cds.getReferenceEntity().getValue() + "_" + cds.getNotional().getCurrency() + "_" +
              cds.getDebtSeniority().toString() + "_" + cds.getRestructuringClause();

          ConfigSearchRequest<CurveDefinition> curveDefinitionConfigSearchRequest = new ConfigSearchRequest<CurveDefinition>(CurveDefinition.class);
          curveDefinitionConfigSearchRequest.setName(curveDefinitionID);
          CurveDefinition curveDefinition = getToolContext().getConfigMaster().search(
              curveDefinitionConfigSearchRequest).getFirstValue().getValue();
        /*final CurveDefinition curveDefinition = configSource.getSingle(CurveDefinition.class,
                                                                       curveName,
                                                                       VersionCorrection.LATEST);

        if (curveDefinition == null) {
          throw new OpenGammaRuntimeException("No curve definition for " + curveName);
        }

        //Map<Tenor, CurveNode> curveNodesByTenors = new HashMap<Tenor, CurveNode>();
        //for (CurveNode curveNode : curveDefinition.getNodes()) {
        //  curveNodesByTenors.put(curveNode.getResolvedMaturity(), curveNode);
        //}
        Map<Tenor, CurveNode> curveNodesByTenors = functional(curveDefinition.getNodes()).groupBy(new Function1<CurveNode, Tenor>() {
          @Override
          public Tenor execute(CurveNode curveNode) {
            return curveNode.getResolvedMaturity();
          }
        });*/

          ZonedDateTime start = cds.getStartDate();
          ZonedDateTime maturity = cds.getMaturityDate();
          Period period = Period.between(start.toLocalDate(), maturity.toLocalDate());
          Tenor tenor = Tenor.of(period);


          final CurveNodeIdMapper curveNodeIdMapper = configSource.getSingle(CurveNodeIdMapper.class,
                                                                             curveDefinitionID,
                                                                             VersionCorrection.LATEST);


          try {
            tenor = Tenor.of(Period.ofYears(5));
            ExternalId timeSeriesId = curveNodeIdMapper.getCreditSpreadNodeId(null /* magic null - ask Elaine */, tenor);

           
            Object strikeObj = snapshot.getGlobalValues().getValue(timeSeriesId, "PX_LAST").getMarketValue();
            if ((strikeObj instanceof Double)) {
              cdsOption.setStrike((Double) strikeObj);
            } else {
              throw new OpenGammaRuntimeException(format("Double expected for strike but '%s' found instead.", String.valueOf(strikeObj)));
            }
View Full Code Here

   * @param snapshotMaster The snapshot master to which to write the snapshot
   */

  public MasterSnapshotWriter(MarketDataSnapshotMaster snapshotMaster) {
    _snapshotMaster = snapshotMaster;
    _snapshot = new ManageableMarketDataSnapshot();
  }
View Full Code Here

      endWithError("Multiple view definitions resolved when searching for string '%s': %s", viewDefinitionName, viewDefinitions);
    }
    ConfigItem<?> value = Iterables.get(viewDefinitions, 0).getValue();
    StructuredMarketDataSnapshot snapshot = makeSnapshot(marketDataSnapshotter, viewProcessor, (ViewDefinition) value.getValue(), viewExecutionOptions);
   
    final ManageableMarketDataSnapshot manageableMarketDataSnapshot = new ManageableMarketDataSnapshot(snapshot);
    manageableMarketDataSnapshot.setName(snapshot.getBasisViewName() + "/" + valuationInstant);
    marketDataSnapshotMaster.add(new MarketDataSnapshotDocument(manageableMarketDataSnapshot));
  }
View Full Code Here

TOP

Related Classes of com.opengamma.core.marketdatasnapshot.impl.ManageableMarketDataSnapshot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.