From a464132e14c1970e7dc3e4234aef929ae9c55259 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 14 Feb 2025 19:00:38 -0500 Subject: [PATCH] BetaGenerator test code. --- Program.cs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Program.cs b/Program.cs index 80b4e2d..08f1397 100644 --- a/Program.cs +++ b/Program.cs @@ -986,6 +986,63 @@ namespace MarketData Trace.Listeners.Add(new TextWriterTraceListener(strLogFile)); DateTime currentDate=DateTime.Now; + //List candidatesList = new List(); + //List differenceItems = new List(); + //String benchmark = "SPY"; + //int lowSlopeBetaDays = 15; + //List symbols = PricingDA.GetSymbols(); + //DateTime tradeDateA = DateTime.Parse("12-31-2024"); + //for (int index = 0; index < symbols.Count; index++) + //{ + // if (0 == (index % 500)) MDTrace.WriteLine(LogLevel.DEBUG, $"Working...{index}"); + // String symbol = symbols[index]; + // if (symbol.StartsWith("^")) continue; + // Price price = GBPriceCache.GetInstance().GetPrice(symbol, tradeDateA); + // if (null == price) continue; + // Prices prices = GBPriceCache.GetInstance().GetPrices(symbol, tradeDateA, (int)252); + // if (null == prices || prices.Count < 252) continue; + // Fundamental fundamental = FundamentalDA.GetFundamentalMaxDate(symbol, tradeDateA); + // if (null == fundamental) continue; + // if (double.IsNaN(fundamental.PE) || fundamental.PE <= 0.00) continue; + + // double fundamentalBeta = fundamental.Beta; + // double beta = BetaGenerator.Beta(symbol, tradeDateA, 36); + // if (double.IsNaN(beta) || double.IsNaN(fundamental.Beta)) continue; + + // if (0 == fundamentalBeta) fundamentalBeta = .00000000000000000001; + + // double difference = Math.Abs(((beta - fundamentalBeta) / fundamentalBeta)); + // if (difference > .25) // greater than 5% + // { + // differenceItems.Add(symbol); + // } + + // if (beta >= 1.00) + // { + // double[] pricesArray = null; + // LeastSquaresResult leastSquaresResult; + // Prices benchmarkPrices = GBPriceCache.GetInstance().GetPrices(benchmark, tradeDateA, lowSlopeBetaDays); + // pricesArray = Numerics.ToDouble(benchmarkPrices.GetPricesLow()); + // leastSquaresResult = Numerics.LeastSquares(pricesArray); + // double slopeBmk = leastSquaresResult.Slope; + // if (slopeBmk < 0) + // { + // continue; + // } + // } + // candidatesList.Add(symbol); + // //if(double.IsNaN(beta)) + // //{ + // // MDTrace.WriteLine(LogLevel.DEBUG,$"No beta for {symbol}"); + // //} + //} + + + + + + + DateTime maxHolidayDate =HolidayDA.GetMaxHolidayDate(); if(currentDate>maxHolidayDate) {