@Override public FxSwapTrade trade(double quantity, MarketData marketData, ReferenceData refData) { FxRate fxRate = marketData.getValue(fxRateId); double rate = fxRate.fxRate(template.getCurrencyPair()); double fxPts = marketData.getValue(farForwardPointsId); BuySell buySell = quantity > 0 ? BuySell.BUY : BuySell.SELL; return template.createTrade(marketData.getValuationDate(), buySell, Math.abs(quantity), rate, fxPts, refData); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.template != null) { if (builder.label == null) { builder.label = Tenor.of(builder.template.getPeriodToFar()).toString(); } if (builder.fxRateId == null) { builder.fxRateId = FxRateId.of(builder.template.getCurrencyPair()); } else { ArgChecker.isTrue( builder.fxRateId.getPair().toConventional().equals(builder.template.getCurrencyPair().toConventional()), "FxRateId currency pair '{}' must match that of the template '{}'", builder.fxRateId.getPair(), builder.template.getCurrencyPair()); } } }
public void test_of_near_far() { FxSwapTemplate test = FxSwapTemplate.of(NEAR_PERIOD, FAR_PERIOD, CONVENTION); assertEquals(test.getPeriodToNear(), NEAR_PERIOD); assertEquals(test.getPeriodToFar(), FAR_PERIOD); assertEquals(test.getConvention(), CONVENTION); assertEquals(test.getCurrencyPair(), EUR_USD); }
public void test_of_far() { FxSwapTemplate test = FxSwapTemplate.of(FAR_PERIOD, CONVENTION); assertEquals(test.getPeriodToNear(), Period.ZERO); assertEquals(test.getPeriodToFar(), FAR_PERIOD); assertEquals(test.getConvention(), CONVENTION); assertEquals(test.getCurrencyPair(), EUR_USD); }