/** * Creates a trade based on this template. * <p> * This returns a trade based on the specified date. * The notional is unsigned, with buy/sell determining the direction of the trade. * If buying the FX Swap, the amount in the first currency of the pair is received * in the near leg and paid in the far leg, while the second currency is paid in the * near leg and received in the far leg. * * @param tradeDate the date of the trade * @param buySell the buy/sell flag * @param notional the notional amount, in the first currency of the currency pair * @param nearFxRate the FX rate for the near leg * @param forwardPoints the FX points to be added to the FX rate at the far leg * @param refData the reference data, used to resolve the trade dates * @return the trade * @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data */ public FxSwapTrade createTrade( LocalDate tradeDate, BuySell buySell, double notional, double nearFxRate, double forwardPoints, ReferenceData refData) { return convention.createTrade( tradeDate, periodToNear, periodToFar, buySell, notional, nearFxRate, forwardPoints, refData); }
/** * Gets the currency pair of the template. * * @return the currency pair */ public CurrencyPair getCurrencyPair() { return convention.getCurrencyPair(); }
/** * Calculates the spot date from the trade date. * * @param tradeDate the trade date * @param refData the reference data, used to resolve the date * @return the spot date * @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data */ public default LocalDate calculateSpotDateFromTradeDate(LocalDate tradeDate, ReferenceData refData) { return getSpotDateOffset().adjust(tradeDate, refData); }
ReferenceData refData) { LocalDate spotValue = calculateSpotDateFromTradeDate(tradeDate, refData); LocalDate startDate = spotValue.plus(periodToNear); LocalDate endDate = spotValue.plus(periodToFar); return toTrade(tradeDate, startDate, endDate, buySell, notional, nearFxRate, farLegForwardPoints);
/** * Obtains an instance from the specified unique name. * * @param uniqueName the unique name * @return the convention * @throws IllegalArgumentException if the name is not known */ @FromString public static FxSwapConvention of(String uniqueName) { ArgChecker.notNull(uniqueName, "uniqueName"); return extendedEnum().lookup(uniqueName); }
return toTrade(tradeInfo, startDate, endDate, buySell, notional, nearFxRate, farLegForwardPoints);
private static CurveNode curveFxSwapCurveNode( String conventionStr, String timeStr, String label, QuoteId quoteId, double spread, CurveNodeDate date, CurveNodeDateOrder order) { if (!DoubleMath.fuzzyEquals(spread, 0d, 1e-10d)) { throw new IllegalArgumentException("Additional spread must be zero for FX swaps"); } Matcher matcher = SIMPLE_YMD_TIME_REGEX.matcher(timeStr.toUpperCase(Locale.ENGLISH)); if (!matcher.matches()) { throw new IllegalArgumentException(Messages.format("Invalid time format for FX swap: {}", timeStr)); } Period periodToEnd = Period.parse("P" + matcher.group(1)); FxSwapConvention convention = FxSwapConvention.of(conventionStr); FxSwapTemplate template = FxSwapTemplate.of(periodToEnd, convention); return FxSwapCurveNode.builder() .template(template) .farForwardPointsId(quoteId) .label(label) .date(date) .dateOrder(order) .build(); }