From 544bd0557ce325724bce8a3f03d18f4f4fbb8f6b Mon Sep 17 00:00:00 2001 From: Felix Bertram Date: Sun, 31 Mar 2024 18:41:01 -0700 Subject: [PATCH] upgrade nuget packages. expand holiday calendar. --- .../Simulator/v1/Core/HolidayCalendar.cs | 23 ++++++++ .../TuringTrader.Simulator.csproj | 4 +- TuringTrader.Tests/TuringTrader.Tests.csproj | 6 +-- TuringTrader/ReportTemplate.cs | 52 +++++++++++++++++++ TuringTrader/TuringTrader.csproj | 4 +- 5 files changed, 82 insertions(+), 7 deletions(-) diff --git a/TuringTrader.Simulator/Simulator/v1/Core/HolidayCalendar.cs b/TuringTrader.Simulator/Simulator/v1/Core/HolidayCalendar.cs index 4d9cf41c..6250b693 100644 --- a/TuringTrader.Simulator/Simulator/v1/Core/HolidayCalendar.cs +++ b/TuringTrader.Simulator/Simulator/v1/Core/HolidayCalendar.cs @@ -95,6 +95,29 @@ static public class HolidayCalendar DateTime.Parse("09/04/2023", CultureInfo.InvariantCulture), // Labor Day DateTime.Parse("11/23/2023", CultureInfo.InvariantCulture), // Thanksgiving Day DateTime.Parse("12/25/2023", CultureInfo.InvariantCulture), // Christmas Day + //--- 2024 + DateTime.Parse("01/01/2024", CultureInfo.InvariantCulture), // New Years Day + DateTime.Parse("01/15/2024", CultureInfo.InvariantCulture), // Martin Luther King, Jr. Day + DateTime.Parse("02/19/2024", CultureInfo.InvariantCulture), // Washington's Birthday + DateTime.Parse("03/29/2024", CultureInfo.InvariantCulture), // Good Friday + DateTime.Parse("05/27/2024", CultureInfo.InvariantCulture), // Memorial Day + DateTime.Parse("06/19/2024", CultureInfo.InvariantCulture), // Juneteenth National Independence Day + DateTime.Parse("07/04/2024", CultureInfo.InvariantCulture), // Independence Day + DateTime.Parse("09/02/2024", CultureInfo.InvariantCulture), // Labor Day + DateTime.Parse("11/28/2024", CultureInfo.InvariantCulture), // Thanksgiving Day + DateTime.Parse("12/25/2024", CultureInfo.InvariantCulture), // Christmas Day + //--- 2025 + DateTime.Parse("01/01/2025", CultureInfo.InvariantCulture), // New Years Day + DateTime.Parse("01/20/2025", CultureInfo.InvariantCulture), // Martin Luther King, Jr. Day + DateTime.Parse("02/17/2025", CultureInfo.InvariantCulture), // Washington's Birthday + DateTime.Parse("04/18/2025", CultureInfo.InvariantCulture), // Good Friday + DateTime.Parse("05/26/2025", CultureInfo.InvariantCulture), // Memorial Day + DateTime.Parse("06/19/2025", CultureInfo.InvariantCulture), // Juneteenth National Independence Day + DateTime.Parse("07/04/2025", CultureInfo.InvariantCulture), // Independence Day + DateTime.Parse("09/01/2025", CultureInfo.InvariantCulture), // Labor Day + DateTime.Parse("11/27/2025", CultureInfo.InvariantCulture), // Thanksgiving Day + DateTime.Parse("12/25/2025", CultureInfo.InvariantCulture), // Christmas Day + //--- }; /// diff --git a/TuringTrader.Simulator/TuringTrader.Simulator.csproj b/TuringTrader.Simulator/TuringTrader.Simulator.csproj index c7e6e80f..4352fed6 100644 --- a/TuringTrader.Simulator/TuringTrader.Simulator.csproj +++ b/TuringTrader.Simulator/TuringTrader.Simulator.csproj @@ -38,8 +38,8 @@ - - + + diff --git a/TuringTrader.Tests/TuringTrader.Tests.csproj b/TuringTrader.Tests/TuringTrader.Tests.csproj index 8e3e275b..b4d5843a 100644 --- a/TuringTrader.Tests/TuringTrader.Tests.csproj +++ b/TuringTrader.Tests/TuringTrader.Tests.csproj @@ -9,9 +9,9 @@ - - - + + + diff --git a/TuringTrader/ReportTemplate.cs b/TuringTrader/ReportTemplate.cs index be1799f5..aaf4d378 100644 --- a/TuringTrader/ReportTemplate.cs +++ b/TuringTrader/ReportTemplate.cs @@ -893,6 +893,7 @@ protected PlotModel RenderSimple(string selectedChart) newSeries.XAxisKey = "x"; newSeries.YAxisKey = "y"; newSeries.Color = CFG_COLORS[allSeries.Count % CFG_COLORS.Count()]; + //newSeries.StrokeThickness = 5; allSeries[yLabel] = newSeries; } @@ -2006,7 +2007,49 @@ protected List> RenderComps() foreach (var p in periods) { +#if false + // retired 2024i08 DateTime datePastTarget = dateLast - TimeSpan.FromDays(p.Item2 * 365.25); +#else + // new 2024i08 + DateTime datePastTarget; + + if (Math.Abs(p.Item2 - 1 / 52.0) < 1e-4) + { + // multi-week + var weeksBack = (int)Math.Round(52.0 * p.Item2); + + datePastTarget = dateLast - TimeSpan.FromDays(7 * weeksBack); + } + else if (p.Item2 < 1.0) + { + // multi-month + var monthsBack = (int)Math.Round(12.0 * p.Item2); + + var month = (dateLast.Month + 11 - monthsBack) % 12 + 1; + + var year = month < dateLast.Month + ? dateLast.Year + : dateLast.Year - 1; + + var day = month == 2 + ? Math.Min(dateLast.Day, 28) // FIXME + : Math.Min(dateLast.Day, 30); // FIXME + + datePastTarget = new DateTime(year, month, day) + dateLast.TimeOfDay; + } + else + { + // multi-year + var yearsBack = (int)Math.Round(p.Item2); + + var day = dateLast.Month == 2 + ? Math.Min(dateLast.Day, 28) // FIXME + : Math.Min(dateLast.Day, 30); // FIXME + + datePastTarget = new DateTime(dateLast.Year - yearsBack, dateLast.Month, day) + dateLast.TimeOfDay; + } +#endif Dictionary rowPast = _firstChart .OrderBy(r => Math.Abs((datePastTarget - (DateTime)r[_xLabel]).TotalSeconds)) .First(); @@ -2022,10 +2065,19 @@ protected List> RenderComps() } //--- year-to-date { +#if false + // retired 2024i08: calculate against close of first day of the year DateTime datePastTarget = dateLast - TimeSpan.FromDays(dateLast.DayOfYear); Dictionary rowPast = _firstChart .OrderBy(r => Math.Abs((datePastTarget - (DateTime)r[_xLabel]).TotalSeconds)) .First(); +#else + // new 2024i08: calculate against close of last day of previous year + Dictionary rowPast = _firstChart + .Where(r => ((DateTime)r[_xLabel]).Year < dateLast.Year) + .OrderByDescending(r => ((DateTime)r[_xLabel]).Ticks) + .First(); +#endif DateTime datePast = (DateTime)rowPast[_xLabel]; double years = (dateLast - datePast).TotalDays / 365.25; double navPast = (double)rowPast[_firstYLabel]; diff --git a/TuringTrader/TuringTrader.csproj b/TuringTrader/TuringTrader.csproj index 5579ba7a..2522dcce 100644 --- a/TuringTrader/TuringTrader.csproj +++ b/TuringTrader/TuringTrader.csproj @@ -20,10 +20,10 @@ - + NU1701 - + NU1701