/** * Creates an instance with spread. * * @param shiftType the shift type * @param shiftAmount the shift amount * @param spread the spread * @return the instance */ public static GenericDoubleShifts of(ShiftType shiftType, DoubleArray shiftAmount, double spread) { return new GenericDoubleShifts(shiftType, shiftAmount, spread); }
@Override public double initialGuess(MarketData marketData, ValueType valueType) { if (ValueType.DISCOUNT_FACTOR.equals(valueType)) { return 1.0d; } return 0.0d; }
@Override public FxRateShifts build() { return new FxRateShifts( shiftType, shiftAmount, currencyPair); }
public void test_of() { FxRateShifts test = FxRateShifts.of(ShiftType.SCALED, SHIFT_AMOUNT_2, EURUSD); assertEquals(test.getCurrencyPair(), EURUSD); assertEquals(test.getScenarioCount(), 3); assertEquals(test.getShiftAmount(), SHIFT_AMOUNT_2); assertEquals(test.getShiftType(), ShiftType.SCALED); }
@Override public MarketDataBox<Double> applyTo(MarketDataBox<Double> marketData, ReferenceData refData) { return marketData.mapWithIndex( getScenarioCount(), (value, scenarioIndex) -> shiftType.applyShift(value + spread, shiftAmount.get(scenarioIndex)) - spread); }
public void test_applyShift() { assertEquals(ShiftType.ABSOLUTE.applyShift(2, 0.1), 2.1); assertEquals(ShiftType.RELATIVE.applyShift(2, 0.1), 2.2); assertEquals(ShiftType.SCALED.applyShift(2, 1.1), 2.2); }
@Override public BeanBuilder<? extends GenericDoubleShifts> builder() { return new GenericDoubleShifts.Builder(); }
@Override public BeanBuilder<? extends FxRateShifts> builder() { return new FxRateShifts.Builder(); }
@Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { metaProperty(propertyName); if (quiet) { return; } throw new UnsupportedOperationException("Property cannot be written: " + propertyName); }
@Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { metaProperty(propertyName); if (quiet) { return; } throw new UnsupportedOperationException("Property cannot be written: " + propertyName); }
/** * Obtains an instance from the specified name. * <p> * Value types must only contains the characters A-Z, a-z, 0-9 and -. * * @param name the name of the field * @return a field with the specified name */ @FromString public static ValueType of(String name) { return new ValueType(name); }
@Override public double initialGuess(MarketData marketData, ValueType valueType) { if (ValueType.DISCOUNT_FACTOR.equals(valueType)) { return 1d; } return 0d; }
@Override public GenericDoubleShifts build() { return new GenericDoubleShifts( shiftType, shiftAmount, spread); }
/** * Creates an instance. * * @param shiftType the shift type * @param shiftAmount the shift amount * @param currencyPair the currency pair * @return the instance */ public static FxRateShifts of(ShiftType shiftType, DoubleArray shiftAmount, CurrencyPair currencyPair) { return new FxRateShifts(shiftType, shiftAmount, currencyPair); }
@Override public double initialGuess(MarketData marketData, ValueType valueType) { if (ValueType.DISCOUNT_FACTOR.equals(valueType)) { return 1.0d; } return 0.0d; }
/** * Creates an instance with zero spread. * * @param shiftType the shift type * @param shiftAmount the shift amount * @return the instance */ public static GenericDoubleShifts of(ShiftType shiftType, DoubleArray shiftAmount) { return new GenericDoubleShifts(shiftType, shiftAmount, 0d); }
@Override public double initialGuess(MarketData marketData, ValueType valueType) { if (ValueType.DISCOUNT_FACTOR.equals(valueType)) { return 1d; } return 0d; }
@Override public double initialGuess(MarketData marketData, ValueType valueType) { if (ValueType.ZERO_RATE.equals(valueType)) { return marketData.getValue(rateId); } return 0d; }