diff --git a/MGSHMomentumHelper.cs b/MGSHMomentumHelper.cs index 2227278..e065f45 100644 --- a/MGSHMomentumHelper.cs +++ b/MGSHMomentumHelper.cs @@ -1,6 +1,8 @@ using MarketData.Generator.MGSHMomentum; +using MarketData.Utils; using System; using System.Collections.Generic; +using System.IO; namespace MarketData { @@ -20,6 +22,7 @@ namespace MarketData public static void HandleMGSHRunDaily(String[] args) { + DateGenerator dateGenerator = new DateGenerator(); CommandArgs commandArgs = new CommandArgs(args); if(!commandArgs.Has("SESSIONFILE,TRADEDATE")) { @@ -27,10 +30,33 @@ namespace MarketData return; } DateTime tradeDate = commandArgs.Get("TRADEDATE"); - String pathSessionFile = commandArgs.Get("PATHSESSIONFILE"); + + if(!dateGenerator.IsMarketOpen(tradeDate)) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"TRADEDATE {tradeDate.ToShortDateString()} is not a trading date."); + return; + } + + DateTime endDate = dateGenerator.FindNextBusinessDay(tradeDate); // UpdateDaily will not process the endDate (i.e.) while(tradeDate("SESSIONFILE"); + pathSessionFile = pathSessionFile.Trim(); + if(!File.Exists(pathSessionFile)) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"The specified file '{pathSessionFile}' does not exist."); + return; + } + MGSHMomentumBacktest momentumBacktest = new MGSHMomentumBacktest(); - MGSHBacktestResult backtestResult = momentumBacktest.UpdateDaily(tradeDate, tradeDate, pathSessionFile); - backtestResult.Display(); + + if(!dateGenerator.IsMarketOpen(tradeDate)) + { + Console.WriteLine(String.Format("The market is closed today, please confirm Y/N:{0}?",tradeDate.ToShortDateString())); + String result=Console.ReadLine(); + if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES")))return; + } + + MGSHBacktestResult backtestResult = momentumBacktest.UpdateDaily(tradeDate, endDate, DateTime.Now, pathSessionFile); } public static void HandleMGSHRunBacktest(String[] args) @@ -115,13 +141,30 @@ namespace MarketData DateTime startDate = commandArgs.Coalesce("STARTDATE"); DateTime endDate=commandArgs.Coalesce("ENDDATE",new DateTime()); - String pathSessionFileName = commandArgs.Coalesce("SESSIONFILE", null); - if(null!=pathSessionFileName)pathSessionFileName=pathSessionFileName.Trim(); + DateGenerator dateGenerator = new DateGenerator(); + if(!dateGenerator.IsMarketOpen(startDate)) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"STARTDATE {startDate.ToShortDateString()} is not a trading date."); + return; + } + if(!dateGenerator.IsMarketOpen(endDate)) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"ENDDATE {endDate.ToShortDateString()} is not a trading date."); + return; + } + + if(!commandArgs.Has("SESSIONFILE")) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"SESSIONFILE is a required parameter."); + return; + } + + String pathSessionFile = commandArgs.Get("SESSIONFILE"); + pathSessionFile = pathSessionFile.Trim(); - mgParams.DisplayHeader(); List results=new List(); MGSHMomentumBacktest backtestMomentum=new MGSHMomentumBacktest(); - results.Add(backtestMomentum.PerformBacktest(startDate,endDate,pathSessionFileName,mgParams)); + results.Add(backtestMomentum.PerformBacktest(startDate, endDate, pathSessionFile, mgParams)); } } }