diff --git a/MarketData.csproj.user b/MarketData.csproj.user index 4078e29..998bb44 100644 --- a/MarketData.csproj.user +++ b/MarketData.csproj.user @@ -1,6 +1,6 @@  - UPDATEPRICES 08-21-2023 + RUNBACKTEST /STARTDATE:01-31-2018 /MAXPOSITIONS:3 /INITIALCASH:10000 /HOLDINGPERIOD:3 /INTRADAYMODE:FALSE /SESSIONFILE:MG20180131.TXT \ No newline at end of file diff --git a/MarketData.v12.suo b/MarketData.v12.suo index ae7295c..c6937bb 100644 Binary files a/MarketData.v12.suo and b/MarketData.v12.suo differ diff --git a/Program.cs b/Program.cs index 61e03e6..21de1f8 100644 --- a/Program.cs +++ b/Program.cs @@ -534,33 +534,36 @@ namespace MarketData // ****************************************************************** C U M U L A T I V E G A I N L O S S ************************************************************* // ****************************************************************************************************************************************************************************** // This is a test of a new model to calculate the cumulate gain loss for the GainLoss Window - private static void RunModelPerformance() + private static void RunModelPerformance(String symbol=null, bool useDividends=false) { GainLossGeneratorCum gainLossGeneratorCum=new GainLossGeneratorCum(); GainLossGenerator gainLossGenerator=new GainLossGenerator(); PortfolioTrades portfolioTrades=PortfolioDA.GetTrades(); DividendPayments dividendPayments=null; + + String strPathFileNameCumulative=String.Format("model_performance_dividends_cumulative_{0}.csv",null==symbol?"ALL":symbol); + String strPathFileNameNonCumulative=String.Format("model_performance_dividends_non_cumulative_{0}.csv",null==symbol?"ALL":symbol); - String symbol="ANF"; // SPY - portfolioTrades = PortfolioDA.GetTrades(symbol); + if(null==symbol)portfolioTrades = PortfolioDA.GetTrades(); + else portfolioTrades = PortfolioDA.GetTrades(symbol); -// dividendPayments=DividendPaymentDA.GetDividendPayments(); -// portfolioTrades = new PortfolioTrades(portfolioTrades.Where(x => x.Symbol.Equals(symbol)).ToList()); - - String strPathFileNameCumulative=String.Format("model_performance_dividends_cumulative_{0}.csv",symbol); - String strPathFileNameNonCumulative=String.Format("model_performance_dividends_non_cumulative_{0}.csv",symbol); + if(useDividends) + { + if(null!=symbol)dividendPayments=DividendPaymentDA.GetDividendPaymentsForSymbol(symbol); + else dividendPayments=DividendPaymentDA.GetDividendPayments(); + } // Run the cumulative version TotalGainLossCollection totalGainLossCollectionCum=null; - if(null!=dividendPayments)gainLossGeneratorCum.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments); - else gainLossGeneratorCum.GenerateTotalGainLoss(portfolioTrades); + if(null!=dividendPayments)totalGainLossCollectionCum=gainLossGeneratorCum.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments); + else totalGainLossCollectionCum=gainLossGeneratorCum.GenerateTotalGainLoss(portfolioTrades); Console.WriteLine(String.Format("Writing Cumulative Model to {0}",strPathFileNameCumulative)); SaveCollection(strPathFileNameCumulative, "CUMULATIVE", totalGainLossCollectionCum); // Run the regular version TotalGainLossCollection totalGainLossCollection=null; - if(null!=dividendPayments)gainLossGenerator.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments); - else gainLossGenerator.GenerateTotalGainLoss(portfolioTrades); + if(null!=dividendPayments)totalGainLossCollection=gainLossGenerator.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments); + else totalGainLossCollection=gainLossGenerator.GenerateTotalGainLoss(portfolioTrades); Console.WriteLine(String.Format("Writing Non-Cumulative Model to {0}",strPathFileNameNonCumulative)); SaveCollection(strPathFileNameNonCumulative, "NON-CUMULATIVE",totalGainLossCollection); } @@ -619,15 +622,15 @@ namespace MarketData Trace.Listeners.Add(new TextWriterTraceListener(strLogFile)); DateTime currentDate=DateTime.Now; - RunModelPerformance(); - Console.ReadLine(); - return 0; + //RunModelPerformance("SPY"); + //Console.ReadLine(); + //return 0; - // Price price=MarketDataHelper.GetLatestPriceFidelity("AAPL"); + // Price price=MarketDataHelper.GetLatestPriceFidelity("AAPL"); - - DateTime maxHolidayDate=HolidayDA.GetMaxHolidayDate(); + + DateTime maxHolidayDate =HolidayDA.GetMaxHolidayDate(); if(currentDate>maxHolidayDate) { Console.WriteLine(String.Format("There are no holidays defined in the system. Add holidays for year {0} into marketholidays table",currentDate.Year)); @@ -2242,9 +2245,10 @@ namespace MarketData { try { - List symbols = WatchListDA.GetWatchList(watchListName); - PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper(); - pricingMarketDataHelper.UpdateLatestPrices(symbols); + if(!CheckRunCriteria())return; + List symbols = WatchListDA.GetWatchList(watchListName); + PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper(); + pricingMarketDataHelper.UpdateLatestPrices(symbols); } catch (Exception exception) { @@ -2255,6 +2259,7 @@ namespace MarketData { try { + if(!CheckRunCriteria())return; PortfolioTrades portfolioTrades=PortfolioDA.GetOpenTrades(); List symbols=(from PortfolioTrade portfolioTrade in portfolioTrades select portfolioTrade.Symbol).Distinct().ToList(); if(symbols.Any(x=>x.Equals("SPY")))symbols.Add("SH"); @@ -3678,6 +3683,7 @@ namespace MarketData int sleepTime=2000; PremarketElements premarketElements=null; + if(!CheckRunCriteria())return; for(int retry=0;retry symbols = WatchListDA.GetWatchList(watchList); HeadlinesMarketDataHelper headlinesMarketDataHelper= new HeadlinesMarketDataHelper();