@Override public MetaProperty<?> findMetaProperty(Class<?> beanType, MetaBean metaBean, String propertyName) { try { return metaBean.metaProperty(propertyName); } catch (NoSuchElementException ex) { if (HOLIDAYS.name().equals(propertyName)) { return HOLIDAYS; } if (WEEKEND_DAYS.name().equals(propertyName)) { return WEEKEND_DAYS; } throw ex; } }
@Override public <R> Property<R> property(String propertyName) { return metaBean().<R>metaProperty(propertyName).createProperty(this); }
private Set<String> fieldValues(Object object) { if (!(object instanceof Bean)) { return ImmutableSet.of(); } Bean bean = (Bean) object; return bean.propertyNames().stream() .map(bean::property) .filter(p -> SUPPORTED_FIELD_TYPES.contains(p.metaProperty().propertyType())) .map(Property::get) .filter(v -> v != null) .map(Object::toString) .map(v -> v.toLowerCase(Locale.ENGLISH)) .collect(toImmutableSet()); }
@Override public EvaluationResult evaluate( Position position, CalculationFunctions functions, String firstToken, List<String> remainingTokens) { MetaBean metaBean = MetaBean.of(position.getClass()); // position Optional<String> positionPropertyName = metaBean.metaPropertyMap().keySet().stream() .filter(p -> p.equalsIgnoreCase(firstToken)) .findFirst(); if (positionPropertyName.isPresent()) { Object propertyValue = metaBean.metaProperty(positionPropertyName.get()).get((Bean) position); return propertyValue != null ? EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("Property '{}' not set", firstToken); } // position info Optional<String> positionInfoPropertyName = position.getInfo().propertyNames().stream() .filter(p -> p.equalsIgnoreCase(firstToken)) .findFirst(); if (positionInfoPropertyName.isPresent()) { Object propertyValue = position.getInfo().property(positionInfoPropertyName.get()).get(); return propertyValue != null ? EvaluationResult.success(propertyValue, remainingTokens) : EvaluationResult.failure("Property '{}' not set", firstToken); } // not found return invalidTokenFailure(position, firstToken); }
public void coverage() { coverImmutableBean(IntArray.of(1, 2, 3)); IntArray.of(1, 2, 3).metaBean().metaProperty("array").metaBean(); IntArray.of(1, 2, 3).metaBean().metaProperty("array").propertyGenericType(); IntArray.of(1, 2, 3).metaBean().metaProperty("array").annotations(); }
Object propertyValue = metaBean.metaProperty(tradePropertyName.get()).get((Bean) trade); if (propertyValue == null) { return EvaluationResult.failure("Property '{}' not set", firstToken);
public void coverage() { coverImmutableBean(DoubleArray.of(1d, 2d, 3d)); DoubleArray.of(1d, 2d, 3d).metaBean().metaProperty("array").metaBean(); DoubleArray.of(1d, 2d, 3d).metaBean().metaProperty("array").propertyGenericType(); DoubleArray.of(1d, 2d, 3d).metaBean().metaProperty("array").annotations(); }
@Override public MetaProperty<?> findMetaProperty(Class<?> beanType, MetaBean metaBean, String propertyName) { try { return metaBean.metaProperty(propertyName); } catch (NoSuchElementException ex) { if (BASE_CURRENCY_AMOUNT.name().equals(propertyName)) { return BASE_CURRENCY_AMOUNT; } if (COUNTER_CURRENCY_AMOUNT.name().equals(propertyName)) { return COUNTER_CURRENCY_AMOUNT; } if (PAYMENT_DATE.name().equals(propertyName)) { return PAYMENT_DATE; } throw ex; } }
.findFirst(); if (securityPropertyName.isPresent()) { Object propertyValue = metaBean.metaProperty(securityPropertyName.get()).get((Bean) security); return propertyValue != null ? EvaluationResult.success(propertyValue, remainingTokens) :
@Override public <R> Property<R> property(String propertyName) { return metaBean().<R>metaProperty(propertyName).createProperty(this); }
@Override public Object get(String propertyName) { if (propertyName.equals(ARRAY.name())) { return array.clone(); } else { throw new NoSuchElementException("Unknown property: " + propertyName); } }
private <T> CurrencyParameterSensitivities sensitivity( ImmutableLegalEntityDiscountingProvider provider, Function<ImmutableLegalEntityDiscountingProvider, CurrencyAmount> valueFn, MetaProperty<ImmutableMap<Pair<T, Currency>, DiscountFactors>> metaProperty, CurrencyAmount valueInit) { ImmutableMap<Pair<T, Currency>, DiscountFactors> baseCurves = metaProperty.get(provider); CurrencyParameterSensitivities result = CurrencyParameterSensitivities.empty(); for (Pair<T, Currency> key : baseCurves.keySet()) { DiscountFactors discountFactors = baseCurves.get(key); Curve curve = checkDiscountFactors(discountFactors); int paramCount = curve.getParameterCount(); double[] sensitivity = new double[paramCount]; for (int i = 0; i < paramCount; i++) { Curve dscBumped = curve.withParameter(i, curve.getParameter(i) + shift); Map<Pair<T, Currency>, DiscountFactors> mapBumped = new HashMap<>(baseCurves); mapBumped.put(key, createDiscountFactors(discountFactors, dscBumped)); ImmutableLegalEntityDiscountingProvider providerDscBumped = provider.toBuilder().set(metaProperty, mapBumped).build(); sensitivity[i] = (valueFn.apply(providerDscBumped).getAmount() - valueInit.getAmount()) / shift; } result = result.combinedWith( curve.createParameterSensitivity(valueInit.getCurrency(), DoubleArray.copyOf(sensitivity))); } return result; }
@Override public Object get(String propertyName) { if (propertyName.equals(ARRAY.name())) { return array.clone(); } else { throw new NoSuchElementException("Unknown property: " + propertyName); } }
private <T> CurrencyParameterSensitivities sensitivityDiscountCurve( ImmutableCreditRatesProvider provider, Function<ImmutableCreditRatesProvider, CurrencyAmount> valueFn, MetaProperty<ImmutableMap<T, CreditDiscountFactors>> metaProperty, CurrencyAmount valueInit) { ImmutableMap<T, CreditDiscountFactors> baseCurves = metaProperty.get(provider); CurrencyParameterSensitivities result = CurrencyParameterSensitivities.empty(); for (T key : baseCurves.keySet()) { CreditDiscountFactors creditDiscountFactors = baseCurves.get(key); DiscountFactors discountFactors = creditDiscountFactors.toDiscountFactors(); Curve curve = checkDiscountFactors(discountFactors); int paramCount = curve.getParameterCount(); double[] sensitivity = new double[paramCount]; for (int i = 0; i < paramCount; i++) { Curve dscBumped = curve.withParameter(i, curve.getParameter(i) + shift); Map<T, CreditDiscountFactors> mapBumped = new HashMap<>(baseCurves); mapBumped.put(key, createCreditDiscountFactors(creditDiscountFactors, dscBumped)); ImmutableCreditRatesProvider providerDscBumped = provider.toBuilder().set(metaProperty, mapBumped).build(); sensitivity[i] = (valueFn.apply(providerDscBumped).getAmount() - valueInit.getAmount()) / shift; } result = result.combinedWith( curve.createParameterSensitivity(valueInit.getCurrency(), DoubleArray.copyOf(sensitivity))); } return result; }
@Override public BeanBuilder<IntArray> set(String propertyName, Object value) { if (propertyName.equals(ARRAY.name())) { this.array = ((int[]) ArgChecker.notNull(value, "value")).clone(); } else { throw new NoSuchElementException("Unknown property: " + propertyName); } return this; }
private CurrencyAmount fn(ImmutableLegalEntityDiscountingProvider provider) { double result = 0.0; // issuer curve ImmutableMap<Pair<LegalEntityGroup, Currency>, DiscountFactors> mapLegal = provider.metaBean().issuerCurves() .get(provider); for (Entry<Pair<LegalEntityGroup, Currency>, DiscountFactors> entry : mapLegal.entrySet()) { InterpolatedNodalCurve curveInt = checkInterpolated(checkDiscountFactors(entry.getValue())); result += sumProduct(curveInt); } // repo curve ImmutableMap<Pair<RepoGroup, Currency>, DiscountFactors> mapRepo = provider.metaBean().repoCurves().get(provider); for (Entry<Pair<RepoGroup, Currency>, DiscountFactors> entry : mapRepo.entrySet()) { InterpolatedNodalCurve curveInt = checkInterpolated(checkDiscountFactors(entry.getValue())); result += sumProduct(curveInt); } return CurrencyAmount.of(USD, result); }
@Override public BeanBuilder<DoubleArray> set(String propertyName, Object value) { if (propertyName.equals(ARRAY.name())) { this.array = ((double[]) ArgChecker.notNull(value, "value")).clone(); } else { throw new NoSuchElementException("Unknown property: " + propertyName); } return this; }
private <T> CurrencyParameterSensitivities sensitivityCreidtCurve( ImmutableCreditRatesProvider provider, Function<ImmutableCreditRatesProvider, CurrencyAmount> valueFn, MetaProperty<ImmutableMap<T, LegalEntitySurvivalProbabilities>> metaProperty, CurrencyAmount valueInit) { ImmutableMap<T, LegalEntitySurvivalProbabilities> baseCurves = metaProperty.get(provider); CurrencyParameterSensitivities result = CurrencyParameterSensitivities.empty(); for (T key : baseCurves.keySet()) { LegalEntitySurvivalProbabilities credit = baseCurves.get(key); CreditDiscountFactors creditDiscountFactors = credit.getSurvivalProbabilities(); DiscountFactors discountFactors = creditDiscountFactors.toDiscountFactors(); Curve curve = checkDiscountFactors(discountFactors); int paramCount = curve.getParameterCount(); double[] sensitivity = new double[paramCount]; for (int i = 0; i < paramCount; i++) { Curve dscBumped = curve.withParameter(i, curve.getParameter(i) + shift); Map<T, LegalEntitySurvivalProbabilities> mapBumped = new HashMap<>(baseCurves); mapBumped.put(key, LegalEntitySurvivalProbabilities.of( credit.getLegalEntityId(), createCreditDiscountFactors(creditDiscountFactors, dscBumped))); ImmutableCreditRatesProvider providerDscBumped = provider.toBuilder().set(metaProperty, mapBumped).build(); sensitivity[i] = (valueFn.apply(providerDscBumped).getAmount() - valueInit.getAmount()) / shift; } result = result.combinedWith( curve.createParameterSensitivity(valueInit.getCurrency(), DoubleArray.copyOf(sensitivity))); } return result; }
public void test_builder() { assertThrowsIllegalArg(() -> DiscountFxForwardRates.meta().builder() .set(DiscountFxForwardRates.meta().currencyPair(), CurrencyPair.parse("GBP/USD")).build()); assertThrowsIllegalArg(() -> DiscountFxForwardRates.meta().builder() .set(DiscountFxForwardRates.meta().currencyPair().name(), CurrencyPair.parse("GBP/USD")).build()); }
public void test_builder() { LocalDateDoubleTimeSeries ts = LocalDateDoubleTimeSeries.of(PREV_DATE, 0.62d); ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE) .timeSeries(GBP_USD_WM, ts) .build(); assertEquals(test.getValuationDate(), VAL_DATE); assertEquals(ImmutableRatesProvider.meta().timeSeries().get(test), ImmutableMap.of(GBP_USD_WM, ts)); assertSame(test.toImmutableRatesProvider(), test); }