// parses the public static final constants
        private static NamedLookup <R> parseConstants <R>(Type <R> enumType, Type constantsType) where R : Named
        {
            System.Reflection.FieldInfo[] fields    = constantsType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
            IDictionary <string, R>       instances = new Dictionary <string, R>();

            foreach (System.Reflection.FieldInfo field in fields)
            {
                if (Modifier.isPublic(field.Modifiers) && Modifier.isStatic(field.Modifiers) && Modifier.isFinal(field.Modifiers) && enumType.IsAssignableFrom(field.Type))
                {
                    if (Modifier.isPublic(constantsType.Modifiers) == false)
                    {
                        field.Accessible = true;
                    }
                    try
                    {
                        R instance = enumType.cast(field.get(null));
                        if (!instances.ContainsKey(instance.Name))
                        {
                            instances.Add(instance.Name, instance);
                        }
                        if (!instances.ContainsKey(instance.Name.ToUpper(Locale.ENGLISH)))
                        {
                            instances.Add(instance.Name.ToUpper(Locale.ENGLISH), instance);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new System.ArgumentException("Unable to query field: " + field, ex);
                    }
                }
            }
            ImmutableMap <string, R> constants = ImmutableMap.copyOf(instances);

            return(new NamedLookupAnonymousInnerClass(constants));
        }
 /// <summary>
 /// Creates an instance. </summary>
 /// <param name="configs">  the value of the property, not null </param>
 /// <param name="defaultConfigs">  the value of the property, not null </param>
 internal MarketDataConfig(IDictionary <Type, SingleTypeMarketDataConfig> configs, IDictionary <Type, object> defaultConfigs)
 {
     JodaBeanUtils.notNull(configs, "configs");
     JodaBeanUtils.notNull(defaultConfigs, "defaultConfigs");
     this.configs        = ImmutableMap.copyOf(configs);
     this.defaultConfigs = ImmutableMap.copyOf(defaultConfigs);
 }
        // the input map is treated as being ordered
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ImmutableConstructor private CalculationParameters(java.util.Map<Class, CalculationParameter> parameters)
        private CalculationParameters(IDictionary <Type, CalculationParameter> parameters)
        {
            JodaBeanUtils.notNull(parameters, "parameters");
            this.parameters = ImmutableMap.copyOf(parameters);
            // find parameters that are super-interfaces of the specified objects
            IDictionary <Type, Type> aliases = new Dictionary <Type, Type>();

            foreach (Type type in parameters.Keys)
            {
                Type[] interfaces = type.GetInterfaces();
                foreach (Type iface in interfaces)
                {
                    if (iface != typeof(CalculationParameter) && iface.IsAssignableFrom(typeof(CalculationParameter)) && !parameters.ContainsKey(iface))
                    {
                        // first registration wins with aliases
                        Type aliasType = iface.asSubclass(typeof(CalculationParameter));
                        if (!aliases.ContainsKey(aliasType))
                        {
                            aliases.Add(aliasType, type);
                        }
                    }
                }
            }
            this.aliases = ImmutableMap.copyOf(aliases);
        }
 private CurveSensitivities(PortfolioItemInfo info, IDictionary <CurveSensitivitiesType, CurrencyParameterSensitivities> typedSensitivities)
 {
     JodaBeanUtils.notNull(info, "info");
     JodaBeanUtils.notNull(typedSensitivities, "typedSensitivities");
     this.info = info;
     this.typedSensitivities = ImmutableMap.copyOf(typedSensitivities);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates an instance. </summary>
 /// <param name="currencies">  the value of the property, not null </param>
 /// <param name="rates">  the value of the property, not null </param>
 internal FxMatrix(IDictionary <Currency, int> currencies, DoubleMatrix rates)
 {
     JodaBeanUtils.notNull(currencies, "currencies");
     JodaBeanUtils.notNull(rates, "rates");
     this.currencies = ImmutableMap.copyOf(currencies);
     this.rates      = rates;
 }
 private SingleTypeMarketDataConfig(Type configType, IDictionary <string, object> configObjects)
 {
     JodaBeanUtils.notNull(configType, "configType");
     JodaBeanUtils.notNull(configObjects, "configObjects");
     this.configType    = configType;
     this.configObjects = ImmutableMap.copyOf(configObjects);
 }
Ejemplo n.º 7
0
        //-------------------------------------------------------------------------
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @VisibleForTesting static com.google.common.collect.ImmutableMap<String, HolidayCalendar> loadFromIni(String filename)
        internal static ImmutableMap <string, HolidayCalendar> loadFromIni(string filename)
        {
            IList <ResourceLocator> resources         = ResourceConfig.orderedResources(filename);
            IDictionary <string, HolidayCalendar> map = new Dictionary <string, HolidayCalendar>();

            foreach (ResourceLocator resource in resources)
            {
                try
                {
                    IniFile ini = IniFile.of(resource.CharSource);
                    foreach (string sectionName in ini.sections())
                    {
                        PropertySet     section = ini.section(sectionName);
                        HolidayCalendar parsed  = parseHolidayCalendar(sectionName, section);
                        map[parsed.Name] = parsed;
                        if (!map.ContainsKey(parsed.Name.ToUpper(Locale.ENGLISH)))
                        {
                            map.Add(parsed.Name.ToUpper(Locale.ENGLISH), parsed);
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.log(Level.SEVERE, "Error processing resource as Holiday Calendar INI file: " + resource, ex);
                    return(ImmutableMap.of());
                }
            }
            return(ImmutableMap.copyOf(map));
        }
 private JumpToDefault(Currency currency, IDictionary <StandardId, double> amounts)
 {
     JodaBeanUtils.notNull(currency, "currency");
     JodaBeanUtils.notNull(amounts, "amounts");
     this.currency = currency;
     this.amounts  = ImmutableMap.copyOf(amounts);
 }
Ejemplo n.º 9
0
        private static ImmutableMap <string, OvernightIndex> loadFromCsv()
        {
            IList <ResourceLocator> resources        = ResourceConfig.orderedResources("OvernightIndexData.csv");
            IDictionary <string, OvernightIndex> map = new Dictionary <string, OvernightIndex>();

            foreach (ResourceLocator resource in resources)
            {
                try
                {
                    CsvFile csv = CsvFile.of(resource.CharSource, true);
                    foreach (CsvRow row in csv.rows())
                    {
                        OvernightIndex parsed = parseOvernightIndex(row);
                        map[parsed.Name] = parsed;
                        if (!map.ContainsKey(parsed.Name.ToUpper(Locale.ENGLISH)))
                        {
                            map.Add(parsed.Name.ToUpper(Locale.ENGLISH), parsed);
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.log(Level.SEVERE, "Error processing resource as Overnight Index CSV file: " + resource, ex);
                    return(ImmutableMap.of());
                }
            }
            return(ImmutableMap.copyOf(map));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates an instance. </summary>
 /// <param name="shiftType">  the value of the property, not null </param>
 /// <param name="shifts">  the value of the property, not null </param>
 /// <param name="nodeIndices">  the value of the property, not null </param>
 internal PointShifts(ShiftType shiftType, DoubleMatrix shifts, IDictionary <object, int> nodeIndices)
 {
     JodaBeanUtils.notNull(shiftType, "shiftType");
     JodaBeanUtils.notNull(shifts, "shifts");
     JodaBeanUtils.notNull(nodeIndices, "nodeIndices");
     this.shiftType   = shiftType;
     this.shifts      = shifts;
     this.nodeIndices = ImmutableMap.copyOf(nodeIndices);
 }
Ejemplo n.º 11
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Creates an instance, based on the specified element.
 /// <para>
 /// The map of references is used to link one part of the XML to another.
 /// For example, if one part of the XML has {@code <foo id="fooId">}, the references
 /// map will contain an entry mapping "fooId" to the parsed element {@code <foo>}.
 ///
 /// </para>
 /// </summary>
 /// <param name="fpmlRootEl">  the source of the FpML XML document </param>
 /// <param name="references">  the map of id/href to referenced element </param>
 /// <param name="ourPartySelector">  the selector used to find "our" party within the set of parties in the FpML document </param>
 /// <param name="tradeInfoParser">  the trade info parser </param>
 /// <param name="refData">  the reference data to use </param>
 public FpmlDocument(XmlElement fpmlRootEl, IDictionary <string, XmlElement> references, FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, ReferenceData refData)
 {
     this.fpmlRoot        = fpmlRootEl;
     this.references      = ImmutableMap.copyOf(references);
     this.parties         = parseParties(fpmlRootEl);
     this.ourPartyHrefIds = findOurParty(ourPartySelector);
     this.tradeInfoParser = tradeInfoParser;
     this.refData         = refData;
 }
 private TradeCounterpartyCalculationParameter(Type queryType, IDictionary <StandardId, CalculationParameter> parameters, CalculationParameter defaultParameter)
 {
     JodaBeanUtils.notNull(queryType, "queryType");
     JodaBeanUtils.notNull(parameters, "parameters");
     JodaBeanUtils.notNull(defaultParameter, "defaultParameter");
     this.queryType_Renamed = queryType;
     this.parameters        = ImmutableMap.copyOf(parameters);
     this.defaultParameter  = defaultParameter;
 }
Ejemplo n.º 13
0
 private LegalEntityCurveGroup(CurveGroupName name, IDictionary <Pair <RepoGroup, Currency>, Curve> repoCurves, IDictionary <Pair <LegalEntityGroup, Currency>, Curve> issuerCurves)
 {
     JodaBeanUtils.notNull(name, "name");
     JodaBeanUtils.notNull(repoCurves, "repoCurves");
     JodaBeanUtils.notNull(issuerCurves, "issuerCurves");
     this.name         = name;
     this.repoCurves   = ImmutableMap.copyOf(repoCurves);
     this.issuerCurves = ImmutableMap.copyOf(issuerCurves);
 }
            // parse the config file FloatingRateName.ini
            internal static ImmutableMap <string, FloatingRateName> parseIndices(IniFile ini)
            {
                Dictionary <string, ImmutableFloatingRateName> map = new Dictionary <string, ImmutableFloatingRateName>();

                parseSection(ini.section("ibor"), "-", FloatingRateType.IBOR, map);
                parseFixingDateOffset(ini.section("iborFixingDateOffset"), map);
                parseSection(ini.section("overnightCompounded"), "", FloatingRateType.OVERNIGHT_COMPOUNDED, map);
                parseSection(ini.section("overnightAveraged"), "", FloatingRateType.OVERNIGHT_AVERAGED, map);
                parseSection(ini.section("price"), "", FloatingRateType.PRICE, map);
                return(ImmutableMap.copyOf(map));
            }
 private DefaultCreditRatesMarketDataLookup(IDictionary <Pair <StandardId, Currency>, CurveId> creditCurveIds, IDictionary <Currency, CurveId> discountCurveIds, IDictionary <StandardId, CurveId> recoveryRateCurveIds, ObservableSource observableSource)
 {
     JodaBeanUtils.notNull(creditCurveIds, "creditCurveIds");
     JodaBeanUtils.notNull(discountCurveIds, "discountCurveIds");
     JodaBeanUtils.notNull(recoveryRateCurveIds, "recoveryRateCurveIds");
     JodaBeanUtils.notNull(observableSource, "observableSource");
     this.creditCurveIds       = ImmutableMap.copyOf(creditCurveIds);
     this.discountCurveIds     = ImmutableMap.copyOf(discountCurveIds);
     this.recoveryRateCurveIds = ImmutableMap.copyOf(recoveryRateCurveIds);
     this.observableSource     = observableSource;
 }
Ejemplo n.º 16
0
        //-------------------------------------------------------------------------
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ImmutableConstructor private FailureItem(FailureReason reason, String message, java.util.Map<String, String> attributes, String stackTrace, Class causeType)
        private FailureItem(FailureReason reason, string message, IDictionary <string, string> attributes, string stackTrace, Type causeType)
        {
            this.attributes = ImmutableMap.copyOf(attributes);
            JodaBeanUtils.notNull(reason, "reason");
            JodaBeanUtils.notEmpty(message, "message");
            JodaBeanUtils.notNull(stackTrace, "stackTrace");
            this.reason     = reason;
            this.message    = message;
            this.stackTrace = INTERNER.intern(stackTrace);
            this.causeType  = causeType;
        }
Ejemplo n.º 17
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Build a new {@code FxMatrix} from the data in the builder.
 /// </summary>
 /// <returns> a new {@code FxMatrix} </returns>
 /// <exception cref="IllegalStateException"> if an attempt was made to add currencies
 ///   which have no currency in common with other rates </exception>
 public virtual FxMatrix build()
 {
     if (disjointRates.Count > 0)
     {
         throw new System.InvalidOperationException("Received rates with no currencies in common with other: " + disjointRates);
     }
     // Trim array down to the correct size - we have to copy the array
     // anyway to ensure immutability, so we may as well remove any
     // unused rows
     return(new FxMatrix(ImmutableMap.copyOf(currencies), DoubleMatrix.ofUnsafe(copyArray(rates, currencies.size()))));
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Formats a templated message inserting named arguments.
        /// <para>
        /// A typical template would look like:
        /// <pre>
        /// Messages.formatWithAttributes("Foo={foo}, Bar={}", "abc", 123)
        /// </pre>
        /// This will return a <seealso cref="Pair"/> with a String and a Map.
        /// The String will be the formatted message: {@code "Foo=abc, Bar=123"}.
        /// The Map will look like: <code>{"foo": "123"}</code>.
        /// </para>
        /// <para>
        /// This method combines a template message with a list of specific arguments.
        /// It can be useful to delay string concatenation, which is sometimes a performance issue.
        /// The approach is similar to SLF4J MessageFormat, Guava Preconditions and String format().
        /// </para>
        /// <para>
        /// The message template contains zero to many "{name}" placeholders.
        /// Each placeholder is replaced by the next available argument.
        /// If there are too few arguments, then the message will be left with placeholders.
        /// If there are too many arguments, then the excess arguments are appended to the message.
        /// No attempt is made to format the arguments.
        /// </para>
        /// <para>
        /// This method is null tolerant to ensure that use in exception construction will
        /// not throw another exception, which might hide the intended exception.
        ///
        /// </para>
        /// </summary>
        /// <param name="messageTemplate">  the message template with "{}" placeholders, null returns empty string </param>
        /// <param name="args">  the message arguments, null treated as empty array </param>
        /// <returns> the formatted message </returns>
        public static Pair <string, IDictionary <string, string> > formatWithAttributes(string messageTemplate, params object[] args)
        {
            if (string.ReferenceEquals(messageTemplate, null))
            {
                return(formatWithAttributes("", args));
            }
            if (args == null)
            {
                return(formatWithAttributes(messageTemplate));
            }

            // do not use an ImmutableMap, as we avoid throwing exceptions in case of duplicate keys.
            IDictionary <string, string> attributes = new Dictionary <string, string>();
            Matcher matcher  = REGEX_PATTERN.matcher(messageTemplate);
            int     argIndex = 0;

            StringBuilder outputMessageBuffer = new StringBuilder();

            while (matcher.find())
            {
                // if the number of placeholders is greater than the number of arguments, then not all placeholders are replaced.
                if (argIndex >= args.Length)
                {
                    continue;
                }

                string attributeName = matcher.group(1);   // extract the attribute name
                string replacement   = args[argIndex].ToString().Replace("$", "\\$");
                matcher.appendReplacement(outputMessageBuffer, replacement);
                if (attributeName.Length > 0)
                {
                    attributes[attributeName] = replacement;
                }
                argIndex++;
            }
            matcher.appendTail(outputMessageBuffer);

            // append remaining args
            if (argIndex < args.Length)
            {
                outputMessageBuffer.Append(" - [");
                for (int i = argIndex; i < args.Length; i++)
                {
                    if (i > argIndex)
                    {
                        outputMessageBuffer.Append(", ");
                    }
                    outputMessageBuffer.Append(args[i]);
                }
                outputMessageBuffer.Append(']');
            }

            return(Pair.of(outputMessageBuffer.ToString(), ImmutableMap.copyOf(attributes)));
        }
Ejemplo n.º 19
0
 public override void reload(PrefabData data)
 {
     this.componentMap   = ImmutableMap.copyOf(data.Components);
     this.persisted      = data.Persisted;
     this.alwaysRelevant = data.AlwaysRelevant;
     this.parent         = data.Parent;
     if (parent != null && parent is PojoPrefab)
     {
         ((PojoPrefab)parent).children.Add(this);
     }
 }
Ejemplo n.º 20
0
 private ImmutableCreditRatesProvider(LocalDate valuationDate, IDictionary <Pair <StandardId, Currency>, LegalEntitySurvivalProbabilities> creditCurves, IDictionary <Currency, CreditDiscountFactors> discountCurves, IDictionary <StandardId, RecoveryRates> recoveryRateCurves)
 {
     JodaBeanUtils.notNull(valuationDate, "valuationDate");
     JodaBeanUtils.notNull(creditCurves, "creditCurves");
     JodaBeanUtils.notEmpty(discountCurves, "discountCurves");
     JodaBeanUtils.notEmpty(recoveryRateCurves, "recoveryRateCurves");
     this.valuationDate      = valuationDate;
     this.creditCurves       = ImmutableMap.copyOf(creditCurves);
     this.discountCurves     = ImmutableMap.copyOf(discountCurves);
     this.recoveryRateCurves = ImmutableMap.copyOf(recoveryRateCurves);
     validate();
 }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Obtains an instance from the specified parameters.
        /// <para>
        /// The map provides a lookup from the <seealso cref="CalculationTarget"/> implementation type
        /// to the appropriate parameter to use for that target. If a target is requested that
        /// is not in the map, the default parameter is used.
        ///
        /// </para>
        /// </summary>
        /// <param name="parameters">  the parameters, keyed by target type </param>
        /// <param name="defaultParameter">  the default parameter </param>
        /// <returns> the target aware parameter </returns>
        public static TradeCounterpartyCalculationParameter of(IDictionary <StandardId, CalculationParameter> parameters, CalculationParameter defaultParameter)
        {
            ArgChecker.notEmpty(parameters, "values");
            ArgChecker.notNull(defaultParameter, "defaultParameter");
            Type queryType = defaultParameter.queryType();

            foreach (CalculationParameter value in parameters.Values)
            {
                if (value.queryType() != queryType)
                {
                    throw new System.ArgumentException(Messages.format("Map contained a parameter '{}' that did not match the expected query type '{}'", value, queryType.GetType().Name));
                }
            }
            return(new TradeCounterpartyCalculationParameter(queryType, ImmutableMap.copyOf(parameters), defaultParameter));
        }
Ejemplo n.º 22
0
        // build the search headers
        internal static ImmutableMap <string, int> buildSearchHeaders(ImmutableList <string> headers)
        {
            // need to allow duplicate headers and only store the first instance
            IDictionary <string, int> searchHeaders = new Dictionary <string, int>();

            for (int i = 0; i < headers.size(); i++)
            {
                string searchHeader = headers.get(i).ToLower(Locale.ENGLISH);
                if (!searchHeaders.ContainsKey(searchHeader))
                {
                    searchHeaders.Add(searchHeader, i);
                }
            }
            return(ImmutableMap.copyOf(searchHeaders));
        }
 private ImmutableLegalEntityDiscountingProvider(LocalDate valuationDate, IDictionary <SecurityId, RepoGroup> repoCurveSecurityGroups, IDictionary <LegalEntityId, RepoGroup> repoCurveGroups, IDictionary <Pair <RepoGroup, Currency>, DiscountFactors> repoCurves, IDictionary <LegalEntityId, LegalEntityGroup> issuerCurveGroups, IDictionary <Pair <LegalEntityGroup, Currency>, DiscountFactors> issuerCurves)
 {
     JodaBeanUtils.notNull(valuationDate, "valuationDate");
     JodaBeanUtils.notNull(repoCurveSecurityGroups, "repoCurveSecurityGroups");
     JodaBeanUtils.notNull(repoCurveGroups, "repoCurveGroups");
     JodaBeanUtils.notNull(repoCurves, "repoCurves");
     JodaBeanUtils.notNull(issuerCurveGroups, "issuerCurveGroups");
     JodaBeanUtils.notNull(issuerCurves, "issuerCurves");
     this.valuationDate           = valuationDate;
     this.repoCurveSecurityGroups = ImmutableMap.copyOf(repoCurveSecurityGroups);
     this.repoCurveGroups         = ImmutableMap.copyOf(repoCurveGroups);
     this.repoCurves        = ImmutableMap.copyOf(repoCurves);
     this.issuerCurveGroups = ImmutableMap.copyOf(issuerCurveGroups);
     this.issuerCurves      = ImmutableMap.copyOf(issuerCurves);
     validate();
 }
 private DefaultLegalEntityDiscountingMarketDataLookup(IDictionary <SecurityId, RepoGroup> repoCurveSecurityGroups, IDictionary <LegalEntityId, RepoGroup> repoCurveGroups, IDictionary <Pair <RepoGroup, Currency>, CurveId> repoCurves, IDictionary <LegalEntityId, LegalEntityGroup> issuerCurveGroups, IDictionary <Pair <LegalEntityGroup, Currency>, CurveId> issuerCurves, ObservableSource observableSource)
 {
     JodaBeanUtils.notNull(repoCurveSecurityGroups, "repoCurveSecurityGroups");
     JodaBeanUtils.notNull(repoCurveGroups, "repoCurveGroups");
     JodaBeanUtils.notNull(repoCurves, "repoCurves");
     JodaBeanUtils.notNull(issuerCurveGroups, "issuerCurveGroups");
     JodaBeanUtils.notNull(issuerCurves, "issuerCurves");
     JodaBeanUtils.notNull(observableSource, "observableSource");
     this.repoCurveSecurityGroups = ImmutableMap.copyOf(repoCurveSecurityGroups);
     this.repoCurveGroups         = ImmutableMap.copyOf(repoCurveGroups);
     this.repoCurves        = ImmutableMap.copyOf(repoCurves);
     this.issuerCurveGroups = ImmutableMap.copyOf(issuerCurveGroups);
     this.issuerCurves      = ImmutableMap.copyOf(issuerCurves);
     this.observableSource  = observableSource;
     validate();
 }
Ejemplo n.º 25
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Returns the map of known instances by name.
        /// <para>
        /// This method returns all known instances.
        /// It is permitted for an enum provider implementation to return an empty map,
        /// thus the map may not be complete.
        /// The map may include instances keyed under an alternate name, such as names
        /// in upper case, however it will not include the base set of
        /// <seealso cref="#alternateNames() alternate names"/>.
        ///
        /// </para>
        /// </summary>
        /// <returns> the map of enum instance by name </returns>
        public ImmutableMap <string, T> lookupAll()
        {
            IDictionary <string, T> map = new Dictionary <string, T>();

            foreach (NamedLookup <T> lookup in lookups)
            {
                IDictionary <string, T> lookupMap = lookup.lookupAll();
                foreach (KeyValuePair <string, T> entry in lookupMap.SetOfKeyValuePairs())
                {
                    if (!map.ContainsKey(entry.Key))
                    {
                        map.Add(entry.Key, entry.Value);
                    }
                }
            }
            return(ImmutableMap.copyOf(map));
        }
Ejemplo n.º 26
0
        public virtual void test_bondDiscountingProvider()
        {
            LocalDate valDate = LocalDate.of(2015, 6, 30);
            Curve     ccAUsd  = ConstantNodalCurve.of(Curves.zeroRates(CC_A_USD.CurveName, ACT_365F), 0.5d, 1.5d);
            Curve     ccBGbp  = ConstantNodalCurve.of(Curves.zeroRates(CC_B_GBP.CurveName, ACT_365F), 0.5d, 2d);
            Curve     ccAGbp  = ConstantNodalCurve.of(Curves.zeroRates(CC_A_GBP.CurveName, ACT_365F), 0.5d, 3d);
            Curve     dcGbp   = ConstantNodalCurve.of(Curves.zeroRates(DC_GBP.CurveName, ACT_365F), 0.5d, 0.1d);
            Curve     dcUsd   = ConstantNodalCurve.of(Curves.zeroRates(DC_USD.CurveName, ACT_365F), 0.5d, 0.05d);
            Curve     rcA     = ConstantCurve.of(Curves.recoveryRates(RC_A.CurveName, ACT_365F), 0.5d);
            Curve     rcB     = ConstantCurve.of(Curves.recoveryRates(RC_B.CurveName, ACT_365F), 0.4234d);
            IDictionary <CurveId, Curve> curveMap = new Dictionary <CurveId, Curve>();

            curveMap[CC_A_USD] = ccAUsd;
            curveMap[CC_B_GBP] = ccBGbp;
            curveMap[CC_A_GBP] = ccAGbp;
            curveMap[DC_USD]   = dcUsd;
            curveMap[DC_GBP]   = dcGbp;
            curveMap[RC_A]     = rcA;
            curveMap[RC_B]     = rcB;
            MarketData          md       = ImmutableMarketData.of(valDate, ImmutableMap.copyOf(curveMap));
            CreditRatesProvider provider = LOOKUP_WITH_SOURCE.creditRatesProvider(md);

            assertEquals(provider.ValuationDate, valDate);
            assertEquals(provider.findData(CC_A_USD.CurveName), ccAUsd);
            assertEquals(provider.findData(DC_USD.CurveName), dcUsd);
            assertEquals(provider.findData(RC_B.CurveName), rcB);
            assertEquals(provider.findData(CurveName.of("Rubbish")), null);
            // check credit curve
            LegalEntitySurvivalProbabilities cc      = provider.survivalProbabilities(ISSUER_A, GBP);
            IsdaCreditDiscountFactors        ccUnder = (IsdaCreditDiscountFactors)cc.SurvivalProbabilities;

            assertEquals(ccUnder.Curve.Name, ccAGbp.Name);
            assertThrowsRuntime(() => provider.survivalProbabilities(ISSUER_B, USD));
            assertThrowsRuntime(() => provider.survivalProbabilities(ISSUER_C, USD));
            // check discount curve
            IsdaCreditDiscountFactors dc = (IsdaCreditDiscountFactors)provider.discountFactors(USD);

            assertEquals(dc.Curve.Name, dcUsd.Name);
            assertThrowsRuntime(() => provider.discountFactors(EUR));
            // check recovery rate curve
            ConstantRecoveryRates rc = (ConstantRecoveryRates)provider.recoveryRates(ISSUER_B);

            assertEquals(rc.RecoveryRate, rcB.getParameter(0));
            assertThrowsRuntime(() => provider.recoveryRates(ISSUER_C));
        }
Ejemplo n.º 27
0
        // parses the alternate names
        private static ImmutableMap <string, string> parseAlternates(IniFile config)
        {
            if (!config.contains(ALTERNATES_SECTION))
            {
                return(ImmutableMap.of());
            }
            IDictionary <string, string> alternates = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> entry in config.section(ALTERNATES_SECTION).asMap().entrySet())
            {
                alternates[entry.Key] = entry.Value;
                if (!alternates.ContainsKey(entry.Key.ToUpper(Locale.ENGLISH)))
                {
                    alternates.Add(entry.Key.ToUpper(Locale.ENGLISH), entry.Value);
                }
            }
            return(ImmutableMap.copyOf(alternates));
        }
Ejemplo n.º 28
0
        //------------------------------------------------------------------------
        /// <summary>
        /// Creates an instance, specifying the headers and row.
        /// <para>
        /// See <seealso cref="CsvFile"/>.
        ///
        /// </para>
        /// </summary>
        /// <param name="headers">  the headers </param>
        /// <param name="fields">  the fields </param>
        private CsvRow(ImmutableList <string> headers, int lineNumber, ImmutableList <string> fields)
        {
            this.headers_Renamed = headers;
            // need to allow duplicate headers and only store the first instance
            IDictionary <string, int> searchHeaders = new Dictionary <string, int>();

            for (int i = 0; i < headers.size(); i++)
            {
                string searchHeader = headers.get(i).ToLower(Locale.ENGLISH);
                if (!searchHeaders.ContainsKey(searchHeader))
                {
                    searchHeaders.Add(searchHeader, i);
                }
            }
            this.searchHeaders      = ImmutableMap.copyOf(searchHeaders);
            this.lineNumber_Renamed = lineNumber;
            this.fields_Renamed     = fields;
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Computes cash flow equivalent and sensitivity of fixed leg.
        /// <para>
        /// The return type is a map of {@code NotionalExchange} and {@code PointSensitivityBuilder}.
        ///
        /// </para>
        /// </summary>
        /// <param name="fixedLeg">  the fixed leg </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <returns> the cash flow equivalent and sensitivity </returns>
        public static ImmutableMap <Payment, PointSensitivityBuilder> cashFlowEquivalentAndSensitivityFixedLeg(ResolvedSwapLeg fixedLeg, RatesProvider ratesProvider)
        {
            ArgChecker.isTrue(fixedLeg.Type.Equals(SwapLegType.FIXED), "Leg type should be FIXED");
            ArgChecker.isTrue(fixedLeg.PaymentEvents.Empty, "PaymentEvent should be empty");
            IDictionary <Payment, PointSensitivityBuilder> res = new Dictionary <Payment, PointSensitivityBuilder>();

            foreach (SwapPaymentPeriod paymentPeriod in fixedLeg.PaymentPeriods)
            {
                ArgChecker.isTrue(paymentPeriod is RatePaymentPeriod, "rate payment should be RatePaymentPeriod");
                RatePaymentPeriod ratePaymentPeriod = (RatePaymentPeriod)paymentPeriod;
                ArgChecker.isTrue(ratePaymentPeriod.AccrualPeriods.size() == 1, "rate payment should not be compounding");
                RateAccrualPeriod rateAccrualPeriod = ratePaymentPeriod.AccrualPeriods.get(0);
                double            factor            = rateAccrualPeriod.YearFraction * ((FixedRateComputation)rateAccrualPeriod.RateComputation).Rate;
                CurrencyAmount    notional          = ratePaymentPeriod.NotionalAmount.multipliedBy(factor);
                LocalDate         paymentDate       = ratePaymentPeriod.PaymentDate;
                Payment           pay = Payment.of(notional, paymentDate);
                res[pay] = PointSensitivityBuilder.none();
            }
            return(ImmutableMap.copyOf(res));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Returns the map of known instances by normalized name.
        /// <para>
        /// This method returns all known instances, keyed by the normalized name.
        /// This is equivalent to the result of <seealso cref="#lookupAll()"/> adjusted such
        /// that each entry is keyed by the result of <seealso cref="Named#getName()"/>.
        ///
        /// </para>
        /// </summary>
        /// <returns> the map of enum instance by name </returns>
        public ImmutableMap <string, T> lookupAllNormalized()
        {
            // add values that are keyed under the normalized name
            // keep values keyed under a non-normalized name
            IDictionary <string, T> result = new Dictionary <string, T>();
            IDictionary <string, T> others = new Dictionary <string, T>();

            foreach (KeyValuePair <string, T> entry in lookupAll().entrySet())
            {
                string normalizedName = entry.Value.Name;
                if (entry.Key.Equals(normalizedName))
                {
                    result[normalizedName] = entry.Value;
                }
                else
                {
                    others[normalizedName] = entry.Value;
                }
            }
            // include any values that are only keyed under a non-normalized name
            others.Values.forEach(v => result.putIfAbsent(v.Name, v));
            return(ImmutableMap.copyOf(result));
        }