예제 #1
0
 // ensure volatilities are Normal
 private NormalIborFutureOptionVolatilities checkNormalVols(IborFutureOptionVolatilities volatilities)
 {
     if (volatilities is NormalIborFutureOptionVolatilities)
     {
         return((NormalIborFutureOptionVolatilities)volatilities);
     }
     throw new System.ArgumentException(Messages.format("Ibor future option only supports Normal volatilities, but was '{}'", volatilities.VolatilityType));
 }
예제 #2
0
 // ensure volatilities are Black
 private BlackBondFutureVolatilities checkBlackVols(BondFutureVolatilities volatilities)
 {
     if (volatilities is BlackBondFutureVolatilities)
     {
         return((BlackBondFutureVolatilities)volatilities);
     }
     throw new System.ArgumentException(Messages.format("Bond future option only supports Black volatilities, but was '{}'", volatilities.VolatilityType));
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void validate(String name, java.io.File value) throws com.beust.jcommander.ParameterException
        public override void validate(string name, File value)
        {
            if (!value.exists())
            {
                throw new ParameterException(Messages.format("Invalid market data root directory: {}", value.AbsolutePath));
            }
            if (!value.Directory)
            {
                throw new ParameterException(Messages.format("Market data root must be a directory: {}", value.AbsolutePath));
            }
        }
        // parse an FxSingle
        internal static FxSingle parseFxSingle(CsvRow row, string prefix)
        {
            PayReceive direction1   = LoaderUtils.parsePayReceive(row.getValue(prefix + LEG_1_DIRECTION_FIELD));
            Currency   currency1    = Currency.of(row.getValue(prefix + LEG_1_CURRENCY_FIELD));
            double     notional1    = LoaderUtils.parseDouble(row.getValue(prefix + LEG_1_NOTIONAL_FIELD));
            LocalDate  paymentDate1 = row.findValue(prefix + LEG_1_PAYMENT_DATE_FIELD).map(str => LoaderUtils.parseDate(str)).orElseGet(() => LoaderUtils.parseDate(row.getValue(prefix + PAYMENT_DATE_FIELD)));
            PayReceive direction2   = LoaderUtils.parsePayReceive(row.getValue(prefix + LEG_2_DIRECTION_FIELD));
            Currency   currency2    = Currency.of(row.getValue(prefix + LEG_2_CURRENCY_FIELD));
            double     notional2    = LoaderUtils.parseDouble(row.getValue(prefix + LEG_2_NOTIONAL_FIELD));
            LocalDate  paymentDate2 = row.findValue(prefix + LEG_2_PAYMENT_DATE_FIELD).map(str => LoaderUtils.parseDate(str)).orElseGet(() => LoaderUtils.parseDate(row.getValue(prefix + PAYMENT_DATE_FIELD)));
            Optional <BusinessDayAdjustment> paymentAdj = parsePaymentDateAdjustment(row);

            if (direction1.Equals(direction2))
            {
                throw new System.ArgumentException(Messages.format("FxSingle legs must not have the same direction: {}, {}", direction1.ToString(), direction2.ToString()));
            }
            Payment payment1 = Payment.of(currency1, direction1.normalize(notional1), paymentDate1);
            Payment payment2 = Payment.of(currency2, direction2.normalize(notional2), paymentDate2);

            return(paymentAdj.map(adj => FxSingle.of(payment1, payment2, adj)).orElseGet(() => FxSingle.of(payment1, payment2)));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Parses the quantity.
        /// </summary>
        /// <param name="row">  the CSV row to parse </param>
        /// <returns> the quantity, long first, short second </returns>
        /// <exception cref="IllegalArgumentException"> if the row cannot be parsed </exception>
        public static DoublesPair parseQuantity(CsvRow row)
        {
            double?quantityOpt = row.findValue(QUANTITY_FIELD).map(s => LoaderUtils.parseDouble(s));

            if (quantityOpt.HasValue)
            {
                double quantity = quantityOpt.Value;
                return(DoublesPair.of(quantity >= 0 ? quantity : 0, quantity >= 0 ? 0 : -quantity));
            }
            double?longQuantityOpt  = row.findValue(LONG_QUANTITY_FIELD).map(s => LoaderUtils.parseDouble(s));
            double?shortQuantityOpt = row.findValue(SHORT_QUANTITY_FIELD).map(s => LoaderUtils.parseDouble(s));

            if (!longQuantityOpt.HasValue && !shortQuantityOpt.HasValue)
            {
                throw new System.ArgumentException(Messages.format("Security must contain a quantity column, either '{}' or '{}' and '{}'", QUANTITY_FIELD, LONG_QUANTITY_FIELD, SHORT_QUANTITY_FIELD));
            }
            double longQuantity  = ArgChecker.notNegative(longQuantityOpt.GetValueOrDefault(0d), LONG_QUANTITY_FIELD);
            double shortQuantity = ArgChecker.notNegative(shortQuantityOpt.GetValueOrDefault(0d), SHORT_QUANTITY_FIELD);

            return(DoublesPair.of(longQuantity, shortQuantity));
        }
예제 #6
0
 /// <summary>
 /// Creates an instance, specifying the definition that caused the problem.
 /// <para>
 /// The message is formatted using <seealso cref="Messages#format(String, Object...)"/>.
 /// Message formatting is null tolerant to avoid hiding this exception.
 ///
 /// </para>
 /// </summary>
 /// <param name="definition">  the invalid schedule definition, null tolerant </param>
 /// <param name="msgTemplate">  the message template, null tolerant </param>
 /// <param name="msgArguments">  the message arguments, null tolerant </param>
 public ScheduleException(PeriodicSchedule definition, string msgTemplate, params object[] msgArguments) : base(Messages.format(msgTemplate, msgArguments))
 {
     this.definition = definition;
 }