From 9c5b04495ddcc056ed655da66fa0bcaf18026c7d Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 25 Apr 2025 17:55:06 -0400 Subject: [PATCH] Code cleanup --- MarketData/MarketData/Services/MainService.cs | 30 +++++++++---------- .../Generator/Momentum/Backtest.cs | 24 +++++++++++++-- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/MarketData/MarketData/Services/MainService.cs b/MarketData/MarketData/Services/MainService.cs index 9df858c..121e4fe 100755 --- a/MarketData/MarketData/Services/MainService.cs +++ b/MarketData/MarketData/Services/MainService.cs @@ -635,7 +635,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -654,7 +654,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)."); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)."); } } @@ -688,7 +688,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -714,7 +714,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -769,7 +769,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took{profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took{profiler.End()}(ms)"); } } @@ -837,7 +837,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -857,7 +857,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -877,7 +877,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -896,7 +896,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -915,7 +915,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -935,7 +935,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -954,7 +954,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -973,7 +973,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -992,7 +992,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } @@ -1010,7 +1010,7 @@ namespace MarketData.Services } finally { - MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End}(ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)"); } } diff --git a/MarketData/MarketDataLib/Generator/Momentum/Backtest.cs b/MarketData/MarketDataLib/Generator/Momentum/Backtest.cs index 696b1f1..c063218 100755 --- a/MarketData/MarketDataLib/Generator/Momentum/Backtest.cs +++ b/MarketData/MarketDataLib/Generator/Momentum/Backtest.cs @@ -118,7 +118,6 @@ namespace MarketData.Generator.Momentum double gainLossClosedPositions=0.00; double exposure=0.00; double marketValue=0.00; -// if(HolidayDA.IsMarketHoliday(currentDate)) continue; ModelPerformanceItem performanceItem=new ModelPerformanceItem(); foreach(MarketData.Generator.Momentum.Position openPosition in openPositions) { @@ -190,7 +189,8 @@ namespace MarketData.Generator.Momentum AllPositions.DisplayTopFive(); MDTrace.WriteLine(LogLevel.DEBUG, "************** T O P L O S S E R S *************"); AllPositions.DisplayBottomFive(); - DisplayBalanceFromPositions(); +// DisplayBalanceFromPositions(); + DisplayLatestModelPerformance(paramPathSessionFileName); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("StartDate:{0}",Utility.DateTimeToStringMMHDDHYYYY(StartDate))); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("TradeDate:{0}",Utility.DateTimeToStringMMHDDHYYYY(TradeDate))); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("AnalysisDate:{0}",Utility.DateTimeToStringMMHDDHYYYY(AnalysisDate))); @@ -588,6 +588,26 @@ namespace MarketData.Generator.Momentum // ********************************************************************************************************************************************************************* // ************************************************************ E N D B U Y P O S I T I O N S *********************************************** // ********************************************************************************************************************************************************************* + private void DisplayLatestModelPerformance(String pathSessionFileName) + { + ModelPerformanceSeries performanceSeries=GetModelPerformance(pathSessionFileName); + if(null==performanceSeries || 0==performanceSeries.Count)return; + MDTrace.WriteLine("Date,Exposure,MarketValue,GainLossDoD,GainLoss,CumulativeGainLoss,R,(1+R),CumProd,CumProd-1,ClosedPositions"); + ModelPerformanceItem modelPerformanceItem = performanceSeries[performanceSeries.Count-1]; // get the last record + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\",\"{9}\",\"{10}\"", + modelPerformanceItem.Date.ToShortDateString(), + Utility.FormatCurrency(modelPerformanceItem.Exposure), + Utility.FormatCurrency(modelPerformanceItem.MarketValue), + Utility.FormatCurrency(modelPerformanceItem.GainLossDOD), + Utility.FormatCurrency(modelPerformanceItem.GainLoss), + Utility.FormatCurrency(modelPerformanceItem.CumulativeGainLoss), + Utility.FormatNumber(modelPerformanceItem.R,4), + Utility.FormatNumber(modelPerformanceItem.OnePlusR,4), + Utility.FormatNumber(modelPerformanceItem.CumProd,4), + Utility.FormatNumber(modelPerformanceItem.CumProdMinusOne,4), + modelPerformanceItem.ClosedPositions)); + } + private void DisplayBalance() { MDTrace.WriteLine(LogLevel.DEBUG,"*******************************************");