diff --git a/MarketData/MarketData/Models/runbacktest.sh b/MarketData/MarketData/Models/runbacktest.sh new file mode 100755 index 0000000..356075f --- /dev/null +++ b/MarketData/MarketData/Models/runbacktest.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# RUN THE BASLINE AND THEN SUBSTITUTE BETACALC36 FOR BETA IN THE MG MODEL AND RERUN THE TEST AND THEN COMPARE THE RESULTS + +export DOTNET_ROOT=/opt/dotnet +RUNDATE="$1" +#PATHMODEL="/home/pi/ARM64/MarketData/MarketData/Models/MGBACKTEST_BETA.TXT" +PATHMODEL="/home/pi/ARM64/MarketData/MarketData/Models/MGBACKTEST_BETA_CALC36.TXT" +/home/pi/ARM64/MarketData/MarketData/bin/Debug/net8.0/mk RUNBACKTEST /USELOWSLOPEBETACHECK:FALSE /STARTDATE:12/31/2018 /ENDDATE:03/31/2025 /INITIALCASH:10000 /MAXPOSITIONS:3 /HOLDINGPERIOD:3 /SESSIONFILE:$PATHMODEL /QUALITYINDICATORTYPE:SCOREINDICATOR diff --git a/MarketData/MarketDataLib/Generator/Momentum/MomentumGenerator.cs b/MarketData/MarketDataLib/Generator/Momentum/MomentumGenerator.cs index 71b5e4d..c7a1617 100755 --- a/MarketData/MarketDataLib/Generator/Momentum/MomentumGenerator.cs +++ b/MarketData/MarketDataLib/Generator/Momentum/MomentumGenerator.cs @@ -74,27 +74,27 @@ namespace MarketData.Generator.Momentum Profiler profiler = new Profiler(); Dictionary 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)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Pricing Dates in {Utility.FormatNumber(profiler.End(),0,true)} (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)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Fundamentals in {Utility.FormatNumber(profiler.End(),0,true)} (ms)"); // Prefetch the Company Profiles profiler.Reset(); Dictionary companyProfiles = CompanyProfileDA.GetCompanyProfiles(symbols); - MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Company Profiles in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Company Profiles in {Utility.FormatNumber(profiler.End(),0,true)} (ms)"); // Prefetch the Analyst Ratings profiler.Reset(); Dictionary analystRatingsDictionary = AnalystRatingsDA.GetAnalystRatingsDowngradesMaxDateNoZacks(symbols, tradeDate); - MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Analyst Ratings in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Analyst Ratings in {Utility.FormatNumber(profiler.End(),0,true)} (ms)"); // Prefetch Zacks Ranks profiler.Reset(); Dictionary zacksRanksDictionary = ZacksRankDA.GetZacksRankOnOrBefore(symbols, tradeDate); - MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Zacks Ranks in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Zacks Ranks in {Utility.FormatNumber(profiler.End(),0,true)} (ms)"); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Generate momentum.. examining candidates")); // Go through the universe of stocks @@ -208,7 +208,9 @@ namespace MarketData.Generator.Momentum // Get the benchmark pricing low pricing data and check the slope of previous lows; only if Beta of candidate is >= LowSlopeBetaThreshhold // The idea behind this check is that a high beta stock will track to the benchmark. So if the benchmark lows are forming a downward pattern then we // assume that this is a somewhat bearish condition. The config has the setting at a 15 day check and the threshold beta set to 1.00 - if(config.UseLowSlopeBetaCheck && fundamental.Beta>=config.LowSlopeBetaThreshhold) +// The BetaCalc36 is calculated as part of the monthly fundamental run. + double beta = fundamental.BetaCalc36; + if(config.UseLowSlopeBetaCheck && beta >= config.LowSlopeBetaThreshhold) { Prices benchmarkPrices=GBPriceCache.GetInstance().GetPrices(config.Benchmark,tradeDate,config.LowSlopeBetaDays); pricesArray=Numerics.ToDouble(benchmarkPrices.GetPricesLow()); @@ -324,7 +326,7 @@ namespace MarketData.Generator.Momentum highPECandidate.MaxDrawdown=prices.MaxDrawdown(); highPECandidate.MaxUpside=prices.MaxUpside(); highPECandidate.PE=fundamental.PE; - highPECandidate.Beta=fundamental.Beta; + highPECandidate.Beta=beta; highPECandidate.Velocity=velocity; highPECandidate.Volume=price.Volume; highPECandidate.Return1D=return1D; @@ -344,7 +346,7 @@ namespace MarketData.Generator.Momentum momentumCandidate.MaxDrawdown=prices.MaxDrawdown(); momentumCandidate.MaxUpside=prices.MaxUpside(); momentumCandidate.PE=fundamental.PE; - momentumCandidate.Beta=fundamental.Beta; + momentumCandidate.Beta=beta; momentumCandidate.Velocity=velocity; momentumCandidate.Volume=price.Volume; momentumCandidate.Return1D=return1D;