Add profiling

This commit is contained in:
2025-04-21 21:41:46 -04:00
parent 9b2451649f
commit ee3f4a5169
2 changed files with 27 additions and 3 deletions

View File

@@ -23,25 +23,37 @@ namespace MarketData.Generator.CMTrend
List<String> symbols=PricingDA.GetSymbols();
// Filter out symbols where we do not have a price on trade date
Profiler profiler = new Profiler();
Dictionary<String,DateTime> latestDates = PricingDA.GetLatestDates(symbols);
symbols=symbols.Where(x => latestDates.ContainsKey(x) && latestDates[x].Date>=tradeDate.Date).ToList();
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded pricing dates in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch a subset of fundamentals where each fundamental.asof is no greater than tradeDate
profiler.Reset();
FundamentalsV2 fundamentals = FundamentalDA.GetFundamentalsMaxDateV2(tradeDate);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded fundamentals in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch the Company Profiles
profiler.Reset();
Dictionary<String,CompanyProfile> companyProfiles = CompanyProfileDA.GetCompanyProfiles(symbols);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded company profiles in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch the pricing dates requires for 200 day moving average.
// Prefetch the pricing dates required for 200 day moving average.
profiler.Reset();
DateGenerator dateGenerator = new DateGenerator();
DateTime historicalDate=dateGenerator.GenerateHistoricalDate(tradeDate,cmtParams.DMA200Horizon+10);
List<DateTime> historicalDates=PricingDA.GetPricingDatesBetween(historicalDate,tradeDate);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded moving average dates in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch the EPS time series
profiler.Reset();
Dictionary<String,TimeSeriesCollection> epsTimeSeriesCollectionDictionary = FundamentalDA.GetEPS(symbols,tradeDate,3);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded EPS Time Series in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch the profit margin time series
profiler.Reset();
Dictionary<String,TimeSeriesCollection> profitMarginTimeSeriesCollectionDictionary = IncomeStatementDA.GetProfitMarginMaxAsOf(symbols,tradeDate,3,IncomeStatement.PeriodType.Quarterly);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Profit Margin Time Series in {Utility.FormatNumber(profiler.End(),2)} (ms)");
for(int index=0;index<symbols.Count;index++)
{

View File

@@ -137,7 +137,6 @@ namespace MarketData.Generator.CMTrend
double gainLossClosedPositions=0.00;
double exposure=0.00;
double marketValue=0.00;
// if(HolidayDA.IsMarketHoliday(currentDate)) continue;
ModelPerformanceItem performanceItem=new ModelPerformanceItem();
foreach(MarketData.Generator.CMTrend.Position openPosition in openPositions)
{
@@ -800,25 +799,38 @@ namespace MarketData.Generator.CMTrend
List<CMTCandidate> candidates=new List<CMTCandidate>();
// Filter out symbols where we do not have a price on trade date
Profiler profiler = new Profiler();
Dictionary<String,DateTime> latestDates = PricingDA.GetLatestDates(symbols);
symbols=symbols.Where(x => latestDates.ContainsKey(x) && latestDates[x].Date>=analysisDate.Value.Date).ToList();
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded pricing dates in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch a subset of fundamentals where each fundamental.asof is no greater than tradeDate
profiler.Reset();
FundamentalsV2 fundamentals = FundamentalDA.GetFundamentalsMaxDateV2(analysisDate.Value);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded fundamentals in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch the company profiles
profiler.Reset();
Dictionary<String,CompanyProfile> companyProfiles = CompanyProfileDA.GetCompanyProfiles(symbols);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded company profiles in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch the pricing dates requires for 200 day moving average.
// Prefetch the pricing dates required for 200 day moving average.
profiler.Reset();
DateGenerator dateGenerator = new DateGenerator();
DateTime historicalDate=dateGenerator.GenerateHistoricalDate(analysisDate.Value,cmtParams.DMA200Horizon+10);
List<DateTime> historicalDates=PricingDA.GetPricingDatesBetween(historicalDate,analysisDate.Value);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded moving average dates in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch the EPS time series
profiler.Reset();
Dictionary<String,TimeSeriesCollection> epsTimeSeriesCollectionDictionary = FundamentalDA.GetEPS(symbols,analysisDate.Value,3);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded EPS Time Series in {Utility.FormatNumber(profiler.End(),2)} (ms)");
// Prefetch the profit margin time series
profiler.Reset();
Dictionary<String,TimeSeriesCollection> profitMarginTimeSeriesCollectionDictionary = IncomeStatementDA.GetProfitMarginMaxAsOf(symbols,analysisDate.Value,3,IncomeStatement.PeriodType.Quarterly);
MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Profit Margin Time Series in {Utility.FormatNumber(profiler.End(),2)} (ms)");
for(int index=0;index<symbols.Count;index++)
{