예제 #1
0
 private Failure(FailureReason reason, string message, ISet <FailureItem> items)
 {
     JodaBeanUtils.notNull(reason, "reason");
     JodaBeanUtils.notEmpty(message, "message");
     JodaBeanUtils.notEmpty(items, "items");
     this.reason  = reason;
     this.message = message;
     this.items   = ImmutableSet.copyOf(items);
 }
예제 #2
0
 private RatesCurveGroupEntry(CurveName curveName, ISet <Currency> discountCurrencies, ISet <Index> indices)
 {
     JodaBeanUtils.notNull(curveName, "curveName");
     JodaBeanUtils.notNull(discountCurrencies, "discountCurrencies");
     JodaBeanUtils.notNull(indices, "indices");
     this.curveName          = curveName;
     this.discountCurrencies = ImmutableSet.copyOf(discountCurrencies);
     this.indices            = ImmutableSet.copyOf(indices);
 }
 //-------------------------------------------------------------------------
 public FunctionRequirements requirements(ISet <IborIndex> indices)
 {
     foreach (Index index in indices)
     {
         if (!volatilityIds.Keys.Contains(index))
         {
             throw new System.ArgumentException(msgIndexNotFound(index));
         }
     }
     return(FunctionRequirements.builder().valueRequirements(ImmutableSet.copyOf(volatilityIds.values())).build());
 }
예제 #4
0
 //-------------------------------------------------------------------------
 public FunctionRequirements requirements(ISet <CurrencyPair> currencyPairs)
 {
     foreach (CurrencyPair currencyPair in currencyPairs)
     {
         if (!volatilityIds.Keys.Contains(currencyPair))
         {
             throw new System.ArgumentException(msgPairNotFound(currencyPair));
         }
     }
     return(FunctionRequirements.builder().valueRequirements(ImmutableSet.copyOf(volatilityIds.values())).build());
 }
 private PortfolioItemSummary(StandardId id, PortfolioItemType portfolioItemType, ProductType productType, ISet <Currency> currencies, string description)
 {
     JodaBeanUtils.notNull(portfolioItemType, "portfolioItemType");
     JodaBeanUtils.notNull(productType, "productType");
     JodaBeanUtils.notNull(currencies, "currencies");
     JodaBeanUtils.notBlank(description, "description");
     this.id = id;
     this.portfolioItemType = portfolioItemType;
     this.productType       = productType;
     this.currencies        = ImmutableSet.copyOf(currencies);
     this.description       = description;
 }
예제 #6
0
        /// <summary>
        /// Obtains a failure for a non-empty collection of failure items.
        /// </summary>
        /// <param name="items">  the failures, not empty </param>
        /// <returns> the failure </returns>
        public static Failure of(ICollection <FailureItem> items)
        {
            ArgChecker.notEmpty(items, "items");
            ISet <FailureItem> itemSet = ImmutableSet.copyOf(items);
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            string message = itemSet.Select(FailureItem::getMessage).collect(Collectors.joining(", "));
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            FailureReason reason = itemSet.Select(FailureItem::getReason).Aggregate((s1, s2) => s1 == s2 ? s1 : FailureReason.MULTIPLE).get();

            return(new Failure(reason, message, itemSet));
        }
        /// <summary>
        /// Obtains a combined holiday calendar instance.
        /// <para>
        /// This combines the two input calendars.
        /// It is intended for up-front occasional use rather than continuous use, as it can be relatively slow.
        ///
        /// </para>
        /// </summary>
        /// <param name="cal1">  the first calendar </param>
        /// <param name="cal2">  the second calendar </param>
        /// <returns> the combined calendar </returns>
        public static ImmutableHolidayCalendar combined(ImmutableHolidayCalendar cal1, ImmutableHolidayCalendar cal2)
        {
            // do not override combinedWith(), as this is too slow
            if (cal1 == cal2)
            {
                return(ArgChecker.notNull(cal1, "cal1"));
            }
            HolidayCalendarId newId = cal1.id.combinedWith(cal2.id);

            // use slow version if lookup arrays do not overlap
            int endYear1 = cal1.startYear + cal1.lookup.Length / 12;
            int endYear2 = cal2.startYear + cal2.lookup.Length / 12;

            if (endYear1 < cal2.startYear || endYear2 < cal1.startYear)
            {
                ImmutableSortedSet <LocalDate> newHolidays = ImmutableSortedSet.copyOf(Iterables.concat(cal1.Holidays, cal2.Holidays));
                ImmutableSet <DayOfWeek>       newWeekends = ImmutableSet.copyOf(Iterables.concat(cal1.WeekendDays, cal2.WeekendDays));
                return(of(newId, newHolidays, newWeekends));
            }

            // merge calendars using bitwise operations
            // figure out which has the lower start year and use that as the base
            bool cal1Lower = cal1.startYear <= cal2.startYear;

            int[] lookup1        = cal1Lower ? cal1.lookup : cal2.lookup;
            int[] lookup2        = cal1Lower ? cal2.lookup : cal1.lookup;
            int   newStartYear   = cal1Lower ? cal1.startYear : cal2.startYear;
            int   otherStartYear = cal1Lower ? cal2.startYear : cal1.startYear;
            // copy base array and map data from the other on top
            int newSize = Math.Max(lookup1.Length, lookup2.Length + (otherStartYear - newStartYear) * 12);
            int offset  = (otherStartYear - newStartYear) * 12;

            int[] newLookup = Arrays.copyOf(lookup1, newSize);
            for (int i = 0; i < lookup2.Length; i++)
            {
                newLookup[i + offset] &= lookup2[i];         // use & because 1 = business day (not holiday)
            }
            int newWeekends = cal1.weekends | cal2.weekends; // use | because 1 = weekend day

            return(new ImmutableHolidayCalendar(newId, newWeekends, newStartYear, newLookup, false));
        }
        //-------------------------------------------------------------------------
        private void assertMCA(MultiCurrencyAmount actual, params CurrencyAmount[] expected)
        {
            assertEquals(actual.size(), expected.Length);
            assertEquals(actual.Amounts.size(), expected.Length);
            assertEquals(actual.Amounts, ImmutableSet.copyOf(expected));
            ISet <Currency> currencies = new HashSet <Currency>();

            foreach (CurrencyAmount expectedAmount in expected)
            {
                currencies.Add(expectedAmount.Currency);
                assertEquals(actual.contains(expectedAmount.Currency), true);
                assertEquals(actual.getAmount(expectedAmount.Currency), expectedAmount);
                assertEquals(actual.getAmountOrZero(expectedAmount.Currency), expectedAmount);
            }
            assertEquals(actual.Currencies, currencies);
            Currency nonExisting = Currency.of("FRZ");

            assertEquals(actual.contains(nonExisting), false);
            assertThrowsIllegalArg(() => actual.getAmount(nonExisting));
            assertEquals(actual.getAmountOrZero(nonExisting), CurrencyAmount.zero(nonExisting));
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Creates a summary instance for a position.
 /// </summary>
 /// <param name="position">  the position </param>
 /// <param name="type">  the type </param>
 /// <param name="description">  the description </param>
 /// <param name="currencies">  the currencies, may be empty </param>
 /// <returns> the string form </returns>
 public static PortfolioItemSummary summary(Position position, ProductType type, string description, params Currency[] currencies)
 {
     return(PortfolioItemSummary.of(position.Id.orElse(null), PortfolioItemType.POSITION, type, ImmutableSet.copyOf(currencies), description));
 }
예제 #10
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Returns the set of keys of this property set.
 /// <para>
 /// The iteration order of the map matches that of the input data.
 ///
 /// </para>
 /// </summary>
 /// <returns> the set of keys </returns>
 public ImmutableSet <string> keys()
 {
     return(ImmutableSet.copyOf(keyValueMap.Keys));
 }
 /// <summary>
 /// Sets the {@code currencies} property in the builder
 /// from an array of objects. </summary>
 /// <param name="currencies">  the new value, not null </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder currencies(params Currency[] currencies)
 {
     return(this.currencies(ImmutableSet.copyOf(currencies)));
 }
예제 #12
0
 /// <summary>
 /// Sets the {@code discountCurrencies} property in the builder
 /// from an array of objects. </summary>
 /// <param name="discountCurrencies">  the new value, not null </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder discountCurrencies(params Currency[] discountCurrencies)
 {
     return(this.discountCurrencies(ImmutableSet.copyOf(discountCurrencies)));
 }
예제 #13
0
 /// <summary>
 /// Creates a new function which calculates one measure for targets of one type.
 /// </summary>
 /// <param name="targetType">  the target type handled by the function, often a trade </param>
 /// <param name="measure">  the measure calculated by the function </param>
 /// <param name="requiredMeasures">  the measures required as inputs to the calculation </param>
 protected internal AbstractDerivedCalculationFunction(Type <T> targetType, Measure measure, ISet <Measure> requiredMeasures)
 {
     this.measure_Renamed          = measure;
     this.requiredMeasures_Renamed = ImmutableSet.copyOf(requiredMeasures);
     this.targetType_Renamed       = targetType;
 }
예제 #14
0
 /// <summary>
 /// Creates a new function which calculates one measure for targets of one type.
 /// </summary>
 /// <param name="targetType">  the target type handled by the function, often a trade </param>
 /// <param name="measure">  the measure calculated by the function </param>
 /// <param name="requiredMeasures">  the measures required as inputs to the calculation </param>
 protected internal AbstractDerivedCalculationFunction(Type <T> targetType, Measure measure, params Measure[] requiredMeasures) : this(targetType, measure, ImmutableSet.copyOf(requiredMeasures))
 {
 }
예제 #15
0
 /// <summary>
 /// Sets the {@code indices} property in the builder
 /// from an array of objects. </summary>
 /// <param name="indices">  the new value, not null </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder indices(params Index[] indices)
 {
     return(this.indices(ImmutableSet.copyOf(indices)));
 }
 /// <summary>
 /// Creates a summary instance for a trade.
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="type">  the type </param>
 /// <param name="description">  the description </param>
 /// <param name="currencies">  the currencies, may be empty </param>
 /// <returns> the string form </returns>
 public static PortfolioItemSummary summary(Trade trade, ProductType type, string description, params Currency[] currencies)
 {
     return(PortfolioItemSummary.of(trade.Id.orElse(null), PortfolioItemType.TRADE, type, ImmutableSet.copyOf(currencies), description));
 }
예제 #17
0
 public ISet <Measure> supportedMeasures()
 {
     // pass all measures here so that the calculation is run to get the correct error message
     return(ImmutableSet.copyOf(Measure.extendedEnum().lookupAllNormalized().values()));
 }
예제 #18
0
        /// <summary>
        /// Adds the definition of a discount curve to the curve group definition.
        /// <para>
        /// A curve added with this method cannot be calibrated by the market data system as it does not include
        /// a curve definition. It is intended to be used with curves which are supplied by the user.
        ///
        /// </para>
        /// </summary>
        /// <param name="curveName">  the name of the curve </param>
        /// <param name="otherCurrencies">  additional currencies for which the curve can provide discount factors </param>
        /// <param name="currency">  the currency for which the curve provides discount rates </param>
        /// <returns> this builder </returns>
        public RatesCurveGroupDefinitionBuilder addDiscountCurve(CurveName curveName, Currency currency, params Currency[] otherCurrencies)
        {
            ArgChecker.notNull(curveName, "curveName");
            ArgChecker.notNull(currency, "currency");
            RatesCurveGroupEntry entry = RatesCurveGroupEntry.builder().curveName(curveName).discountCurrencies(ImmutableSet.copyOf(Lists.asList(currency, otherCurrencies))).build();

            return(mergeEntry(entry));
        }