List of usage examples for org.apache.commons.lang Validate isTrue
public static void isTrue(boolean expression, String message)
Validate an argument, throwing IllegalArgumentException
if the test result is false
.
This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.
Validate.isTrue( (i > 0), "The value must be greater than zero"); Validate.isTrue( myObject.isOk(), "The object is not OK");
For performance reasons, the message string should not involve a string append, instead use the #isTrue(boolean,String,Object) method.
From source file:com.opengamma.analytics.financial.interestrate.FDCurveSensitivityCalculator.java
/** * Gives the sensitivity of the some metric of an IRD to a points on a one of the family of curves by finite difference * @param ird The Interest Rate Derivative * @param calculator This calculates the metric * @param curves The family of yield curves * @param curveName The name of the curve of interest * @param times The times along the curve. <b>Note</b> These should be in ascending order and be known sensitivity points * (or the result will be zero)// w w w . j av a 2 s . c om * @param absTol If the absolute value of a sensitivities is below this value it is ignored * @return Sensitivities at a given points */ public static final List<DoublesPair> curveSensitvityFDCalculator(final InstrumentDerivative ird, final InstrumentDerivativeVisitorAdapter<YieldCurveBundle, Double> calculator, final YieldCurveBundle curves, final String curveName, final double[] times, final double absTol) { Validate.notNull(times, "null times"); Validate.notNull(ird, "null ird"); Validate.notNull(calculator, "null calculator"); Validate.notNull(curves, "null curves"); Validate.isTrue(times[0] >= 0.0, "t less than 0"); Validate.isTrue(curves.containsName(curveName), "curveName not in curves"); final List<DoublesPair> res = new ArrayList<>(); double oldT = times[0]; boolean first = true; for (final double t : times) { if (!first) { Validate.isTrue(t > oldT, "times not strictly assending"); } else { first = false; } final double sense = impFDCalculator(ird, calculator, curves, curveName, t); if (Math.abs(sense) > absTol) { res.add(new DoublesPair(t, sense)); } oldT = t; } return res; }
From source file:com.opengamma.analytics.financial.timeseries.util.TimeSeriesWeightedVolatilityOperator.java
@Override public DateDoubleTimeSeries<?> evaluate(DateDoubleTimeSeries<?> ts) { Validate.notNull(ts, "time series"); Validate.isTrue(ts.size() > 1, "time series length must be > 1"); DateDoubleTimeSeries<?> percentageChangeSeries = PERCENTAGE_CHANGE.evaluate(ts); int n = percentageChangeSeries.size(); double[] weightedVariances = new double[n]; double[] weightedVolatilities = new double[n]; double oldestPercentageChange = percentageChangeSeries.getEarliestValueFast(); weightedVariances[0] = oldestPercentageChange * oldestPercentageChange; weightedVolatilities[0] = Math.abs(oldestPercentageChange); for (int i = 1; i < n; i++) { double percentageChange = percentageChangeSeries.getValueAtIndexFast(i); weightedVariances[i] = ((1 - _lambda) * percentageChange * percentageChange) + (_lambda * weightedVariances[i - 1]); weightedVolatilities[i] = Math.sqrt(weightedVariances[i]); }//from www . jav a2 s . c o m return ImmutableLocalDateDoubleTimeSeries.of(percentageChangeSeries.timesArrayFast(), weightedVolatilities); }
From source file:com.opengamma.analytics.financial.interestrate.payments.derivative.Coupon.java
/** * Constructor of a generic coupon from details. * @param currency The payment currency. * @param paymentTime Time (in years) up to the payment. * @param fundingCurveName Name of the funding curve. * @param paymentYearFraction The year fraction (or accrual factor) for the coupon payment. * @param notional Coupon notional./*from w w w. j a va 2 s.c o m*/ */ public Coupon(final Currency currency, final double paymentTime, final String fundingCurveName, final double paymentYearFraction, final double notional) { super(currency, paymentTime, fundingCurveName); Validate.isTrue(paymentYearFraction >= 0, "year fraction < 0"); _paymentYearFraction = paymentYearFraction; _notional = notional; }
From source file:com.relicum.ipsum.Configuration.RankMap.java
/** * Gets formatted color formatted player names for tab list based on rank. * * @param ranks the ranks//from ww w .j ava2 s. co m * @param player the player * @return the formatted */ public static String getFormatted(GameRanks ranks, String player) { Validate.isTrue(!(player.length() > 15), "Players name can not be longer than 14 characters"); if (rankValid(ranks)) { System.out.println("The rank of " + ranks.toString() + " has been found"); return rankMap.get(ranks) + player; } else { System.out.println("The rank of " + ranks.toString() + " has not been found"); return rankMap.get(GameRanks.NOOB) + player; } }
From source file:com.opengamma.analytics.financial.interestrate.payments.derivative.CouponFloating.java
/** * Constructor from all the details.//from w w w. j a v a2 s . com * @param currency The payment currency. * @param paymentTime Time (in years) up to the payment. * @param fundingCurveName Name of the funding curve. * @param paymentYearFraction The year fraction (or accrual factor) for the coupon payment. * @param notional Coupon notional. * @param fixingTime Time (in years) up to fixing. */ public CouponFloating(final Currency currency, final double paymentTime, final String fundingCurveName, final double paymentYearFraction, final double notional, final double fixingTime) { super(currency, paymentTime, fundingCurveName, paymentYearFraction, notional); Validate.isTrue(fixingTime >= 0.0, "fixing time < 0"); _fixingTime = fixingTime; }
From source file:com.opengamma.analytics.math.statistics.descriptive.PearsonSecondSkewnessCoefficientCalculator.java
/** * @param x The array of data, not null. Must contain at least two data points * @return The Pearson second skewness coefficient *///from w w w . jav a 2 s .c o m @Override public Double evaluate(final double[] x) { Validate.notNull(x); Validate.isTrue(x.length > 1, "Need at least two data points to calculate Pearson first skewness coefficient"); return 3 * (_mean.evaluate(x) - _median.evaluate(x)) / _stdDev.evaluate(x); }
From source file:com.opengamma.financial.analytics.model.forex.option.black.FXOneLookBarrierOptionBlackVannaFunction.java
@Override protected Object computeValues(Set<ForexOptionVanilla> vanillaOptions, ForexOptionDataBundle<?> market) { Validate.isTrue(market instanceof SmileDeltaTermStructureDataBundle, "FXOneLookBarrierOptionBlackVannaFunction requires a Vol surface with a smile."); double sum = 0.0; for (ForexOptionVanilla derivative : vanillaOptions) { final CurrencyAmount vannaCcy = METHOD.vanna(derivative, market); sum += vannaCcy.getAmount();/*from w w w . j a va 2 s. c o m*/ } return sum; }
From source file:com.opengamma.financial.analytics.model.forex.option.black.FXOneLookBarrierOptionBlackVommaFunction.java
@Override protected Object computeValues(Set<ForexOptionVanilla> vanillaOptions, ForexOptionDataBundle<?> market) { Validate.isTrue(market instanceof SmileDeltaTermStructureDataBundle, "FXOneLookBarrierOptionBlackVommaFunction requires a Vol surface with a smile."); double sum = 0.0; for (ForexOptionVanilla derivative : vanillaOptions) { final CurrencyAmount vommaCcy = METHOD.vomma(derivative, market); sum += vommaCcy.getAmount();/* www. j a va 2s. c o m*/ } return sum; }
From source file:com.opengamma.analytics.math.statistics.descriptive.PearsonFirstSkewnessCoefficientCalculator.java
/** * @param x The array of data, not null. Must contain at least two data points * @return The Pearson first skewness coefficient *//*from w w w. ja va2s. co m*/ @Override public Double evaluate(final double[] x) { Validate.notNull(x); Validate.isTrue(x.length > 1, "Need at least two data points to calculate Pearson first skewness coefficient"); return 3 * (MEAN.evaluate(x) - MODE.evaluate(x)) / STD_DEV.evaluate(x); }
From source file:com.opengamma.analytics.math.statistics.descriptive.SampleFisherKurtosisCalculator.java
/** * @param x The array of data, not null. Must contain at least four data points. * @return The sample Fisher kurtosis/* ww w . j a v a 2 s .c o m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length >= 4, "Need at least four points to calculate kurtosis"); double sum = 0; final double mean = MEAN.evaluate(x); double variance = 0; for (final Double d : x) { final double diff = d - mean; final double diffSq = diff * diff; variance += diffSq; sum += diffSq * diffSq; } final int n = x.length; final double n1 = n - 1; final double n2 = n1 - 1; variance /= n1; return n * (n + 1.) * sum / (n1 * n2 * (n - 3.) * variance * variance) - 3 * n1 * n1 / (n2 * (n - 3.)); }