@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { accrualPeriods .stream() .forEach(accrual -> accrual.getRateObservation().collectIndices(builder)); getFxReset().ifPresent(fxReset -> builder.add(fxReset.getIndex())); }
/** * Gets the accrual end date of the swap. * * <p>This is the latest accrual date of the legs, often known as the termination date. The latest * date is chosen by examining the unadjusted end date. * * @return the end date of the swap */ @DerivedProperty public AdjustableDate getEndDate() { return legs.stream() .map(SwapLeg::getEndDate) .max(Comparator.comparing(adjDate -> adjDate.getUnadjusted())) .get(); // always at least one leg, so get() is safe }
/** * Finds a single sensitivity instance by name and currency. * * @param name the curve name to find * @param currency the currency to find * @return the matching sensitivity */ public Optional<CurveCurrencyParameterSensitivity> findSensitivity( CurveName name, Currency currency) { return sensitivities .stream() .filter(sens -> sens.getCurveName().equals(name) && sens.getCurrency().equals(currency)) .findFirst(); }
@Override public Optional<Currency> reportingCurrency(CalculationTarget target) { return rules .stream() .map(rule -> rule.reportingCurrency(target)) .flatMap(Guavate::stream) .findFirst(); }
/** * Returns an instance with the specified operation applied to the sensitivity values. * * <p>The result will consist of the same entries, but with the operator applied to each * sensitivity value. This instance is immutable and unaffected by this method. * * <p>This is used to apply a mathematical operation to the sensitivity values. For example, the * operator could multiply the sensitivities by a constant, or take the inverse. * * <pre> * inverse = base.mapSensitivities(value -> 1 / value); * </pre> * * @param operator the operator to be applied to the sensitivities * @return an instance based on this one, with the operator applied to the sensitivity values */ public CurveCurrencyParameterSensitivities mapSensitivities(DoubleUnaryOperator operator) { return sensitivities .stream() .map(s -> s.mapSensitivity(operator)) .collect( Collectors.collectingAndThen( Guavate.toImmutableList(), CurveCurrencyParameterSensitivities::new)); }
/** Generates the .Net documentation for a list of parameters */ protected static String toParamListDocs( final ImmutableList<String> params, final Ds3DocSpec docSpec, final int indent) { if (isEmpty(params)) { return ""; } return params .stream() .map(name -> toParamDocs(name, docSpec.getParamDocumentation(name).orElse(""), indent)) .collect(Collectors.joining()); }
/** Gets the list of with-constructors for all optional parameters */ @Override public ImmutableList<String> toWithConstructorList( final ImmutableList<Arguments> optionalParams, final String requestName, final Ds3DocSpec docSpec) { return optionalParams .stream() .map(param -> toWithConstructor(param, requestName, docSpec)) .collect(GuavaCollectors.immutableList()); }
/** * Converts a list of Ds3Params into a list of Arguments * * @param ds3Params A list of Ds3Params * @return A list of Arguments */ protected static ImmutableList<Arguments> toArgumentsList( final ImmutableList<Ds3Param> ds3Params) { if (isEmpty(ds3Params)) { return ImmutableList.of(); } return ds3Params .stream() .filter(param -> !param.getName().equals("Operation")) .map( param -> new Arguments( param.getType().substring(param.getType().lastIndexOf(".") + 1), param.getName())) .collect(GuavaCollectors.immutableList()); }
/** * Gets the list of constructor models from a Ds3Request. For the base request, the constructor * list will be of size one. */ @Override public ImmutableList<RequestConstructor> toConstructorList( final Ds3Request ds3Request, final String requestName, final Ds3DocSpec docSpec) { final ImmutableList<Arguments> constructorArgs = toConstructorArgumentsList(ds3Request); final ImmutableList<String> argNames = constructorArgs.stream().map(Arguments::getName).collect(GuavaCollectors.immutableList()); final RequestConstructor constructor = new RequestConstructor( constructorArgs, constructorArgs, toQueryParamsList(ds3Request), toConstructorDocs(requestName, argNames, docSpec, 1)); return ImmutableList.of(constructor); }
// ------------------------------------------------------------------------- @Override public ResolvedSwap resolve(ReferenceData refData) { return ResolvedSwap.builder() .legs(legs.stream().map(leg -> leg.resolve(refData)).collect(toImmutableList())) .build(); }
/** * Totals all the sensitivity values. * * <p>The result is the total of all values, in whatever currency they are defined. * * @return the total sensitivity */ public MultiCurrencyAmount total() { return sensitivities .stream() .map(CurveCurrencyParameterSensitivity::total) .collect(MultiCurrencyAmount.collector()); }
private static long getNeTypeCount(ImmutableList<String> attributes) { return attributes .stream() .filter(b -> IwanModelConstants.KEY_TYPES.contains(b.substring(0, b.indexOf(':')))) .count(); }
/** * Gets the legs of the swap with the specified type. * * <p>This returns all the legs with the given type. * * @param type the type to find * @return the matching legs of the swap */ public ImmutableList<SwapLeg> getLegs(SwapLegType type) { return legs.stream().filter(leg -> leg.getType() == type).collect(toImmutableList()); }
@Setup public void setup() { MetadataManager metadata = MetadataManager.createTestMetadataManager(); ExpressionCompiler compiler = new ExpressionCompiler(metadata); List<String> keys; switch (mapSize) { case 1: keys = ImmutableList.of("do_not_use"); break; case 13: keys = ImmutableList.of( "is_inverted", "device_model", "country", "carrier_id", "network_type", "os_version", "device_brand", "device_type", "interface", "device_os", "app_version", "device_type_class", "browser"); break; default: throw new UnsupportedOperationException(); } verify(keys.size() == mapSize); MapType mapType; Block valueBlock; switch (name) { case "fix-width": mapType = new MapType(createUnboundedVarcharType(), DOUBLE); valueBlock = createFixWidthValueBlock(POSITIONS, mapSize); break; case "var-width": mapType = new MapType(createUnboundedVarcharType(), createUnboundedVarcharType()); valueBlock = createVarWidthValueBlock(POSITIONS, mapSize); break; case "dictionary": mapType = new MapType(createUnboundedVarcharType(), createUnboundedVarcharType()); valueBlock = createDictionaryValueBlock(POSITIONS, mapSize); break; default: throw new UnsupportedOperationException(); } Block keyBlock = createKeyBlock(POSITIONS, keys); Block block = createMapBlock(POSITIONS, keyBlock, valueBlock); ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder(); Signature signature = new Signature( "$operator$" + SUBSCRIPT.name(), FunctionKind.SCALAR, mapType.getValueType().getTypeSignature(), mapType.getTypeSignature(), mapType.getKeyType().getTypeSignature()); for (int i = 0; i < mapSize; i++) { projectionsBuilder.add( new CallExpression( signature, mapType.getValueType(), ImmutableList.of( new InputReferenceExpression(0, mapType), new ConstantExpression(utf8Slice(keys.get(i)), createUnboundedVarcharType())))); } ImmutableList<RowExpression> projections = projectionsBuilder.build(); pageProcessor = compiler .compilePageProcessor(new ConstantExpression(true, BooleanType.BOOLEAN), projections) .get(); pageBuilder = new PageBuilder( projections.stream().map(RowExpression::getType).collect(Collectors.toList())); page = new Page(block); }
/** * Gets the first pay or receive leg of the swap. * * <p>This returns the first pay or receive leg of the swap, empty if no matching leg. * * @param payReceive the pay or receive flag * @return the first matching leg of the swap */ public Optional<SwapLeg> getLeg(PayReceive payReceive) { return legs.stream().filter(leg -> leg.getPayReceive() == payReceive).findFirst(); }
/** * Returns the set of indices referred to by the swap. * * <p>A swap will typically refer to at least one index, such as 'GBP-LIBOR-3M'. Calling this * method will return the complete list of indices, including any associated with FX reset. * * @return the set of indices referred to by this swap */ public ImmutableSet<Index> allIndices() { ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); legs.stream().forEach(leg -> leg.collectIndices(builder)); return builder.build(); }
/** * Returns the set of payment currencies referred to by the swap. * * <p>This returns the complete set of payment currencies for the swap. This will typically return * one or two currencies. * * <p>If there is an FX reset, then this set contains the currency of the payment, not the * currency of the notional. Note that in many cases, the currency of the FX reset notional will * be the currency of the other leg. * * @return the set of payment currencies referred to by this swap */ public ImmutableSet<Currency> allPaymentCurrencies() { return legs.stream().map(leg -> leg.getCurrency()).collect(toImmutableSet()); }