/// <include file='../docs.xml' /// path='docs/doc[@name="M:PeterO.PrecisionContext.#ctor(System.Int32,PeterO.Rounding,System.Int32,System.Int32,System.Boolean)"]/*'/> public PrecisionContext( int precision, Rounding rounding, int exponentMinSmall, int exponentMaxSmall, bool clampNormalExponents) { throw new NotSupportedException("This class is now obsolete."); }
public Currency(string name, string code, int numericCode, string symbol, string fractionSymbol, int fractionsPerUnit, Rounding rounding, string formatString, Currency triangulationCurrency) { _name = name; _code = code; _numeric = numericCode; _symbol = symbol; _fractionSymbol = fractionSymbol; _fractionsPerUnit = fractionsPerUnit; _rounding = rounding; _triangulated = triangulationCurrency; _formatString = formatString; }
public static PrecisionContext ForPrecisionAndRounding(int precision, Rounding rounding){ return new PrecisionContext(precision,rounding,0,0,false).WithUnlimitedExponents(); }
public static PrecisionContext ForRounding(Rounding rounding){ return new PrecisionContext(0,rounding,0,0,false).WithUnlimitedExponents(); }
/// <summary> Copies this PrecisionContext with the specified rounding /// mode. </summary> /// <returns>A PrecisionContext object.</returns> /// <param name='rounding'>A Rounding object.</param> public PrecisionContext WithRounding(Rounding rounding) { PrecisionContext pc = this.Copy(); pc.rounding = rounding; return pc; }
public override int DpToPixels(double dp, Rounding rounding = Rounding.Round) => (int)dp;
/// <summary> /// Sets the definition of how to round the option price, defaulted to no rounding. /// <para> /// The price is represented in decimal form, not percentage form. /// As such, the decimal places expressed by the rounding refers to this decimal form. /// </para> /// </summary> /// <param name="rounding"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder rounding(Rounding rounding) { JodaBeanUtils.notNull(rounding, "rounding"); this.rounding_Renamed = rounding; return(this); }
public Currency(string name, string code, int numericCode, string symbol, string fractionSymbol, int fractionsPerUnit, Rounding rounding, string formatString) : this(name, code, numericCode, symbol, fractionSymbol, fractionsPerUnit, rounding, formatString, new Currency()) { }
public void DecimalLengthTest() { Assert.AreEqual(10.26, Rounding.RoundToTwo(num)); }
public void RoundingValueAdjustedForMinTickOfZeroReturnsDefaultOfOneCent() { var result = Rounding.ValueAdjustedForMinTick(5.1234, 0); Assert.Equal(5.12, result); }
public void RoundingValueAdjustedForMinTickReturnsCorrectValues(double value, double minTick, double expected) { var result = Rounding.ValueAdjustedForMinTick(value, minTick); Assert.Equal(expected, result); }
public void testConversions() { InterestRateData[] cases = { // data from "Option Pricing Formulas", Haug, pag.181-182 // Rate,Compounding, Frequency, Time, Compounding2, Frequency2, Rate2, precision new InterestRateData(0.0800, Compounding.Compounded, Frequency.Quarterly, 1.00, Compounding.Continuous, Frequency.Annual, 0.0792, 4), new InterestRateData(0.1200, Compounding.Continuous, Frequency.Annual, 1.00, Compounding.Compounded, Frequency.Annual, 0.1275, 4), new InterestRateData(0.0800, Compounding.Compounded, Frequency.Quarterly, 1.00, Compounding.Compounded, Frequency.Annual, 0.0824, 4), new InterestRateData(0.0700, Compounding.Compounded, Frequency.Quarterly, 1.00, Compounding.Compounded, Frequency.Semiannual, 0.0706, 4), // undocumented, but reasonable :) new InterestRateData(0.0100, Compounding.Compounded, Frequency.Annual, 1.00, Compounding.Simple, Frequency.Annual, 0.0100, 4), new InterestRateData(0.0200, Compounding.Simple, Frequency.Annual, 1.00, Compounding.Compounded, Frequency.Annual, 0.0200, 4), new InterestRateData(0.0300, Compounding.Compounded, Frequency.Semiannual, 0.50, Compounding.Simple, Frequency.Annual, 0.0300, 4), new InterestRateData(0.0400, Compounding.Simple, Frequency.Annual, 0.50, Compounding.Compounded, Frequency.Semiannual, 0.0400, 4), new InterestRateData(0.0500, Compounding.Compounded, Frequency.EveryFourthMonth, 1.0 / 3, Compounding.Simple, Frequency.Annual, 0.0500, 4), new InterestRateData(0.0600, Compounding.Simple, Frequency.Annual, 1.0 / 3, Compounding.Compounded, Frequency.EveryFourthMonth, 0.0600, 4), new InterestRateData(0.0500, Compounding.Compounded, Frequency.Quarterly, 0.25, Compounding.Simple, Frequency.Annual, 0.0500, 4), new InterestRateData(0.0600, Compounding.Simple, Frequency.Annual, 0.25, Compounding.Compounded, Frequency.Quarterly, 0.0600, 4), new InterestRateData(0.0700, Compounding.Compounded, Frequency.Bimonthly, 1.0 / 6, Compounding.Simple, Frequency.Annual, 0.0700, 4), new InterestRateData(0.0800, Compounding.Simple, Frequency.Annual, 1.0 / 6, Compounding.Compounded, Frequency.Bimonthly, 0.0800, 4), new InterestRateData(0.0900, Compounding.Compounded, Frequency.Monthly, 1.0 / 12, Compounding.Simple, Frequency.Annual, 0.0900, 4), new InterestRateData(0.1000, Compounding.Simple, Frequency.Annual, 1.0 / 12, Compounding.Compounded, Frequency.Monthly, 0.1000, 4), new InterestRateData(0.0300, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.25, Compounding.Simple, Frequency.Annual, 0.0300, 4), new InterestRateData(0.0300, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.25, Compounding.Simple, Frequency.Semiannual, 0.0300, 4), new InterestRateData(0.0300, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.25, Compounding.Simple, Frequency.Quarterly, 0.0300, 4), new InterestRateData(0.0300, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.50, Compounding.Simple, Frequency.Annual, 0.0300, 4), new InterestRateData(0.0300, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.50, Compounding.Simple, Frequency.Semiannual, 0.0300, 4), new InterestRateData(0.0300, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.75, Compounding.Compounded, Frequency.Semiannual, 0.0300, 4), new InterestRateData(0.0400, Compounding.Simple, Frequency.Semiannual, 0.25, Compounding.SimpleThenCompounded, Frequency.Quarterly, 0.0400, 4), new InterestRateData(0.0400, Compounding.Simple, Frequency.Semiannual, 0.25, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.0400, 4), new InterestRateData(0.0400, Compounding.Simple, Frequency.Semiannual, 0.25, Compounding.SimpleThenCompounded, Frequency.Annual, 0.0400, 4), new InterestRateData(0.0400, Compounding.Compounded, Frequency.Quarterly, 0.50, Compounding.SimpleThenCompounded, Frequency.Quarterly, 0.0400, 4), new InterestRateData(0.0400, Compounding.Simple, Frequency.Semiannual, 0.50, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.0400, 4), new InterestRateData(0.0400, Compounding.Simple, Frequency.Semiannual, 0.50, Compounding.SimpleThenCompounded, Frequency.Annual, 0.0400, 4), new InterestRateData(0.0400, Compounding.Compounded, Frequency.Quarterly, 0.75, Compounding.SimpleThenCompounded, Frequency.Quarterly, 0.0400, 4), new InterestRateData(0.0400, Compounding.Compounded, Frequency.Semiannual, 0.75, Compounding.SimpleThenCompounded, Frequency.Semiannual, 0.0400, 4), new InterestRateData(0.0400, Compounding.Simple, Frequency.Semiannual, 0.75, Compounding.SimpleThenCompounded, Frequency.Annual, 0.0400, 4) }; Rounding roundingPrecision; double r3; double r2; Date d1 = Date.Today; Date d2; InterestRate ir; InterestRate ir2; InterestRate ir3; InterestRate expectedIR; double compoundf; double error; double disc; for (int i = 0; i < cases.Length - 1; i++) { ir = new InterestRate(cases[i].r, new Actual360(), cases[i].comp, cases[i].freq); d2 = d1 + new Period((int)(360 * cases[i].t + 0.5), TimeUnit.Days); roundingPrecision = new Rounding(cases[i].precision); // check that the compound factor is the inverse of the discount factor compoundf = ir.compoundFactor(d1, d2); disc = ir.discountFactor(d1, d2); error = Math.Abs(disc - 1.0 / compoundf); if (error > 1e-15) { QAssert.Fail(ir + " 1.0/compound_factor: " + 1.0 / compoundf); } // check that the equivalent InterestRate with *same* daycounter, // compounding, and frequency is the *same* InterestRate //ir2 = ir.equivalentRate(d1, d2, ir.dayCounter(), ir.compounding(), ir.frequency()); ir2 = ir.equivalentRate(ir.dayCounter(), ir.compounding(), ir.frequency(), d1, d2); error = Math.Abs(ir.rate() - ir2.rate()); if (error > 1e-15) { QAssert.Fail("original interest rate: " + ir + " equivalent interest rate: " + ir2 + " rate error: " + error); } if (ir.dayCounter() != ir2.dayCounter()) { QAssert.Fail("day counter error original interest rate: " + ir + " equivalent interest rate: " + ir2); } if (ir.compounding() != ir2.compounding()) { QAssert.Fail("compounding error original interest rate: " + ir + " equivalent interest rate: " + ir2); } if (ir.frequency() != ir2.frequency()) { QAssert.Fail("frequency error original interest rate: " + ir + " equivalent interest rate: " + ir2); } // check that the equivalent rate with *same* daycounter, // compounding, and frequency is the *same* rate //r2 = ir.equivalentRate(d1, d2, ir.dayCounter(), ir.compounding(), ir.frequency()).rate(); r2 = ir.equivalentRate(ir.dayCounter(), ir.compounding(), ir.frequency(), d1, d2).value(); error = Math.Abs(ir.rate() - r2); if (error > 1e-15) { QAssert.Fail("original rate: " + ir + " equivalent rate: " + r2 + " error: " + error); } // check that the equivalent InterestRate with *different* // compounding, and frequency is the *expected* InterestRate //ir3 = ir.equivalentRate(d1, d2, ir.dayCounter(), cases[i].comp2, cases[i].freq2); ir3 = ir.equivalentRate(ir.dayCounter(), cases[i].comp2, cases[i].freq2, d1, d2); expectedIR = new InterestRate(cases[i].expected, ir.dayCounter(), cases[i].comp2, cases[i].freq2); r3 = roundingPrecision.Round(ir3.rate()); error = Math.Abs(r3 - expectedIR.rate()); if (error > 1.0e-17) { QAssert.Fail("original interest rate: " + ir + " calculated equivalent interest rate: " + ir3 + " truncated equivalent rate: " + r3 + " expected equivalent interest rate: " + expectedIR + " rate error: " + error); } if (ir3.dayCounter() != expectedIR.dayCounter()) { QAssert.Fail("day counter error original interest rate: " + ir3 + " equivalent interest rate: " + expectedIR); } if (ir3.compounding() != expectedIR.compounding()) { QAssert.Fail("compounding error original interest rate: " + ir3 + " equivalent interest rate: " + expectedIR); } if (ir3.frequency() != expectedIR.frequency()) { QAssert.Fail("frequency error original interest rate: " + ir3 + " equivalent interest rate: " + expectedIR); } // check that the equivalent rate with *different* // compounding, and frequency is the *expected* rate //r3 = ir.equivalentRate(d1, d2, ir.dayCounter(), cases[i].comp2, cases[i].freq2).rate(); r3 = ir.equivalentRate(ir.dayCounter(), cases[i].comp2, cases[i].freq2, d1, d2).value(); r3 = roundingPrecision.Round(r3); error = Math.Abs(r3 - cases[i].expected); if (error > 1.0e-17) { QAssert.Fail("calculated equivalent rate: " + r3 + " expected equivalent rate: " + cases[i].expected + " error: " + error); } } }
/// <summary> /// Creates an instance. </summary> /// <param name="securityId"> the value of the property, not null </param> /// <param name="putCall"> the value of the property </param> /// <param name="strikePrice"> the value of the property </param> /// <param name="expiryDate"> the value of the property, not null </param> /// <param name="expiryTime"> the value of the property, not null </param> /// <param name="expiryZone"> the value of the property, not null </param> /// <param name="premiumStyle"> the value of the property, not null </param> /// <param name="rounding"> the value of the property, not null </param> /// <param name="underlyingFuture"> the value of the property, not null </param> internal IborFutureOption(SecurityId securityId, PutCall putCall, double strikePrice, LocalDate expiryDate, LocalTime expiryTime, ZoneId expiryZone, FutureOptionPremiumStyle premiumStyle, Rounding rounding, IborFuture underlyingFuture) { JodaBeanUtils.notNull(securityId, "securityId"); JodaBeanUtils.notNull(expiryDate, "expiryDate"); JodaBeanUtils.notNull(expiryTime, "expiryTime"); JodaBeanUtils.notNull(expiryZone, "expiryZone"); JodaBeanUtils.notNull(premiumStyle, "premiumStyle"); JodaBeanUtils.notNull(rounding, "rounding"); JodaBeanUtils.notNull(underlyingFuture, "underlyingFuture"); this.securityId = securityId; this.putCall = putCall; this.strikePrice = strikePrice; this.expiryDate = expiryDate; this.expiryTime = expiryTime; this.expiryZone = expiryZone; this.premiumStyle = premiumStyle; this.rounding = rounding; this.underlyingFuture = underlyingFuture; validate(); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableDefaults private static void applyDefaults(Builder builder) private static void applyDefaults(Builder builder) { builder.rounding(Rounding.none()); }
/// <summary> Initializes a new PrecisionContext. HasFlags will be /// set to false. </summary> public PrecisionContext(int precision, Rounding rounding, int exponentMinSmall, int exponentMaxSmall, bool clampNormalExponents) { if ((precision) < 0) throw new ArgumentException("precision" + " not greater or equal to " + "0" + " (" + Convert.ToString((precision),System.Globalization.CultureInfo.InvariantCulture) + ")"); if ((exponentMinSmall) > exponentMaxSmall) throw new ArgumentException("exponentMinSmall" + " not less or equal to " + Convert.ToString((exponentMaxSmall),System.Globalization.CultureInfo.InvariantCulture) + " (" + Convert.ToString((exponentMinSmall),System.Globalization.CultureInfo.InvariantCulture) + ")"); this.bigintPrecision = precision==0 ? BigInteger.Zero : (BigInteger)precision; this.rounding = rounding; this.clampNormalExponents = clampNormalExponents; this.hasExponentRange=true; exponentMax = exponentMaxSmall==0 ? BigInteger.Zero : (BigInteger)exponentMaxSmall; exponentMin = exponentMinSmall==0 ? BigInteger.Zero : (BigInteger)exponentMinSmall; }
public Rounding rounding() { Rounding ret = new Rounding(NQuantLibcPINVOKE.Currency_rounding(swigCPtr), false); if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public void RoundToFourTest() { Assert.AreEqual(1.8744, Rounding.RoundToFour(x)); }
public void RoundToFiveTest() { Assert.AreEqual(6.89746, Rounding.RoundToFive(y)); }
public ExchangeRate CalculateFromConversionRate(ConversionRate conversionRate, DateTime timstampUtc, Rounding rounding) { Argument.NotNull(conversionRate, "conversionRate"); var baseCurrency = _currencyRepository.Find(conversionRate.Conversion.From); if (baseCurrency == null) { var message = string.Format("Can't find currency [{0}] in the database.", conversionRate.Conversion.From); throw new InvalidOperationException(message); } var foreignCurrency = _currencyRepository.Find(conversionRate.Conversion.To); if (foreignCurrency == null) { var message = string.Format("Can't find currency [{0}] in the database.", conversionRate.Conversion.To); throw new InvalidOperationException(message); } var buyRate = MoneyMath.Round(conversionRate.Rate * (decimal)Randomizer.FromRange(_settings.BuyRateCoefficientRange), rounding); var sellRate = MoneyMath.Round(conversionRate.Rate * (decimal)Randomizer.FromRange(_settings.SellRateCoefficientRange), rounding); return(ExchangeRate.Create(baseCurrency, foreignCurrency, buyRate, sellRate, timstampUtc)); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rounding obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }