Package com.opengamma.master.security

Examples of com.opengamma.master.security.SecurityMaster


public class SecurityFieldMappingTemplateGenerator extends AbstractTool<ToolContext> {
  private static final Logger s_logger = LoggerFactory.getLogger(SecurityFieldMappingTemplateGenerator.class);
  @Override
  protected void doRun() throws Exception {
    CSVWriter csvWriter = new CSVWriter(new FileWriter(getCommandLine().getArgs()[0]));
    SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    SecurityMetaDataRequest metaRequest = new SecurityMetaDataRequest();
    SecurityMetaDataResult metaData = securityMaster.metaData(metaRequest);
    for (String securityType : metaData.getSecurityTypes()) {
      s_logger.info("Processing security type " + securityType);
      SecuritySearchRequest searchRequest = new SecuritySearchRequest();
      searchRequest.setName("*");
      searchRequest.setSecurityType(securityType);
      searchRequest.setPagingRequest(PagingRequest.ONE);
      SecuritySearchResult search = securityMaster.search(searchRequest);
      s_logger.info("Search returned " + search.getPaging().getTotalItems() + " securities");
      dumpSecurityStructure(csvWriter, securityType, search.getFirstSecurity());
    }
    csvWriter.close();
  }
View Full Code Here


   * @param name the pattern to match securities
   * @param dryRun set to true to not write to the database
   */
  private void createSurfaces(String name, boolean dryRun) {
    ConfigMaster configMaster = getToolContext().getConfigMaster();
    SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    ReferenceDataProvider bbgRefData = getToolContext().getBloombergReferenceDataProvider();

    SecuritySearchRequest securityRequest = new SecuritySearchRequest();
    securityRequest.setName(name);
    securityRequest.setSortOrder(SecuritySearchSortOrder.NAME_ASC);
View Full Code Here

    s_logger.info("loading securities");
    AbstractTool<ToolContext> remoteServerTool = new AbstractTool<ToolContext>() {

      @Override
      protected void doRun() throws Exception {
        SecurityMaster remotesecurityMaster = getToolContext().getSecurityMaster();
        for (SecurityDocument securityDocument : SecuritySearchIterator.iterable(remotesecurityMaster, new SecuritySearchRequest())) {
          securityDocument.setUniqueId(null);
          demoSecurityMaster.add(securityDocument);
        }
      }
View Full Code Here

    return externalIds;
  }

  private void loadSecuritylData(final boolean write, final Set<ExternalId> externalIds) {
    BloombergBulkSecurityLoader bulkSecurityLoader = new BloombergBulkSecurityLoader(getToolContext().getBloombergReferenceDataProvider(), DefaultExchangeDataProvider.getInstance());
    SecurityMaster secMaster = getToolContext().getSecurityMaster();
    Set<ExternalIdBundle> externalIdBundles = new HashSet<>();
    for (ExternalId externalId : externalIds) {
      externalIdBundles.add(externalId.toBundle());
    }
    Map<ExternalIdBundle, ManageableSecurity> loadedSecurities = bulkSecurityLoader.loadSecurity(externalIdBundles);
View Full Code Here

  /** The counterparty */
  private static final String COUNTERPARTY = "Cpty";

  @Override
  public PortfolioNodeGenerator createPortfolioNodeGenerator(final int size) {
    final SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    final MySecurityGenerator<ManageableSecurity> firstGenerator = getSwapParityGenerator();
    final MySecurityGenerator<ManageableSecurity> secondGenerator = getSwaptionLongShortGenerator(securityMaster);
    final MySecurityGenerator<ManageableSecurity> thirdGenerator = getSwaptionConventionGenerator(securityMaster);
    final MySecurityGenerator<ManageableSecurity> fourthGenerator = getSwaptionParityGenerator(securityMaster);
    configure(firstGenerator);
View Full Code Here

    return securities;
  }

  @Override
  protected void doRun() {
    final SecurityMaster securities = getToolContext().getSecurityMaster();
    final PositionMaster positions = getToolContext().getPositionMaster();
    final PortfolioMaster portfolios = getToolContext().getPortfolioMaster();
    final ManageablePortfolio portfolio = new ManageablePortfolio("Tutorial 1");
    final ManageablePortfolioNode root = portfolio.getRootNode();
    final Random rnd = new Random();
    root.setName("Root");
    for (final Tutorial1Security security : loadSecurities()) {
      securities.add(new SecurityDocument(security.toRawSecurity()));
      final ManageablePosition position = new ManageablePosition(new BigDecimal(100 + rnd.nextInt(900)), security.getExternalIdBundle());
      root.addPosition(positions.add(new PositionDocument(position)));
    }
    portfolios.add(new PortfolioDocument(portfolio));
  }
View Full Code Here

  //-------------------------------------------------------------------------
  @Override
  public void init(ComponentRepository repo, LinkedHashMap<String, String> securityuration) {

    SecurityMaster master = new EHCachingSecurityMaster(getClassifier(),
                                                        getUnderlying(),
                                                        getCacheManager());

    // register
    ComponentInfo info = new ComponentInfo(SecurityMaster.class, getClassifier());
View Full Code Here

    final PositionGenerator positions = new SimplePositionGenerator<>(securities, getSecurityPersister(), getCounterPartyGenerator());
    return new LeafPortfolioNodeGenerator(new StaticNameGenerator("Swaptions"), positions, size);
  }

  private SwaptionSecurity[] createSwaptions(final int size) {
    final SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    final List<Currency> currencies = new ArrayList<>(REGIONS.keySet());
    final ZonedDateTime[] tradeDates = new ZonedDateTime[size];
    final Random rng = new Random(123);
    final ZonedDateTime date = DateUtils.previousWeekDay().atStartOfDay(ZoneOffset.UTC);
    Arrays.fill(tradeDates, date);
    final SwaptionSecurity[] swaptions = new SwaptionSecurity[size];
    for (int i = 0; i < size; i++) {
      final Currency currency = currencies.get(rng.nextInt(currencies.size()));
      final ExternalId region = REGIONS.get(currency);
      final ExternalId floatingRate = TICKERS.get(currency);
      final int swaptionYears = 1 + rng.nextInt(9);
      final ZonedDateTime swaptionExpiry = date.plusYears(swaptionYears);
      final int swapYears = 1 + rng.nextInt(28);
      final ZonedDateTime swapMaturity = swaptionExpiry.plusMonths(swapYears);
      final double amount = 100000 * (1 + rng.nextInt(30));
      final InterestRateNotional notional = new InterestRateNotional(currency, amount);
      final double rate = swapYears * rng.nextDouble() / 500;
      final Frequency frequency = currency.equals(Currency.USD) ? PeriodFrequency.QUARTERLY : PeriodFrequency.SEMI_ANNUAL;
      final SwapLeg fixedLeg = new FixedInterestRateLeg(DAY_COUNT, PeriodFrequency.SEMI_ANNUAL, region, BDC, notional, false, rate);
      final SwapLeg floatLeg = new FloatingInterestRateLeg(DAY_COUNT, frequency, region, BDC, notional, false, floatingRate, FloatingRateType.IBOR);
      final SwapLeg payLeg, receiveLeg;
      final String swapName, swaptionName;
      final boolean isLong = rng.nextBoolean();
      final boolean isCashSettled = rng.nextBoolean();
      final boolean payer;
      if (rng.nextBoolean()) {
        payLeg = fixedLeg;
        receiveLeg = floatLeg;
        swapName = swapYears + "Y pay " + currency + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
        swaptionName = (isLong ? "Long " : "Short ") + swaptionYears + "Y x " + swapYears + "Y pay " + currency + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
        payer = true;
      } else {
        payLeg = floatLeg;
        receiveLeg = fixedLeg;
        swapName = swapYears + "Y receive " + currency + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
        swaptionName = (isLong ? "Long " : "Short ") + swaptionYears + "Y x " + swapYears + "Y receive " + currency + " " + notional.getAmount() + " @ " + STRIKE_FORMATTER.format(rate);
        payer = false;
      }
      final SwapSecurity swap = new SwapSecurity(swaptionExpiry, swaptionExpiry.plusDays(2), swapMaturity, COUNTER_PARTY_OPT, payLeg, receiveLeg);
      swap.setName(swapName);
      final SecurityDocument toAddDoc = new SecurityDocument();
      toAddDoc.setSecurity(swap);
      securityMaster.add(toAddDoc);
      final ExternalId swapId = getSecurityPersister().storeSecurity(swap).iterator().next();
      final SwaptionSecurity swaption = new SwaptionSecurity(payer, swapId, isLong, new Expiry(swaptionExpiry), isCashSettled, currency);
      swaption.setName(swaptionName);
      swaptions[i] = swaption;
    }
View Full Code Here

   * Creates securities and adds them to the master.
   *
   * @return a collection of all securities that have been persisted, not null
   */
  protected Collection<EquitySecurity> createAndPersistEquitySecurities() {
    SecurityMaster secMaster = getToolContext().getSecurityMaster();
    Collection<EquitySecurity> securities = loadEquitySecurities();
    for (EquitySecurity security : securities) {
      SecurityDocument doc = new SecurityDocument(security);
      secMaster.add(doc);
    }
    return securities;
  }
View Full Code Here

      initYieldCurves(repo);
    }
  }

  protected void initSecurities(final ComponentRepository repo) {
    final SecurityMaster master = new InMemorySecurityMaster();
    final MasterFinancialSecuritySource source = new MasterFinancialSecuritySource(master);

    final ComponentInfo infoMaster = new ComponentInfo(SecurityMaster.class, "test");
    repo.registerComponent(infoMaster, master);
    repo.getRestComponents().publish(infoMaster, new DataSecurityMasterResource(master));
View Full Code Here

TOP

Related Classes of com.opengamma.master.security.SecurityMaster

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.