Skip to content

Commit

Permalink
CPI lag direction fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Aug 15, 2023
1 parent 0beadd8 commit 40378d0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Qwack.Core/Curves/CPICurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public IIrCurve BumpRateFlat(double delta, bool mutate)
public Dictionary<DateTime, IIrCurve> BumpScenarios(double delta, DateTime lastSensitivityDate) => throw new NotImplementedException();


public double GetForecast(DateTime fixingDate, int fixingLagInMonths) => _cpiInterp.Interpolate(fixingDate.AddMonths(fixingLagInMonths).ToOADate()); // InflationUtils.InterpFixing(fixingDate, _cpiInterp, fixingLagInMonths);
public double GetForecast(DateTime fixingDate, int fixingLagInMonths) => _cpiInterp.Interpolate(fixingDate.AddMonths(-System.Math.Abs(fixingLagInMonths)).ToOADate()); // InflationUtils.InterpFixing(fixingDate, _cpiInterp, fixingLagInMonths);
public double GetForecastExact(DateTime fixingDate, int fixingLagInMonths) => InflationUtils.InterpFixing(fixingDate, _cpiInterp, fixingLagInMonths);

public double GetDf(DateTime startDate, DateTime endDate)
Expand Down
48 changes: 48 additions & 0 deletions src/Qwack.Dates/DateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,5 +816,53 @@ public static DateTime[] GenerateDateSchedule(this DatePeriodType period, DateTi
}

public static int DiffinMonths(this DateTime start, DateTime end) => (end.Year * 12 + end.Month) - (start.Year * 12 + start.Month);

public static DateTime AddWeekDays(DateTime d, int n)
{
var cd = d;
for (var i = 0; i < n; i++)
{
cd = cd.AddDays(1);
while (cd.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday)
{
cd = cd.AddDays(1);
}
}
return cd;
}

public static DateTime SubtractWeekDays(DateTime d, int n)
{
var cd = d;
for (var i = n; i > 0; i--)
{
cd = cd.AddDays(-1);
while (cd.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday)
{
cd = cd.AddDays(-1);
}
}
return cd;
}

public static DateTime PrevWeekDay(DateTime day)
{
day = day.AddDays(-1);
while (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday)
{
day = day.AddDays(-1);
}
return day;
}

public static DateTime NextWeekDay(DateTime day)
{
day = day.AddDays(1);
while (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday)
{
day = day.AddDays(1);
}
return day;
}
}
}
2 changes: 1 addition & 1 deletion version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<VersionPrefix>0.7.30</VersionPrefix>
<VersionPrefix>0.7.31</VersionPrefix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.30
0.7.31

0 comments on commit 40378d0

Please sign in to comment.