//------------------------------------------------------------------------- public T get(int index) { ArgChecker.inRange(index, 0, scenarioCount, "index"); return(value); }
/// <summary> /// Returns the principal value of log, with z the principal argument of z defined to lie in the interval (-pi, pi]. </summary> /// <param name="z"> ComplexNumber </param> /// <returns> The log </returns> public static ComplexNumber log(ComplexNumber z) { ArgChecker.notNull(z, "z"); return(new ComplexNumber(Math.Log(Math.hypot(z.Real, z.Imaginary)), Math.Atan2(z.Imaginary, z.Real))); }
// CSOFF: JavadocMethod public static ComplexNumber add(ComplexNumber z1, ComplexNumber z2) { ArgChecker.notNull(z1, "z1"); ArgChecker.notNull(z2, "z2"); return(new ComplexNumber(z1.Real + z2.Real, z1.Imaginary + z2.Imaginary)); }
/// <summary> /// Puts all the entries from the supplied map into this builder. /// <para> /// If a date is duplicated it will overwrite an earlier entry. /// /// </para> /// </summary> /// <param name="map"> the map of points to be added </param> /// <returns> this builder </returns> public LocalDateDoubleTimeSeriesBuilder putAll(IDictionary <LocalDate, double> map) { ArgChecker.noNulls(map, "map"); map.SetOfKeyValuePairs().forEach(e => put(e.Key, e.Value)); return(this); }
/// <summary> /// Measure image box size by the width\height set on the box and the actual rendered image size.<br/> /// If no image exists for the box error icon will be set. /// </summary> /// <param name="imageWord">the image word to measure</param> public static void MeasureImageSize(CssRectImage imageWord) { ArgChecker.AssertArgNotNull(imageWord, "imageWord"); ArgChecker.AssertArgNotNull(imageWord.OwnerBox, "imageWord.OwnerBox"); var width = new CssLength(imageWord.OwnerBox.Width); var height = new CssLength(imageWord.OwnerBox.Height); bool hasImageTagWidth = width.Number > 0 && width.Unit == CssUnit.Pixels; bool hasImageTagHeight = height.Number > 0 && height.Unit == CssUnit.Pixels; bool scaleImageHeight = false; if (hasImageTagWidth) { imageWord.Width = width.Number; } else if (width.Number > 0 && width.IsPercentage) { imageWord.Width = width.Number * imageWord.OwnerBox.ContainingBlock.Size.Width; scaleImageHeight = true; } else if (imageWord.Image != null) { imageWord.Width = imageWord.ImageRectangle == RRect.Empty ? imageWord.Image.Width : imageWord.ImageRectangle.Width; } else { imageWord.Width = hasImageTagHeight ? height.Number / 1.14f : 20; } var maxWidth = new CssLength(imageWord.OwnerBox.MaxWidth); if (maxWidth.Number > 0) { double maxWidthVal = -1; if (maxWidth.Unit == CssUnit.Pixels) { maxWidthVal = maxWidth.Number; } else if (maxWidth.IsPercentage) { maxWidthVal = maxWidth.Number * imageWord.OwnerBox.ContainingBlock.Size.Width; } if (maxWidthVal > -1 && imageWord.Width > maxWidthVal) { imageWord.Width = maxWidthVal; scaleImageHeight = !hasImageTagHeight; } } if (hasImageTagHeight) { imageWord.Height = height.Number; } else if (imageWord.Image != null) { imageWord.Height = imageWord.ImageRectangle == RRect.Empty ? imageWord.Image.Height : imageWord.ImageRectangle.Height; } else { imageWord.Height = imageWord.Width > 0 ? imageWord.Width * 1.14f : 22.8f; } if (imageWord.Image != null) { // If only the width was set in the html tag, ratio the height. if ((hasImageTagWidth && !hasImageTagHeight) || scaleImageHeight) { // Divide the given tag width with the actual image width, to get the ratio. double ratio = imageWord.Width / imageWord.Image.Width; imageWord.Height = imageWord.Image.Height * ratio; } // If only the height was set in the html tag, ratio the width. else if (hasImageTagHeight && !hasImageTagWidth) { // Divide the given tag height with the actual image height, to get the ratio. double ratio = imageWord.Height / imageWord.Image.Height; imageWord.Width = imageWord.Image.Width * ratio; } } imageWord.Height += imageWord.OwnerBox.ActualBorderBottomWidth + imageWord.OwnerBox.ActualBorderTopWidth + imageWord.OwnerBox.ActualPaddingTop + imageWord.OwnerBox.ActualPaddingBottom; }
/// <summary> /// Puts the specified date/value point into this builder. /// </summary> /// <param name="point"> the point to be added </param> /// <returns> this builder </returns> public LocalDateDoubleTimeSeriesBuilder put(LocalDateDoublePoint point) { ArgChecker.notNull(point, "point"); put(point.Date, point.Value); return(this); }
/// <summary> /// Puts all the specified points into this builder. /// <para> /// The points are added one by one. /// If a date is duplicated it will overwrite an earlier entry. /// /// </para> /// </summary> /// <param name="points"> the points to be added </param> /// <returns> this builder </returns> public LocalDateDoubleTimeSeriesBuilder putAll(Stream <LocalDateDoublePoint> points) { ArgChecker.notNull(points, "points"); points.forEach(this.put); return(this); }
/// <summary> /// Creates a standard identifier using the correct Markit RED code scheme. /// </summary> /// <param name="name"> the Markit RED code, 6 or 9 characters long </param> /// <returns> the equivalent standard identifier </returns> public static StandardId id(string name) { ArgChecker.isTrue(name.Length == 6 || name.Length == 9, "RED Code must be exactly 6 or 9 characters"); return(StandardId.of(MARKIT_REDCODE_SCHEME, name)); }
/// <summary> /// Handle mouse leave to handle hover cursor. /// </summary> /// <param name="parent">the control hosting the html to set cursor and invalidate</param> public void HandleMouseLeave(Control parent) { ArgChecker.AssertArgNotNull(parent, "parent"); _htmlContainerInt.HandleMouseLeave(new ControlAdapter(parent, _useGdiPlusTextRendering)); }
/// <summary> /// Computes the present value sensitivity to strike by replication in SABR framework with extrapolation on the right. /// </summary> /// <param name="cmsPeriod"> the CMS </param> /// <param name="provider"> the rates provider </param> /// <param name="swaptionVolatilities"> the swaption volatilities </param> /// <returns> the present value sensitivity </returns> public double presentValueSensitivityStrike(CmsPeriod cmsPeriod, RatesProvider provider, SabrSwaptionVolatilities swaptionVolatilities) { ArgChecker.isFalse(cmsPeriod.CmsPeriodType.Equals(CmsPeriodType.COUPON), "presentValueSensitivityStrike is not relevant for CMS coupon"); Currency ccy = cmsPeriod.Currency; SwapIndex index = cmsPeriod.Index; if (provider.ValuationDate.isAfter(cmsPeriod.PaymentDate)) { return(0d); } ResolvedSwap swap = cmsPeriod.UnderlyingSwap; double dfPayment = provider.discountFactor(ccy, cmsPeriod.PaymentDate); ZonedDateTime valuationDate = swaptionVolatilities.ValuationDateTime; LocalDate fixingDate = cmsPeriod.FixingDate; double tenor = swaptionVolatilities.tenor(swap.StartDate, swap.EndDate); ZonedDateTime expiryDate = fixingDate.atTime(index.FixingTime).atZone(index.FixingZone); double expiryTime = swaptionVolatilities.relativeTime(expiryDate); double strike = cmsPeriod.Strike; double shift = swaptionVolatilities.shift(expiryTime, tenor); if (!fixingDate.isAfter(valuationDate.toLocalDate())) { double?fixedRate = provider.timeSeries(cmsPeriod.Index).get(fixingDate); if (fixedRate.HasValue) { double payoff = 0d; switch (cmsPeriod.CmsPeriodType) { case CAPLET: payoff = fixedRate.Value >= strike ? -1d : 0d; break; case FLOORLET: payoff = fixedRate.Value < strike ? 1d : 0d; break; default: throw new System.ArgumentException("unsupported CMS type"); } return(payoff * cmsPeriod.Notional * cmsPeriod.YearFraction * dfPayment); } else if (fixingDate.isBefore(valuationDate.toLocalDate())) { throw new System.ArgumentException(Messages.format("Unable to get fixing for {} on date {}, no time-series supplied", cmsPeriod.Index, fixingDate)); } } double forward = swapPricer.parRate(swap, provider); double eta = index.Template.Convention.FixedLeg.DayCount.relativeYearFraction(cmsPeriod.PaymentDate, swap.StartDate); CmsIntegrantProvider intProv = new CmsIntegrantProvider(this, cmsPeriod, swap, swaptionVolatilities, forward, strike, expiryTime, tenor, cutOffStrike, eta); double factor = dfPayment * intProv.g(forward) / intProv.h(forward); RungeKuttaIntegrator1D integrator = new RungeKuttaIntegrator1D(ABS_TOL, REL_TOL_STRIKE, NUM_ITER); double[] kpkpp = intProv.kpkpp(strike); double firstPart; double thirdPart; System.Func <double, double> integrant = intProv.integrantDualDelta(); if (intProv.PutCall.Call) { firstPart = -kpkpp[0] * intProv.bs(strike); thirdPart = integrateCall(integrator, integrant, swaptionVolatilities, forward, strike, expiryTime, tenor); } else { firstPart = -kpkpp[0] * intProv.bs(strike); thirdPart = -integrator.integrate(integrant, -shift + ZERO_SHIFT, strike).Value; } double secondPart = intProv.k(strike) * intProv.SabrExtrapolation.priceDerivativeStrike(strike + shift, intProv.PutCall); return(cmsPeriod.Notional * cmsPeriod.YearFraction * factor * (firstPart + secondPart + thirdPart)); }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance from the specified name. /// <para> /// RED codes must be 6 or 9 characters long. /// /// </para> /// </summary> /// <param name="name"> the name of the field </param> /// <returns> a RED code </returns> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @FromString public static MarkitRedCode of(String name) public static MarkitRedCode of(string name) { ArgChecker.isTrue(name.Length == 6 || name.Length == 9, "RED Code must be exactly 6 or 9 characters"); return(new MarkitRedCode(name)); }
private SabrExtrapolationReplicationCmsPeriodPricer(DiscountingSwapProductPricer swapPricer, double cutOffStrike, double mu) { this.swapPricer = ArgChecker.notNull(swapPricer, "swapPricer"); this.cutOffStrike = cutOffStrike; this.mu = ArgChecker.notNegativeOrZero(mu, "mu"); }
//------------------------------------------------------------------------- public double relativeTime(ZonedDateTime zonedDateTime) { ArgChecker.notNull(zonedDateTime, "date"); return(dayCount.relativeYearFraction(valuationDateTime.toLocalDate(), zonedDateTime.toLocalDate())); }
/// <summary> /// Computes the implied volatility. /// </summary> /// <param name="optionPrice"> the option price </param> /// <param name="volGuess"> the initial guess </param> /// <returns> the volatility </returns> public virtual double impliedVolatility(double optionPrice, double volGuess) { ArgChecker.isTrue(volGuess >= 0.0, "volGuess must be positive; have {}", volGuess); ArgChecker.isTrue(Doubles.isFinite(volGuess), "volGuess must be finite; have {} ", volGuess); double lowerSigma; double upperSigma; try { double[] temp = bracketRoot(optionPrice, volGuess); lowerSigma = temp[0]; upperSigma = temp[1]; } catch (MathException e) { throw new System.ArgumentException(e.ToString() + " No implied Volatility for this price. [price: " + optionPrice + "]"); } double sigma = (lowerSigma + upperSigma) / 2.0; double[] pnv = priceAndVegaFunc.apply(sigma); // This can happen for American options, // where low volatilities puts you in the early excise region which obviously has zero vega if (pnv[1] == 0 || double.IsNaN(pnv[1])) { return(solveByBisection(optionPrice, lowerSigma, upperSigma)); } double diff = pnv[0] - optionPrice; bool above = diff > 0; if (above) { upperSigma = sigma; } else { lowerSigma = sigma; } double trialChange = -diff / pnv[1]; double actChange; if (trialChange > 0.0) { actChange = Math.Min(MAX_CHANGE, Math.Min(trialChange, upperSigma - sigma)); } else { actChange = Math.Max(-MAX_CHANGE, Math.Max(trialChange, lowerSigma - sigma)); } int count = 0; while (Math.Abs(actChange) > VOL_TOL) { sigma += actChange; pnv = priceAndVegaFunc.apply(sigma); if (pnv[1] == 0 || double.IsNaN(pnv[1])) { return(solveByBisection(optionPrice, lowerSigma, upperSigma)); } diff = pnv[0] - optionPrice; above = diff > 0; if (above) { upperSigma = sigma; } else { lowerSigma = sigma; } trialChange = -diff / pnv[1]; if (trialChange > 0.0) { actChange = Math.Min(MAX_CHANGE, Math.Min(trialChange, upperSigma - sigma)); } else { actChange = Math.Max(-MAX_CHANGE, Math.Max(trialChange, lowerSigma - sigma)); } if (count++ > MAX_ITERATIONS) { return(solveByBisection(optionPrice, lowerSigma, upperSigma)); } } return(sigma + actChange); // apply the final change }
/// <summary> /// Obtains a template based on the specified periods and convention. /// </summary> /// <param name="depositPeriod"> the period between the start date and the end date </param> /// <param name="convention"> the market convention </param> /// <returns> the template </returns> public static IborFixingDepositTemplate of(Period depositPeriod, IborFixingDepositConvention convention) { ArgChecker.notNull(depositPeriod, "depositPeriod"); ArgChecker.notNull(convention, "convention"); return(IborFixingDepositTemplate.builder().depositPeriod(depositPeriod).convention(convention).build()); }
// creates an identifier private LegalEntityId(StandardId standardId) { this.standardId = ArgChecker.notNull(standardId, "standardId"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableValidator private void validate() private void validate() { ArgChecker.isFalse(depositPeriod.Negative, "Deposit Period must not be negative"); }
/// <summary> /// Init. /// </summary> public FontsHandler(RAdapter adapter) { ArgChecker.AssertArgNotNull(adapter, "global"); _adapter = adapter; }
/// <summary> /// Merges the specified date/value point into this builder. /// <para> /// The operator is invoked if the date already exists. /// /// </para> /// </summary> /// <param name="point"> the point to be added </param> /// <param name="operator"> the operator to use for merging </param> /// <returns> this builder </returns> public LocalDateDoubleTimeSeriesBuilder merge(LocalDateDoublePoint point, System.Func <double, double, double> @operator) { ArgChecker.notNull(point, "point"); entries.merge(point.Date, point.Value, (a, b) => @operator(a, b)); return(this); }
/// <summary> /// Adds a font family to be used. /// </summary> /// <param name="fontFamily">The font family to add.</param> public void AddFontFamily(RFontFamily fontFamily) { ArgChecker.AssertArgNotNull(fontFamily, "family"); _existingFontFamilies[fontFamily.Name] = fontFamily; }
/// <summary> /// Puts all the specified points into this builder. /// <para> /// The points are added one by one. /// If a date is duplicated it will overwrite an earlier entry. /// /// </para> /// </summary> /// <param name="points"> the points to be added </param> /// <returns> this builder </returns> public LocalDateDoubleTimeSeriesBuilder putAll(IList <LocalDateDoublePoint> points) { ArgChecker.notNull(points, "points"); return(putAll(points.stream())); }
/// <summary> /// Creates a selector that consists of the :not() pseudo-class with this selector as argument. /// </summary> /// <returns>The newly created selector.</returns> public CssSimpleSelector Negate() { ArgChecker.AssertIsTrue <InvalidOperationException>(!(this is CssNegationSelector), "Double negation of selectors is not allowed"); return(new CssNegationSelector(this)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableValidator private void validate() private void validate() { ArgChecker.inRange(scenarioIndex, 0, marketData.ScenarioCount, "scenarioIndex"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("synthetic-access") @Override public System.Nullable<double> apply(System.Nullable<double> x) public override double?apply(double?x) { ArgChecker.notNull(x, "x"); return((function(x + outerInstance.eps) - function(x)) / outerInstance.eps); }
//------------------------------------------------------------------------- public override double?apply(double?x) { ArgChecker.inRangeInclusive(x, 0d, 1d, "x"); double pp, p, t, h, w, lnA, lnB, u, a1 = _a - 1; double b1 = _b - 1; if (_a >= 1 && _b >= 1) { pp = x < 0.5 ? x.Value : 1 - x; t = Math.Sqrt(-2 * Math.Log(pp)); p = (2.30753 + t * 0.27061) / (1 + t * (0.99229 + t * 0.04481)) - t; if (p < 0.5) { p *= -1; } a1 = (Math.Sqrt(p) - 3.0) / 6.0; double tempA = 1.0 / (2 * _a - 1); double tempB = 1.0 / (2 * _b - 1); h = 2.0 / (tempA + tempB); w = p * Math.Sqrt(a1 + h) / h - (tempB - tempA) * (a1 + 5.0 / 6 - 2.0 / (3 * h)); p = _a / (_a + _b + Math.Exp(2 * w)); } else { lnA = Math.Log(_a / (_a + _b)); lnB = Math.Log(_b / (_a + _b)); t = Math.Exp(_a * lnA) / _a; u = Math.Exp(_b * lnB) / _b; w = t + u; if (x.Value < t / w) { p = Math.Pow(_a * w * x, 1.0 / _a); } else { p = 1 - Math.Pow(_b * w * (1 - x), 1.0 / _b); } } double afac = -_lnGamma.apply(_a) - _lnGamma.apply(_b) + _lnGamma.apply(_a + _b); double error; for (int j = 0; j < 10; j++) { if (DoubleMath.fuzzyEquals(p, 0d, 1e-16) || DoubleMath.fuzzyEquals(p, (double)1, 1e-16)) { throw new MathException("a or b too small for accurate evaluation"); } error = _beta.apply(p) - x; t = Math.Exp(a1 * Math.Log(p) + b1 * Math.Log(1 - p) + afac); u = error / t; t = u / (1 - 0.5 * Math.Min(1, u * (a1 / p - b1 / (1 - p)))); p -= t; if (p <= 0) { p = 0.5 * (p + t); } if (p >= 1) { p = 0.5 * (p + t + 1); } if (Math.Abs(t) < EPS * p && j > 0) { break; } } return(p); }
/// <summary> /// This regression method is private and called in other regression methods </summary> /// <param name="xData"> X values of data </param> /// <param name="yData"> Y values of data </param> /// <param name="degree"> Degree of polynomial which fits the given data </param> /// <param name="normalize"> Normalize xData by mean and standard deviation if normalize == true </param> /// <returns> LeastSquaresRegressionResult Containing optimal coefficients of the polynomial and difference between yData[i] and f(xData[i]) </returns> private LeastSquaresRegressionResult regress(double[] xData, double[] yData, int degree, bool normalize) { ArgChecker.notNull(xData, "xData"); ArgChecker.notNull(yData, "yData"); ArgChecker.isTrue(degree >= 0, "Minus degree"); ArgChecker.isTrue(xData.Length == yData.Length, "xData length should be the same as yData length"); ArgChecker.isTrue(xData.Length > degree, "Not enough amount of data"); int nData = xData.Length; for (int i = 0; i < nData; ++i) { ArgChecker.isFalse(double.IsNaN(xData[i]), "xData containing NaN"); ArgChecker.isFalse(double.IsInfinity(xData[i]), "xData containing Infinity"); ArgChecker.isFalse(double.IsNaN(yData[i]), "yData containing NaN"); ArgChecker.isFalse(double.IsInfinity(yData[i]), "yData containing Infinity"); } for (int i = 0; i < nData; ++i) { for (int j = i + 1; j < nData; ++j) { ArgChecker.isFalse(xData[i] == xData[j] && yData[i] != yData[j], "Two distinct data on x=const. line"); } } int nRepeat = 0; for (int i = 0; i < nData; ++i) { for (int j = i + 1; j < nData; ++j) { if (xData[i] == xData[j] && yData[i] == yData[j]) { ++nRepeat; } } } ArgChecker.isFalse(nRepeat > nData - degree - 1, "Too many repeated data"); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] tmpMatrix = new double[nData][degree + 1]; double[][] tmpMatrix = RectangularArrays.ReturnRectangularDoubleArray(nData, degree + 1); if (normalize == true) { double[] normData = normaliseData(xData); for (int i = 0; i < nData; ++i) { for (int j = 0; j < degree + 1; ++j) { tmpMatrix[i][j] = Math.Pow(normData[i], j); } } } else { for (int i = 0; i < nData; ++i) { for (int j = 0; j < degree + 1; ++j) { tmpMatrix[i][j] = Math.Pow(xData[i], j); } } } DoubleMatrix xDataMatrix = DoubleMatrix.copyOf(tmpMatrix); DoubleArray yDataVector = DoubleArray.copyOf(yData); double vandNorm = COMMONS_ALGEBRA.getNorm2(xDataMatrix); ArgChecker.isFalse(vandNorm > 1e9, "Too large input data or too many degrees"); return(regress(xDataMatrix, yDataVector, nData, degree)); }
public static double mod(ComplexNumber z) { ArgChecker.notNull(z, "z"); return(Math.hypot(z.Real, z.Imaginary)); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableValidator private void validate() private void validate() { ArgChecker.isTrue(fixedLeg.Currency.Equals(floatingLeg.Currency), Messages.format("Swap leg conventions must have same currency but found {} and {}, conventions {} and {}", fixedLeg.Currency, floatingLeg.Currency, fixedLeg, floatingLeg)); }
public static ComplexNumber multiply(ComplexNumber z, double x) { ArgChecker.notNull(z, "z"); return(new ComplexNumber(z.Real * x, z.Imaginary * x)); }
/// <summary> /// 指定の番号を用いてリテラルで使用するラベルの名前を作成します。 /// </summary> /// <param name="number">ラベル名の一部として使用する番号です。</param> /// <returns>作成したラベルの名前を返します。</returns> internal static String MakeLiteralLabelName(Int32 number) { ArgChecker.CheckRange(number, MinLiteralLabelNumber, MaxLiteralLabelNumber, nameof(number)); return(String.Format(LiteralLabelFormat, number)); }