Package com.opengamma

Examples of com.opengamma.OpenGammaRuntimeException


    final ReferenceDataProvider referenceDataProvider = getToolContext().getBloombergReferenceDataProvider();
    if (idBundle.getExternalId(ExternalSchemes.BLOOMBERG_BUID) == null && idBundle.getExternalId(ExternalSchemes.BLOOMBERG_TICKER) != null) {
      //For some reason loading some series by TICKER fails, but BUID works
      final BiMap<String, ExternalIdBundle> map = BloombergDataUtils.convertToBloombergBuidKeys(Collections.singleton(idBundle), referenceDataProvider);
      if (map.size() != 1) {
        throw new OpenGammaRuntimeException("Failed to get buid");
      }
      for (final String key : map.keySet()) {
        final String buid = referenceDataProvider.getReferenceDataValue(key, BloombergConstants.FIELD_ID_BBG_UNIQUE);
        idBundle = idBundle.withExternalId(ExternalSchemes.bloombergBuidSecurityId(buid));
      }
    }
    final ExternalIdBundle searchBundle = idBundle.withoutScheme(ExternalSchemes.ISIN); // For things which move country, e.g. ISIN(VALE5 BZ Equity) == ISIN(RIODF US Equity)
    final Map<ExternalId, UniqueId> timeSeries = getToolContext().getHistoricalTimeSeriesLoader()
        .loadTimeSeries(searchBundle.getExternalIds(), "UNKNOWN", "PX_LAST", LocalDate.now().minusYears(1), null);
    if (timeSeries.size() != 1) {
      throw new OpenGammaRuntimeException("Failed to load time series " + idBundle + " " + timeSeries);
    }
    for (final UniqueId uid : timeSeries.values()) {
      return getToolContext().getHistoricalTimeSeriesMaster().get(uid);
    }
    throw new OpenGammaRuntimeException("Unexpected state");
  }
View Full Code Here


    throw new OpenGammaRuntimeException("Unexpected state");
  }

  private HistoricalTimeSeries updateTimeSeries(final HistoricalTimeSeries timeSeries) {
    if (!getToolContext().getHistoricalTimeSeriesLoader().updateTimeSeries(timeSeries.getUniqueId())) {
      throw new OpenGammaRuntimeException("Failed to update time series " + timeSeries);
    }
    //Force a cache miss on the source
    final HistoricalTimeSeriesInfoDocument newUid = getToolContext().getHistoricalTimeSeriesMaster().get(timeSeries.getUniqueId().toLatest());
    return getToolContext().getHistoricalTimeSeriesSource().getHistoricalTimeSeries(newUid.getUniqueId());
  }
View Full Code Here

  }

  private ManageableSecurity getOrLoadEquity(final ExternalId ticker) {
    final ManageableSecurity underlyingSecurity = getOrLoadSecurity(ticker);
    if (!EquitySecurity.SECURITY_TYPE.equals(underlyingSecurity.getSecurityType())) {
      throw new OpenGammaRuntimeException("Underlying is not an equity");
    }
    return underlyingSecurity;
  }
View Full Code Here

    final ExternalIdBundle tickerBundle = ExternalIdBundle.of(ticker);
    final Collection<ExternalIdBundle> bundles = Collections.singleton(tickerBundle);
    final Map<ExternalIdBundle, UniqueId> loaded = getToolContext().getSecurityLoader().loadSecurities(bundles);
    final UniqueId loadedSec = loaded.get(tickerBundle);
    if (loadedSec == null) {
      throw new OpenGammaRuntimeException("Failed to load security for " + ticker);
    }
    return getToolContext().getSecurityMaster().get(loadedSec).getSecurity();
  }
View Full Code Here

        final PortfolioDocument document = new PortfolioDocument(portfolio);
        document.setUniqueId(previousId);
        portfolioMaster.update(document);
        break;
      default:
        throw new OpenGammaRuntimeException("Multiple portfolios matching " + req);
    }
  }
View Full Code Here

  public UserExpression parse(final String expression) {
    try {
      final ExprParser parser = new ExprParser(new CommonTokenStream(new ExprLexer(new ANTLRReaderStream(new StringReader(expression))))) {
        @Override
        public void reportError(final RecognitionException e) {
          throw new OpenGammaRuntimeException(e.getMessage());
        }
      };
      final ExprParser.root_return root = parser.root();
      return build(((Tree) root.getTree()).getChild(0));
    } catch (Throwable e) {
View Full Code Here

    final IborIndexConvention indexConvention;
    if (convention instanceof IborIndexConvention) {
      indexConvention = (IborIndexConvention) convention;
    } else {
      if (convention == null) {
        throw new OpenGammaRuntimeException("Convention with id " + fraNode.getConvention() + " was null");
      }
      throw new OpenGammaRuntimeException("Could not handle underlying convention of type " + convention.getClass());
    }
    final Currency currency = indexConvention.getCurrency();
    final Calendar fixingCalendar = CalendarUtils.getCalendar(_regionSource,
                                                              _holidaySource,
                                                              indexConvention.getFixingCalendar());
View Full Code Here

  @Override
  public FinancialSecurity visitSwapNode(final SwapNode swapNode) {
    final Convention payLegConvention = _conventionSource.getConvention(swapNode.getPayLegConvention());
    if (payLegConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + swapNode.getPayLegConvention() + " was null");
    }
    final Convention receiveLegConvention = _conventionSource.getConvention(swapNode.getReceiveLegConvention());
    if (receiveLegConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + swapNode.getPayLegConvention() + " was null");
    }
    final Pair<? extends InterestRateLeg, Triple<ZonedDateTime, ZonedDateTime, ZonedDateTime>> payLeg;
    final Pair<? extends InterestRateLeg, Triple<ZonedDateTime, ZonedDateTime, ZonedDateTime>> receiveLeg;
    final boolean isFloatFloat = ((payLegConvention instanceof VanillaIborLegConvention) || (payLegConvention instanceof OISLegConvention))
        && ((receiveLegConvention instanceof VanillaIborLegConvention) || (receiveLegConvention instanceof OISLegConvention));
    if (payLegConvention instanceof SwapFixedLegConvention) {
      payLeg = getFixedLeg((SwapFixedLegConvention) payLegConvention, swapNode, true);
    } else if (payLegConvention instanceof VanillaIborLegConvention) {
      payLeg = getIborLeg(_identifier, (VanillaIborLegConvention) payLegConvention, swapNode, true, false);
    } else if (payLegConvention instanceof OISLegConvention) {
      payLeg = getOISLeg(_identifier, (OISLegConvention) payLegConvention, swapNode, true, false);
    } else {
      throw new OpenGammaRuntimeException("Cannot handle convention type " + payLegConvention.getClass());
    }
    if (receiveLegConvention instanceof SwapFixedLegConvention) {
      receiveLeg = getFixedLeg((SwapFixedLegConvention) receiveLegConvention, swapNode, false);
    } else if (receiveLegConvention instanceof VanillaIborLegConvention) {
      receiveLeg = getIborLeg(_identifier,
                              (VanillaIborLegConvention) receiveLegConvention,
                              swapNode,
                              false,
                              isFloatFloat);
    } else if (receiveLegConvention instanceof OISLegConvention) {
      receiveLeg = getOISLeg(_identifier, (OISLegConvention) receiveLegConvention, swapNode, false, isFloatFloat);
    } else {
      throw new OpenGammaRuntimeException("Cannot handle convention type " + receiveLegConvention.getClass());
    }

    if (!payLeg.getSecond().getFirst().equals(receiveLeg.getSecond().getFirst())) {
      throw new OpenGammaRuntimeException(
          "Both, pay and receive legs should resolve equal start dates, but instead there were: payleg(" + payLeg.getSecond().getFirst() + "), receiveLeg(" + receiveLeg.getSecond().getFirst() + ")");
    }
    if (!payLeg.getSecond().getSecond().equals(receiveLeg.getSecond().getSecond())) {
      throw new OpenGammaRuntimeException(
          "Both, pay and receive legs should resolve equal effective dates, but instead there were: payleg(" + payLeg.getSecond().getSecond() + "), " +
              "receiveLeg(" + receiveLeg.getSecond().getSecond() + ")");
    }
    if (!payLeg.getSecond().getThird().equals(receiveLeg.getSecond().getThird())) {
      throw new OpenGammaRuntimeException(
          "Both, pay and receive legs should resolve equal maturity dates, but instead there were: payleg(" + payLeg.getSecond().getThird() + "), " +
              "receiveLeg(" + receiveLeg.getSecond().getThird() + ")");
    }
    return new SwapSecurity(payLeg.getSecond().getFirst(),
                            payLeg.getSecond().getSecond(),
View Full Code Here

                                                                                                                  final boolean isPayer,
                                                                                                                  final boolean isFloatFloat) {
    final Convention underlyingConvention = _conventionSource.getConvention(convention.getIborIndexConvention());
    if (!(underlyingConvention instanceof IborIndexConvention)) {
      if (underlyingConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention with id " + convention.getIborIndexConvention());
      }
      throw new OpenGammaRuntimeException("Convention of the underlying was not an ibor index convention; have " + underlyingConvention.getClass());
    }
    final IborIndexConvention indexConvention = (IborIndexConvention) underlyingConvention;
    final Currency currency = indexConvention.getCurrency();
    final DayCount dayCount = indexConvention.getDayCount();
    final BusinessDayConvention businessDayConvention = indexConvention.getBusinessDayConvention();
View Full Code Here

  @Override
  public CashSecurity visitCashNode(final CashNode cashNode) {
    final Convention convention = _conventionSource.getConvention(cashNode.getConvention());
    if (convention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + cashNode.getConvention() + " was null");
    }
    final Period startPeriod = cashNode.getStartTenor().getPeriod();
    final Period maturityPeriod = cashNode.getMaturityTenor().getPeriod();
    if (convention instanceof DepositConvention) {
      final DepositConvention depositConvention = (DepositConvention) convention;
      final Currency currency = depositConvention.getCurrency();
      final Calendar calendar = CalendarUtils.getCalendar(_regionSource,
                                                          _holidaySource,
                                                          depositConvention.getRegionCalendar());
      final BusinessDayConvention businessDayConvention = depositConvention.getBusinessDayConvention();
      final boolean isEOM = depositConvention.isIsEOM();
      final DayCount dayCount = depositConvention.getDayCount();
      final int settlementDays = depositConvention.getSettlementDays();
      final ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(_valuationTime, settlementDays, calendar);
      final ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(spotDate,
                                                                         startPeriod,
                                                                         businessDayConvention,
                                                                         calendar,
                                                                         isEOM);
      final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(startDate,
                                                                       maturityPeriod,
                                                                       businessDayConvention,
                                                                       calendar,
                                                                       isEOM);
      final double accrualFactor = dayCount.getDayCountFraction(startDate, endDate);
      return new CashSecurity(currency,
                              depositConvention.getRegionCalendar(),
                              startDate,
                              endDate,
                              dayCount,
                              _rate,
                              _amount);
    } else if (convention instanceof IborIndexConvention) {
      final IborIndexConvention iborConvention = (IborIndexConvention) convention;
      final Currency currency = iborConvention.getCurrency();
      final Calendar calendar = CalendarUtils.getCalendar(_regionSource,
                                                          _holidaySource,
                                                          iborConvention.getRegionCalendar());
      final BusinessDayConvention businessDayConvention = iborConvention.getBusinessDayConvention();
      final boolean isEOM = iborConvention.isIsEOM();
      final DayCount dayCount = iborConvention.getDayCount();
      final int settlementDays = iborConvention.getSettlementDays();
      final ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(_valuationTime, settlementDays, calendar);
      final ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(spotDate,
                                                                         startPeriod,
                                                                         businessDayConvention,
                                                                         calendar,
                                                                         isEOM);
      final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(startDate,
                                                                       maturityPeriod,
                                                                       businessDayConvention,
                                                                       calendar,
                                                                       isEOM);
      final double accrualFactor = dayCount.getDayCountFraction(startDate, endDate);
      final int spotLag = iborConvention.getSettlementDays();
      final boolean eom = iborConvention.isIsEOM();
      final long months = maturityPeriod.toTotalMonths() - startPeriod.toTotalMonths();
      final Period indexTenor = Period.ofMonths((int) months);
      final IborIndex iborIndex = new IborIndex(currency,
                                                indexTenor,
                                                spotLag,
                                                dayCount,
                                                businessDayConvention,
                                                eom,
                                                convention.getName());
      return new CashSecurity(currency,
                              iborConvention.getRegionCalendar(),
                              startDate,
                              endDate,
                              dayCount,
                              _rate,
                              _amount);
    } else {
      throw new OpenGammaRuntimeException("Could not handle convention of type " + convention.getClass());
    }
  }
View Full Code Here

TOP

Related Classes of com.opengamma.OpenGammaRuntimeException

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.