Check dates.
This commit is contained in:
@@ -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<DateTime>("TRADEDATE");
|
||||
String pathSessionFile = commandArgs.Get<String>("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<endDate){;}
|
||||
|
||||
String pathSessionFile = commandArgs.Get<String>("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<DateTime>("STARTDATE");
|
||||
DateTime endDate=commandArgs.Coalesce<DateTime>("ENDDATE",new DateTime());
|
||||
|
||||
String pathSessionFileName = commandArgs.Coalesce<String>("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<String>("SESSIONFILE");
|
||||
pathSessionFile = pathSessionFile.Trim();
|
||||
|
||||
mgParams.DisplayHeader();
|
||||
List<MGSHBacktestResult> results=new List<MGSHBacktestResult>();
|
||||
MGSHMomentumBacktest backtestMomentum=new MGSHMomentumBacktest();
|
||||
results.Add(backtestMomentum.PerformBacktest(startDate,endDate,pathSessionFileName,mgParams));
|
||||
results.Add(backtestMomentum.PerformBacktest(startDate, endDate, pathSessionFile, mgParams));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user