Ejemplo n.º 1
0
        private CurvePoint ResolveMaturity(Maturity maturity, IEnumerable <CurvePoint> points)
        {
            var alreadyExistingPoint = points.FirstOrDefault(p => p.Maturity == maturity);

            if (alreadyExistingPoint != null)
            {
                return(alreadyExistingPoint);
            }

            var minPoint = points
                           .OrderBy(p => p.Maturity)
                           .First();

            if (maturity < minPoint.Maturity)
            {
                return(ExtrapolationShort.Solve(minPoint, maturity));
            }

            var maxPoint = points
                           .OrderBy(p => p.Maturity)
                           .Last();

            if (maturity > maxPoint.Maturity)
            {
                return(ExtrapolationLong.Solve(maxPoint, maturity));
            }

            var before = points
                         .Where(p => p.Maturity < maturity)
                         .OrderBy(p => p.Maturity)
                         .Last();

            var after = points
                        .Where(p => p.Maturity > maturity)
                        .OrderBy(p => p.Maturity)
                        .First();

            return(Interpolation.Solve(before, after, maturity));
        }
Ejemplo n.º 2
0
 public OutputFrequency(OutputSeries outputSeries, Maturity maximumMaturity)
 {
     OutputSeries    = outputSeries;
     MaximumMaturity = maximumMaturity;
 }
Ejemplo n.º 3
0
        public static CurvePoint Solve(this Interpolation interpolation, CurvePoint a, CurvePoint b, Maturity maturity)
        {
            if (a.Price.Currency != b.Price.Currency)
            {
                throw new NotImplementedException("Converting between currencies is not supported");
            }

            var pointA = a.ToPoint();
            var pointB = b.ToPoint();
            var x      = maturity.ToX();

            var point = interpolation.SolveForY(pointA, pointB, x);

            return(CurvePoint.FromPoint(point, a.Price.Currency));
        }
Ejemplo n.º 4
0
        public static CurvePoint Solve(this ExtrapolationLong extraShort, CurvePoint min, Maturity maturity)
        {
            var p = min.ToPoint();
            var x = maturity.ToX();

            var point = extraShort.GetPoint(p, x);

            return(CurvePoint.FromPoint(point, min.Price.Currency));
        }
Ejemplo n.º 5
0
 public CurvePoint(Maturity maturity, Price price)
 {
     Maturity = maturity;
     Price    = price;
 }
Ejemplo n.º 6
0
 public static CurvePoint FromPoint(Point point, string currency) =>
 new CurvePoint(Maturity.FromX(point.X), Price.FromY(point.Y, currency));
Ejemplo n.º 7
0
 public Point ToPoint() => new Point(Maturity.ToX(), Price.ToY());