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)); }
public OutputFrequency(OutputSeries outputSeries, Maturity maximumMaturity) { OutputSeries = outputSeries; MaximumMaturity = maximumMaturity; }
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)); }
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)); }
public CurvePoint(Maturity maturity, Price price) { Maturity = maturity; Price = price; }
public static CurvePoint FromPoint(Point point, string currency) => new CurvePoint(Maturity.FromX(point.X), Price.FromY(point.Y, currency));
public Point ToPoint() => new Point(Maturity.ToX(), Price.ToY());