From af499ff0371fbdaa208ae6f4a2880158d1670ff8 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 27 Feb 2026 20:43:41 -0500 Subject: [PATCH] Daily + GLPriceCache optimizations --- MarketData/MarketData/Models/CMT20200817.TXT | 12 +++---- .../MarketDataLib/Cache/GLPriceCache.cs | 33 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/MarketData/MarketData/Models/CMT20200817.TXT b/MarketData/MarketData/Models/CMT20200817.TXT index f92a549..31ca3f1 100755 --- a/MarketData/MarketData/Models/CMT20200817.TXT +++ b/MarketData/MarketData/Models/CMT20200817.TXT @@ -1,15 +1,15 @@ CMTSESSIONv1.00 -LastUpdated=2/26/2026 9:54:20 PM -TradeDate=2/26/2026 +LastUpdated=2/27/2026 8:39:15 PM +TradeDate=2/27/2026 StartDate=1/1/0001 -AnalysisDate=2/26/2026 +AnalysisDate=2/27/2026 CashBalance=4287.320000000001 NonTradeableCash=6456.42 -SuspendTrading=False|UsePriceSlopeIndicator=True|UsePriceSlopeIndicatorDays=252|AnalysisDate=2/26/2026|BetaMonths=6|TradeDate=2/26/2026|MarketCapLowerLimit=500000000|SidewaysDetection=False|SidewaysAfterDays=30|PriceTrendDays=20|CheckOutliersInReturnStream=True|DailyReturnLimit=0.25|MaxDailyPositions=3|MaxOpenPositions=3|NoTradeSymbols=CODYY,MARUY,CSTM,CS,NATI,QADA,CRTO,GTBIF,CLCT,PRSC,CMD,STAY,GBTC,YOKU,PNY,RFMD,ASAZY,USMO,VNR,STB,XIV,SYNT,DFP|OnlyTradeSymbols=|MinRSI=70|InitialCash=10000|TotalRiskPercentDecimal=0.05|PositionRiskPercentDecimal=0.12|EquityOnly=False|MinPercentReturnProximityTo52WeekHigh=30|MinPercentReturnOver52WeekLow=80|ProfitMarginCheck=True|EPSCheck=True|MinDaysBetweenReholding=30|LiquidityCheck=True|MinVolume=1000|DMA200Horizon=15|MinDaysBetweenStopAdjustments=30|MinDaysBetweenInitialStopAdjustment=5|MaxPricingExceptions=3|MACDSetup=(12,26,9)|MACDSignalDays=5|MACDRejectStrongSells=True|MACDRejectWeakSells=True|UseMarketIndicator=True|Benchmark=SPY|BenchmarkMovingAverageDays=200|BenchmarkMovingAverageHorizon=5|UseMarketIndicatorVolatility=True|UseMarketIndicatorVolatilityHorizon=60|UseMarketIndicatorVolatilityBenchmark=^VIX|UseStopLimitScaling=True|StopLimitScalingType=AverageTrueRange|StopLimitScalingVolatilityDays=30|SellOnDMABreak=True|DMABreakValues=200|DMABreakForceBreak=False|EntryType=OverExtended,MVP,PriceTrend,VolumeTrend|EntryHorizon=30|CandidateExpiryDays=180|VolumeTrendDays=10|ChannelBreakoutHorizon=40|UseOverExtendedIndicatorDays=45|UseOverExtendedIndicatorViolationThreshhold=1|UseOverExtendedIndicatorMarginPercent=1|MaxBeta=10|UseMaxBeta=False|UseProfitMaximization=True|UseProfitMaximizationExpression=R_THRESSHOLD=4;MAX_ATR=3;MULTIPLIER=MAX_ATR;IF(RMultiple>=R_THRESSHOLD){MULTIPLIER=1.2;}|UseTradeOnlySectors=False|UseTradeOnlySectorsSectors=Healthcare,Technology,Basic Materials,Consumer Defensive,Industrials|EvaluateStopOnUpTrend=False +SuspendTrading=False|UsePriceSlopeIndicator=True|UsePriceSlopeIndicatorDays=252|AnalysisDate=2/27/2026|BetaMonths=6|TradeDate=2/27/2026|MarketCapLowerLimit=500000000|SidewaysDetection=False|SidewaysAfterDays=30|PriceTrendDays=20|CheckOutliersInReturnStream=True|DailyReturnLimit=0.25|MaxDailyPositions=3|MaxOpenPositions=3|NoTradeSymbols=CODYY,MARUY,CSTM,CS,NATI,QADA,CRTO,GTBIF,CLCT,PRSC,CMD,STAY,GBTC,YOKU,PNY,RFMD,ASAZY,USMO,VNR,STB,XIV,SYNT,DFP|OnlyTradeSymbols=|MinRSI=70|InitialCash=10000|TotalRiskPercentDecimal=0.05|PositionRiskPercentDecimal=0.12|EquityOnly=False|MinPercentReturnProximityTo52WeekHigh=30|MinPercentReturnOver52WeekLow=80|ProfitMarginCheck=True|EPSCheck=True|MinDaysBetweenReholding=30|LiquidityCheck=True|MinVolume=1000|DMA200Horizon=15|MinDaysBetweenStopAdjustments=30|MinDaysBetweenInitialStopAdjustment=5|MaxPricingExceptions=3|MACDSetup=(12,26,9)|MACDSignalDays=5|MACDRejectStrongSells=True|MACDRejectWeakSells=True|UseMarketIndicator=True|Benchmark=SPY|BenchmarkMovingAverageDays=200|BenchmarkMovingAverageHorizon=5|UseMarketIndicatorVolatility=True|UseMarketIndicatorVolatilityHorizon=60|UseMarketIndicatorVolatilityBenchmark=^VIX|UseStopLimitScaling=True|StopLimitScalingType=AverageTrueRange|StopLimitScalingVolatilityDays=30|SellOnDMABreak=True|DMABreakValues=200|DMABreakForceBreak=False|EntryType=OverExtended,MVP,PriceTrend,VolumeTrend|EntryHorizon=30|CandidateExpiryDays=180|VolumeTrendDays=10|ChannelBreakoutHorizon=40|UseOverExtendedIndicatorDays=45|UseOverExtendedIndicatorViolationThreshhold=1|UseOverExtendedIndicatorMarginPercent=1|MaxBeta=10|UseMaxBeta=False|UseProfitMaximization=True|UseProfitMaximizationExpression=R_THRESSHOLD=4;MAX_ATR=3;MULTIPLIER=MAX_ATR;IF(RMultiple>=R_THRESSHOLD){MULTIPLIER=1.2;}|UseTradeOnlySectors=False|UseTradeOnlySectorsSectors=Healthcare,Technology,Basic Materials,Consumer Defensive,Industrials|EvaluateStopOnUpTrend=False PricingExceptions=0 TotalActivePositions=2 -Symbol=HWM|PurchaseDate=11/17/2025 12:00:00 AM|SellDate=1/1/0001 12:00:00 AM|Shares=11|PurchasePrice=200.81|CurrentPrice=260.31|Exposure=2208.91|MarketValue=2863.41|GainLoss=654.5|GainLossPcnt=0.296299985060505|PositionRiskDecimal=0.12|R=24.0336|C=276.15000000000003|P=11.490163770720992|InitialStopLimit=176.71|TrailingStopLimit=235.233001537323|TotalRiskExposure=264.3696|RMultiple=2.48R|Volatility=3.682325839996338|Volume=0|LastStopAdjustment=2/25/2026 12:00:00 AM|Comment=Price changed on 11/18/2025 from $200.28 to $200.81 -Symbol=FTI|PurchaseDate=11/20/2025 12:00:00 AM|SellDate=1/1/0001 12:00:00 AM|Shares=41|PurchasePrice=43.23|CurrentPrice=67.29|Exposure=1772.4299999999998|MarketValue=2758.8900000000003|GainLoss=986.4600000000005|GainLossPcnt=0.5565579458709233|PositionRiskDecimal=0.12|R=5.2188|C=218.45950000000005|P=41.86010193914311|InitialStopLimit=38.04|TrailingStopLimit=62.83571408271789|TotalRiskExposure=213.9708|RMultiple=4.61R|Volatility=0.825829267501831|Volume=0|LastStopAdjustment=2/25/2026 12:00:00 AM|Comment=Price changed on 11/21/2025 from $43.49 to $43.23 +Symbol=HWM|PurchaseDate=11/17/2025 12:00:00 AM|SellDate=1/1/0001 12:00:00 AM|Shares=11|PurchasePrice=200.81|CurrentPrice=262.53|Exposure=2208.91|MarketValue=2887.83|GainLoss=678.9200000000001|GainLossPcnt=0.30735521139385497|PositionRiskDecimal=0.12|R=24.0336|C=276.15000000000003|P=11.490163770720992|InitialStopLimit=176.71|TrailingStopLimit=235.233001537323|TotalRiskExposure=264.3696|RMultiple=2.57R|Volatility=3.682325839996338|Volume=0|LastStopAdjustment=2/25/2026 12:00:00 AM|Comment=Price changed on 11/18/2025 from $200.28 to $200.81 +Symbol=FTI|PurchaseDate=11/20/2025 12:00:00 AM|SellDate=1/1/0001 12:00:00 AM|Shares=41|PurchasePrice=43.23|CurrentPrice=66.31|Exposure=1772.4299999999998|MarketValue=2718.71|GainLoss=946.2800000000002|GainLossPcnt=0.5338885033541524|PositionRiskDecimal=0.12|R=5.2188|C=218.45950000000005|P=41.86010193914311|InitialStopLimit=38.04|TrailingStopLimit=62.83571408271789|TotalRiskExposure=213.9708|RMultiple=4.42R|Volatility=0.825829267501831|Volume=0|LastStopAdjustment=2/25/2026 12:00:00 AM|Comment=Price changed on 11/21/2025 from $43.49 to $43.23 TotalPositions=133 Symbol=CDNS|PurchaseDate=8/25/2020 12:00:00 AM|SellDate=9/3/2020 12:00:00 AM|Shares=16|PurchasePrice=111.82|CurrentPrice=109.57|Exposure=1789.12|MarketValue=1753.12|GainLoss=-36|GainLossPcnt=-0.020121624038633518|PositionRiskDecimal=0.12|R=13.3512|C=225.6365|P=16.900091377554077|InitialStopLimit=97.9088|TrailingStopLimit=109.599856939316|TotalRiskExposure=213.6192|RMultiple=-0.17R|Volatility=2.3209912776947|Volume=1767980|LastStopAdjustment=9/2/2020 12:00:00 AM|Comment=Manual close. Symbol=LULU|PurchaseDate=8/28/2020 12:00:00 AM|SellDate=9/4/2020 12:00:00 AM|Shares=3|PurchasePrice=377.5|CurrentPrice=370.23|Exposure=1132.5|MarketValue=1110.69|GainLoss=-21.809999999999945|GainLossPcnt=-0.019258278145695317|PositionRiskDecimal=0.12|R=45.2976|C=136.6285|P=3.016241478577231|InitialStopLimit=332.1824|TrailingStopLimit=372.562428512573|TotalRiskExposure=135.89280000000002|RMultiple=-0.16R|Volatility=25.858959197998|Volume=2871665|LastStopAdjustment=9/2/2020 12:00:00 AM|Comment=Manual close. diff --git a/MarketData/MarketDataLib/Cache/GLPriceCache.cs b/MarketData/MarketDataLib/Cache/GLPriceCache.cs index bbc3603..c8b1ca9 100644 --- a/MarketData/MarketDataLib/Cache/GLPriceCache.cs +++ b/MarketData/MarketDataLib/Cache/GLPriceCache.cs @@ -17,9 +17,25 @@ namespace MarketData.Cache private static GLPriceCache instance = null; // -- Disposal ------------------------------------------------------------- private volatile bool disposed = false; - private int refreshInProgress = 0; + // -- State ---------------------------------------------------------------- + private readonly Dictionary priceCache = new Dictionary(); + private readonly ConcurrentDictionary symbolFetchLocks = new ConcurrentDictionary(); + private readonly object cacheLock = new object(); + private DateTime latestDate = Utility.Epoch; + + // -- Background refresh --------------------------------------------------- + private readonly TimeSpan cacheCycle = TimeSpan.FromMinutes(5); + private Timer refreshTimer = null; + private int tickCount = 0; +// private const int evictionTickInterval = 12; // every 12 ticks x 5 min = 1 hour + private const int evictionTickInterval = 144; // every 144 ticks x 5 min interval length = 12 hour. (144 intervals *5 minutes )/60 minutes = 12 hours + + // -- Parallelism ---------------------------------------------------------- + private static readonly int maxParallelDbCalls = ResolveMaxParallelDbCalls(); + + /// /// /// @@ -33,21 +49,6 @@ namespace MarketData.Cache } } - // -- State ---------------------------------------------------------------- - private readonly Dictionary priceCache = new Dictionary(); - private readonly ConcurrentDictionary symbolFetchLocks = new ConcurrentDictionary(); - private readonly object cacheLock = new object(); - private DateTime latestDate = Utility.Epoch; - - // -- Background refresh --------------------------------------------------- - private readonly TimeSpan cacheCycle = TimeSpan.FromMinutes(5); - private Timer refreshTimer = null; - private int tickCount = 0; - private const int evictionTickInterval = 12; // every 12 ticks x 5 min = 1 hour - - // -- Parallelism ---------------------------------------------------------- - private static readonly int maxParallelDbCalls = ResolveMaxParallelDbCalls(); - private static int ResolveMaxParallelDbCalls() { return Math.Min(Math.Max(1, Environment.ProcessorCount) * 3, 32);