Momnentum Generator using precalculated BetaCalc36
This commit is contained in:
9
MarketData/MarketData/Models/runbacktest.sh
Executable file
9
MarketData/MarketData/Models/runbacktest.sh
Executable file
@@ -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
|
||||||
@@ -74,27 +74,27 @@ namespace MarketData.Generator.Momentum
|
|||||||
Profiler profiler = new Profiler();
|
Profiler profiler = new Profiler();
|
||||||
Dictionary<String,DateTime> latestDates = PricingDA.GetLatestDates(symbols);
|
Dictionary<String,DateTime> latestDates = PricingDA.GetLatestDates(symbols);
|
||||||
symbols=symbols.Where(x => latestDates.ContainsKey(x) && latestDates[x].Date>=tradeDate.Date).ToList();
|
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
|
// Prefetch a subset of fundamentals where each fundamental.asof is no greater than tradeDate
|
||||||
profiler.Reset();
|
profiler.Reset();
|
||||||
FundamentalsV2 fundamentals = FundamentalDA.GetFundamentalsMaxDateV2(tradeDate);
|
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
|
// Prefetch the Company Profiles
|
||||||
profiler.Reset();
|
profiler.Reset();
|
||||||
Dictionary<String,CompanyProfile> companyProfiles = CompanyProfileDA.GetCompanyProfiles(symbols);
|
Dictionary<String,CompanyProfile> 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
|
// Prefetch the Analyst Ratings
|
||||||
profiler.Reset();
|
profiler.Reset();
|
||||||
Dictionary<String,AnalystRatings> analystRatingsDictionary = AnalystRatingsDA.GetAnalystRatingsDowngradesMaxDateNoZacks(symbols, tradeDate);
|
Dictionary<String,AnalystRatings> 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
|
// Prefetch Zacks Ranks
|
||||||
profiler.Reset();
|
profiler.Reset();
|
||||||
Dictionary<String,ZacksRank> zacksRanksDictionary = ZacksRankDA.GetZacksRankOnOrBefore(symbols, tradeDate);
|
Dictionary<String,ZacksRank> 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"));
|
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Generate momentum.. examining candidates"));
|
||||||
// Go through the universe of stocks
|
// 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
|
// 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
|
// 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
|
// 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);
|
Prices benchmarkPrices=GBPriceCache.GetInstance().GetPrices(config.Benchmark,tradeDate,config.LowSlopeBetaDays);
|
||||||
pricesArray=Numerics.ToDouble(benchmarkPrices.GetPricesLow());
|
pricesArray=Numerics.ToDouble(benchmarkPrices.GetPricesLow());
|
||||||
@@ -324,7 +326,7 @@ namespace MarketData.Generator.Momentum
|
|||||||
highPECandidate.MaxDrawdown=prices.MaxDrawdown();
|
highPECandidate.MaxDrawdown=prices.MaxDrawdown();
|
||||||
highPECandidate.MaxUpside=prices.MaxUpside();
|
highPECandidate.MaxUpside=prices.MaxUpside();
|
||||||
highPECandidate.PE=fundamental.PE;
|
highPECandidate.PE=fundamental.PE;
|
||||||
highPECandidate.Beta=fundamental.Beta;
|
highPECandidate.Beta=beta;
|
||||||
highPECandidate.Velocity=velocity;
|
highPECandidate.Velocity=velocity;
|
||||||
highPECandidate.Volume=price.Volume;
|
highPECandidate.Volume=price.Volume;
|
||||||
highPECandidate.Return1D=return1D;
|
highPECandidate.Return1D=return1D;
|
||||||
@@ -344,7 +346,7 @@ namespace MarketData.Generator.Momentum
|
|||||||
momentumCandidate.MaxDrawdown=prices.MaxDrawdown();
|
momentumCandidate.MaxDrawdown=prices.MaxDrawdown();
|
||||||
momentumCandidate.MaxUpside=prices.MaxUpside();
|
momentumCandidate.MaxUpside=prices.MaxUpside();
|
||||||
momentumCandidate.PE=fundamental.PE;
|
momentumCandidate.PE=fundamental.PE;
|
||||||
momentumCandidate.Beta=fundamental.Beta;
|
momentumCandidate.Beta=beta;
|
||||||
momentumCandidate.Velocity=velocity;
|
momentumCandidate.Velocity=velocity;
|
||||||
momentumCandidate.Volume=price.Volume;
|
momentumCandidate.Volume=price.Volume;
|
||||||
momentumCandidate.Return1D=return1D;
|
momentumCandidate.Return1D=return1D;
|
||||||
|
|||||||
Reference in New Issue
Block a user