ConventionBundle swapConvention = getConventionBundleSource().getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, ccy.getCode() + "_SWAP"));
if (swapConvention == null) {
s_logger.error("Couldn't get swap convention for {}", ccy.getCode());
return null;
}
final Tenor maturity = getRandom(TENORS);
// get the convention of the identifier of the initial rate
ConventionBundle liborConvention = getConventionBundleSource().getConventionBundle(swapConvention.getSwapFloatingLegInitialRate());
if (liborConvention == null) {
s_logger.error("Couldn't get libor convention for {}", swapConvention.getSwapFloatingLegInitialRate());
return null;
}
// look up the rate timeseries identifier out of the bundle
final ExternalId tsIdentifier = getTimeSeriesIdentifier(liborConvention);
// look up the value on our chosen trade date
final HistoricalTimeSeries initialRateSeries = getHistoricalSource().getHistoricalTimeSeries(MarketDataRequirementNames.MARKET_VALUE, tsIdentifier.toBundle(), null, tradeDate,
true, tradeDate, true);
if (initialRateSeries == null || initialRateSeries.getTimeSeries().isEmpty()) {
s_logger.error("couldn't get series for {} on {}", tsIdentifier, tradeDate);
return null;
}
Double initialRate = initialRateSeries.getTimeSeries().getEarliestValue();
// get the identifier for the swap rate for the maturity we're interested in (assuming the fixed rate will be =~ swap rate)
final ExternalId swapRateForMaturityIdentifier = getSwapRateFor(ccy, tradeDate, maturity);
if (swapRateForMaturityIdentifier == null) {
s_logger.error("Couldn't get swap rate identifier for {} [{}] from {}", new Object[] {ccy, maturity, tradeDate });
return null;
}
final HistoricalTimeSeries fixedRateSeries = getHistoricalSource().getHistoricalTimeSeries(MarketDataRequirementNames.MARKET_VALUE, swapRateForMaturityIdentifier.toBundle(),
null, tradeDate, true,
tradeDate, true);
if (fixedRateSeries == null) {
s_logger.error("can't find time series for {} on {}", swapRateForMaturityIdentifier, tradeDate);
return null;
}
Double fixedRate = (fixedRateSeries.getTimeSeries().getEarliestValue() + getRandom().nextDouble()) / 100d;
Double notional = (double) (getRandom(99999) + 1) * 1000;
ZonedDateTime tradeDateTime = tradeDate.atStartOfDay(ZoneOffset.UTC);
ZonedDateTime maturityDateTime = tradeDate.plus(maturity.getPeriod()).atStartOfDay(ZoneOffset.UTC);
String counterparty = "CParty";
SwapLeg fixedLeg = new FixedInterestRateLeg(swapConvention.getSwapFixedLegDayCount(),
swapConvention.getSwapFixedLegFrequency(),
swapConvention.getSwapFixedLegRegion(),
swapConvention.getSwapFixedLegBusinessDayConvention(),