示例#1
0
        // Stores historical fixings from a TimeSeries
        // The dates in the TimeSeries must be the actual calendar dates of the fixings; no settlement days must be used.
        public void addFixings(TimeSeries <double?> source, bool forceOverwrite = false)
        {
            checkNativeFixingsAllowed();
            TimeSeries <double?> target = IndexManager.instance().getHistory(name());

            foreach (Date d in source.Keys)
            {
                if (isValidFixingDate(d))
                {
                    if (!target.ContainsKey(d))
                    {
                        target.Add(d, source[d]);
                    }
                    else if (forceOverwrite)
                    {
                        target[d] = source[d];
                    }
                    else if (Utils.close(target[d].GetValueOrDefault(), source[d].GetValueOrDefault()))
                    {
                        continue;
                    }
                    else
                    {
                        throw new ArgumentException("Duplicated fixing provided: " + d + ", " + source[d] +
                                                    " while " + target[d] + " value is already present");
                    }
                }
                else
                {
                    throw new ArgumentException("Invalid fixing provided: " + d.DayOfWeek + " " + d + ", " + source[d]);
                }
            }

            IndexManager.instance().setHistory(name(), target);
        }
示例#2
0
文件: Index.cs 项目: tzhdingli/qlnet
        public void addFixings(List <Date> d, List <double> v, bool forceOverwrite)
        {
            if ((d.Count != v.Count) || d.Count == 0)
            {
                throw new ArgumentException("Wrong collection dimensions when creating index fixings");
            }

            TimeSeries <double> t = new TimeSeries <double>();

            for (int i = 0; i < d.Count; i++)
            {
                t.Add(d[i], v[i]);
            }
            addFixings(t, forceOverwrite);
        }