Exemplo n.º 1
0
        public double GetRate(DateTime targetDate)
        {
            RateAtDate before = new RateAtDate();
            RateAtDate after  = new RateAtDate();

            foreach (var item in sortedSource)
            {
                if (item.Date == targetDate)
                {
                    return(item.Rate);
                }

                if (item.Date < targetDate)
                {
                    before = item;
                }
                else
                {
                    after = item;
                    break;
                }
            }

            return(InterpolatedRate(before, after, targetDate));
        }
Exemplo n.º 2
0
        protected override double InterpolatedRate(RateAtDate before, RateAtDate after, DateTime targetDate)
        {
            double mu  = Utils.GetMu(before, after, targetDate);
            double mu2 = (1 - Math.Cos(mu * Math.PI)) / 2;

            return(before.Rate * (1 - mu2) + after.Rate * mu2);
        }
Exemplo n.º 3
0
        internal static double GetMu(RateAtDate before, RateAtDate after, DateTime targetDate)
        {
            Contract.Requires(after.Date != before.Date);

            return((targetDate - before.Date).TotalMilliseconds /
                   (after.Date - before.Date).TotalMilliseconds);
        }
Exemplo n.º 4
0
        public double GetRate(DateTime targetDate)
        {
            Contract.Requires(SortedSource != null);
            Contract.Requires(targetDate >= SortedSource[0].Date);
            Contract.Requires(targetDate <= SortedSource[SortedSource.Count - 1].Date);

            RateAtDate before = new RateAtDate();
            RateAtDate after  = new RateAtDate();

            foreach (var item in sortedSource)
            {
                if (item.Date == targetDate)
                {
                    return(item.Rate);
                }

                if (item.Date < targetDate)
                {
                    before = item;
                }
                else
                {
                    after = item;
                    break;
                }
            }

            return(InterpolatedRate(before, after, targetDate));
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            RateAtDate[] rates = new RateAtDate[]
            {
                new RateAtDate("10/10/2009", 4.01),
                new RateAtDate("11/10/2009", 4.01),
                new RateAtDate("12/10/2009", 4.02),
                new RateAtDate("17/10/2009", 4.14),
                new RateAtDate("31/10/2009", 4.25),
                new RateAtDate("30/11/2009", 4.35),
                new RateAtDate("28/02/2010", 4.5),
                new RateAtDate("31/05/2010", 4.75),
                new RateAtDate("10/10/2010", 5.13),
                new RateAtDate("10/10/2015", 5.5),
            };

            string rootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Visualizer visualizer = new Visualizer(rootPath + @"\testdata");

            visualizer.Visualize(rates, 3000);
        }
Exemplo n.º 6
0
 protected abstract double InterpolatedRate(RateAtDate before, RateAtDate after, DateTime targetDate);
Exemplo n.º 7
0
        protected override double InterpolatedRate(RateAtDate before, RateAtDate after, DateTime targetDate)
        {
            double mu = Utils.GetMu(before, after, targetDate);

            return(before.Rate * (1 - mu) + after.Rate * mu);
        }