Put the CMMomentum command line code into a helper class.
This commit is contained in:
@@ -71,6 +71,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="CMMomentumHelper.cs" />
|
||||||
<Compile Include="CMTrendHelper.cs" />
|
<Compile Include="CMTrendHelper.cs" />
|
||||||
<Compile Include="CommandArgs.cs" />
|
<Compile Include="CommandArgs.cs" />
|
||||||
<Compile Include="MGSHMomentumHelper.cs" />
|
<Compile Include="MGSHMomentumHelper.cs" />
|
||||||
|
|||||||
103
Program.cs
103
Program.cs
@@ -16,7 +16,6 @@ using MarketData.Numerical;
|
|||||||
using MarketData.ValueAtRisk;
|
using MarketData.ValueAtRisk;
|
||||||
using MarketData.Integration;
|
using MarketData.Integration;
|
||||||
using MarketData.Generator.Momentum;
|
using MarketData.Generator.Momentum;
|
||||||
using MarketData.Generator.CMMomentum;
|
|
||||||
using MarketData.MarketDataModel.GainLoss;
|
using MarketData.MarketDataModel.GainLoss;
|
||||||
using MarketData.Cache;
|
using MarketData.Cache;
|
||||||
using MarketData.Generator.CMTrend;
|
using MarketData.Generator.CMTrend;
|
||||||
@@ -24,7 +23,6 @@ using Axiom.Interpreter;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using MarketData.Generator.MovingAverage;
|
using MarketData.Generator.MovingAverage;
|
||||||
using MarketData.Generator.MGSHMomentum;
|
using MarketData.Generator.MGSHMomentum;
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
namespace MarketData
|
namespace MarketData
|
||||||
{
|
{
|
||||||
@@ -1828,35 +1826,19 @@ namespace MarketData
|
|||||||
// *************************************************************************************************************************************************************************************************************************
|
// *************************************************************************************************************************************************************************************************************************
|
||||||
else if(arg.Equals("RUNCMBACKTEST")) // CMMOMENTUM
|
else if(arg.Equals("RUNCMBACKTEST")) // CMMOMENTUM
|
||||||
{
|
{
|
||||||
RunCMMomentum(args);
|
CMMomentumHelper.RunCMMomentum(args);
|
||||||
}
|
}
|
||||||
else if (arg.Equals("CMSESSION")) // CMMOMENTUM
|
else if (arg.Equals("CMSESSION")) // CMMOMENTUM
|
||||||
{
|
{
|
||||||
CommandArgs commandArgs = new CommandArgs(args);
|
CMMomentumHelper.RunCMSession(args);
|
||||||
if (!commandArgs.Has("SESSIONFILE")) {MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Missing SESSIONFILE"));return 0;}
|
|
||||||
CMMomentumBacktest cmBacktest = new CMMomentumBacktest();
|
|
||||||
cmBacktest.DisplaySession(commandArgs.Coalesce<String>("SESSIONFILE"));
|
|
||||||
}
|
}
|
||||||
else if(arg.Equals("CMGAINLOSS")) // CMMOMENTUM
|
else if(arg.Equals("CMGAINLOSS")) // CMMOMENTUM
|
||||||
{
|
{
|
||||||
CommandArgs commandArgs=new CommandArgs(args);
|
CMMomentumHelper.RunCMGainLoss(args);
|
||||||
if(!commandArgs.Has("SESSIONFILE")) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Missing SESSIONFILE")); return 0; }
|
|
||||||
CMMomentumBacktest cmBacktest=new CMMomentumBacktest();
|
|
||||||
cmBacktest.DisplayGainLoss(commandArgs.Coalesce<String>("SESSIONFILE"));
|
|
||||||
}
|
}
|
||||||
else if (arg.Equals("CMCANDIDATELASTRESORT")) // CMMOMENTUM
|
else if (arg.Equals("CMCANDIDATELASTRESORT")) // CMMOMENTUM
|
||||||
{
|
{
|
||||||
CMParams cmParams = new CMParams();
|
CMMomentumHelper.RunCMCandidateLastResort(args);
|
||||||
List<String> candidates = Utility.ToList(cmParams.FallbackCandidateBestOf);
|
|
||||||
CommandArgs commandArgs = new CommandArgs(args);
|
|
||||||
if (!commandArgs.Has("TRADEDATE")) { MDTrace.WriteLine(LogLevel.DEBUG, "TRADEDATE required"); return 0; }
|
|
||||||
CMCandidate cmCandidate = CMCandidateGenerator.GetFallbackCandidateOfLastResort(candidates, commandArgs.Coalesce<DateTime>("TRADEDATE"), commandArgs.Coalesce<DateTime>("TRADEDATE"), cmParams);
|
|
||||||
if (null == cmCandidate) { MDTrace.WriteLine(LogLevel.DEBUG, "Unable to determine candidate of last resort."); return 0; }
|
|
||||||
foreach (String candidate in candidates)
|
|
||||||
{
|
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Candidate examined..{0}", candidate));
|
|
||||||
}
|
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Best candidate is {0}", cmCandidate.Symbol));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -4214,82 +4196,5 @@ namespace MarketData
|
|||||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0}",momentumCandidate.ToString()));
|
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0}",momentumCandidate.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// **********************************************************************************************************************************************************************************************
|
|
||||||
// *************************************************************************** C M M O M E N T U M ( B A C K T E S T & M O N T H L Y) ***********************************************************
|
|
||||||
// **********************************************************************************************************************************************************************************************
|
|
||||||
public static void RunCMMomentum(String[] args)
|
|
||||||
{
|
|
||||||
CommandArgs commandArgs=new CommandArgs(args);
|
|
||||||
if(!commandArgs.Has("STARTDATE,MAXPOSITIONS,INITIALCASH,HOLDINGPERIOD"))
|
|
||||||
{
|
|
||||||
if(!commandArgs.Has("STARTDATE")) MDTrace.WriteLine(LogLevel.DEBUG,"Missing STARTDATE");
|
|
||||||
if(!commandArgs.Has("MAXPOSITIONS")) MDTrace.WriteLine(LogLevel.DEBUG,"Missing MAXPOSITIONS");
|
|
||||||
if(!commandArgs.Has("INITIALCASH")) MDTrace.WriteLine(LogLevel.DEBUG,"Missing INITIALCASH");
|
|
||||||
if(!commandArgs.Has("HOLDINGPERIOD")) MDTrace.WriteLine(LogLevel.DEBUG,"Missing HOLDINGPERIOD");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMParams cmParams=new CMParams();
|
|
||||||
cmParams.AnalysisDate=commandArgs.Get<DateTime>("STARTDATE");
|
|
||||||
cmParams.MaxPositions=commandArgs.Get<int>("MAXPOSITIONS");
|
|
||||||
cmParams.InitialCash=commandArgs.Get<double>("INITIALCASH");
|
|
||||||
cmParams.HoldingPeriod=commandArgs.Get<int>("HOLDINGPERIOD");
|
|
||||||
|
|
||||||
if(commandArgs.Has("USECNN"))
|
|
||||||
{
|
|
||||||
if(!commandArgs.Has("USECNNCLIENT,USECNNDAYCOUNT"))
|
|
||||||
{
|
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG,"Missing USECNNCLIENT, USECNNDAYCOUNT");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cmParams.UseCNN=true;
|
|
||||||
cmParams.UseCNNHost=commandArgs.Get<String>("USECNNHOST");
|
|
||||||
cmParams.UseCNNDayCount=commandArgs.Get<int>("USECNNDAYCOUNT");
|
|
||||||
if(commandArgs.Has("USECNNREWARDPERCENTDECIMAL"))cmParams.UseCNNRewardPercentDecimal=commandArgs.Get<double>("USECNNREWARDPERCENTDECIMAL");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(commandArgs.Has("USEOVEREXTENDEDINDICATOR"))
|
|
||||||
{
|
|
||||||
if(!commandArgs.Has("USEOVEREXTENDEDINDICATORDAYS,USEOVEREXTENDEDINDICATORVIOLATIONTHRESHHOLD,USEOVEREXTENDEDINDICATORMARGINPERCENT"))
|
|
||||||
{
|
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG,"Missing USEOVEREXTENDEDINDICATORDAYS, USEOVEREXTENDEDINDICATORVIOLATIONTHRESHHOLD, USEOVEREXTENDEDINDICATORMARGINPERCENT");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cmParams.UseOverExtendedIndicator=commandArgs.Get<bool>("USEOVEREXTENDEDINDICATOR");
|
|
||||||
cmParams.UseOverExtendedIndicatorDays=commandArgs.Get<int>("USEOVEREXTENDEDINDICATORDAYS");
|
|
||||||
cmParams.UseOverExtendedIndicatorViolationThreshhold=commandArgs.Get<int>("USEOVEREXTENDEDINDICATORVIOLATIONTHRESHHOLD");
|
|
||||||
cmParams.UseOverExtendedIndicatorMarginPercent=commandArgs.Get<double>("USEOVEREXTENDEDINDICATORMARGINPERCENT");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(commandArgs.Has("USEMAXPOSITIONBUCKETWEIGHT")) // UseMaxPositionBucketWeight
|
|
||||||
{
|
|
||||||
if(!commandArgs.Has("USEMAXPOSITIONBUCKETWEIGHTMAXWEIGHT")) // UseMaxPositionBucketWeightMaxWeight
|
|
||||||
{
|
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG,"Missing USEMAXPOSITIONBUCKETWEIGHTMAXWEIGHT");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cmParams.UseMaxPositionBucketWeight=commandArgs.Get<bool>("USEMAXPOSITIONBUCKETWEIGHT");
|
|
||||||
cmParams.UseMaxPositionBucketWeightMaxWeight=commandArgs.Get<double>("USEMAXPOSITIONBUCKETWEIGHTMAXWEIGHT");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cmParams.UseMaxPositionBucketWeight=false;
|
|
||||||
cmParams.UseMaxPositionBucketWeightMaxWeight=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(commandArgs.Has("TARGETBETA"))cmParams.TargetBeta=commandArgs.Get<double>("TARGETBETA");
|
|
||||||
else cmParams.TargetBeta=1.00;
|
|
||||||
|
|
||||||
DateTime endDate=DateTime.Now;
|
|
||||||
String pathSessionFileName=commandArgs.Coalesce<String>("SESSIONFILE",null);
|
|
||||||
if(null!=pathSessionFileName) pathSessionFileName=pathSessionFileName.Trim();
|
|
||||||
cmParams.DisplayHeader();
|
|
||||||
|
|
||||||
CMMomentumBacktest backtestMomentum=new CMMomentumBacktest();
|
|
||||||
List<CMBacktestResult> results=new List<CMBacktestResult>();
|
|
||||||
results.Add(backtestMomentum.PerformBacktest(cmParams.AnalysisDate,endDate,pathSessionFileName,cmParams));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user