Files
marketdata/MGSHMomentumHelper.cs
2025-02-06 16:50:01 -05:00

128 lines
5.1 KiB
C#

using MarketData.Generator.MGSHMomentum;
using System;
using System.Collections.Generic;
namespace MarketData
{
public static class MGSHMomentumHelper
{
public static void HandleMGSHSession(String[] args)
{
CommandArgs commandArgs = new CommandArgs(args);
if(!commandArgs.Has("SESSIONFILE"))
{
MDTrace.WriteLine(LogLevel.DEBUG,"Missing SESSIONFILE");
return;
}
MGSHMomentumBacktest momentumBacktest = new MGSHMomentumBacktest();
momentumBacktest.DisplaySession(commandArgs.Coalesce<String>("SESSIONFILE"));
}
public static void HandleMGSHRunDaily(String[] args)
{
CommandArgs commandArgs = new CommandArgs(args);
if(!commandArgs.Has("SESSIONFILE,TRADEDATE"))
{
MDTrace.WriteLine(LogLevel.DEBUG,"SESSIONFILE and TRADEDATE are required parameters.");
return;
}
DateTime tradeDate = commandArgs.Get<DateTime>("TRADEDATE");
String pathSessionFile = commandArgs.Get<String>("PATHSESSIONFILE");
MGSHMomentumBacktest momentumBacktest = new MGSHMomentumBacktest();
MGSHBacktestResult backtestResult = momentumBacktest.UpdateDaily(tradeDate, tradeDate, pathSessionFile);
backtestResult.Display();
}
public static void HandleMGSHRunBacktest(String[] args)
{
CommandArgs commandArgs = new CommandArgs(args);
MGSHConfiguration mgParams=new MGSHConfiguration();
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;
}
mgParams.MaxPositions=commandArgs.Coalesce<int>("MAXPOSITIONS");
mgParams.InitialCash=commandArgs.Coalesce<int>("INITIALCASH");
mgParams.HoldingPeriod=commandArgs.Coalesce<int>("HOLDINGPERIOD");
if(commandArgs.Has("INCLUDETRADEMASTERFORSYMBOLSHELD"))
{
mgParams.IncludeTradeMasterForSymbolsHeld=commandArgs.Get<bool>("INCLUDETRADEMASTERFORSYMBOLSHELD");
}
if(commandArgs.Has("USESTOCHASTICS"))
{
mgParams.UseStochastics=commandArgs.Coalesce<bool>("USESTOCHASTICS",true);
}
if(commandArgs.Has("USESTOPLIMITS"))
{
mgParams.UseStopLimits=commandArgs.Coalesce<bool>("USESTOPLIMITS",false);
}
if(commandArgs.Has("STOPLIMITRISKPERCENTDECIMAL"))
{
mgParams.StopLimitRiskPercentDecimal=commandArgs.Coalesce<double>("STOPLIMITRISKPERCENTDECIMAL",.12);
}
if(commandArgs.Has("USEHEDGING"))
{
mgParams.UseHedging=commandArgs.Coalesce<bool>("USEHEDGING",false);
if(commandArgs.Has("INITIALHEDGECASH"))
{
mgParams.HedgeInitialCash=commandArgs.Get<double>("INITIALHEDGECASH");
}
}
if(commandArgs.Has("KEEPSLOTPOSITIONS"))
{
mgParams.KeepSlotPositions=commandArgs.Get<bool>("KEEPSLOTPOSITIONS");
}
// ** M A C D
if(commandArgs.Has("USEMACD"))
{
mgParams.UseMACD=commandArgs.Coalesce<bool>("USEMACD",true);
}
if(commandArgs.Has("MACDREJECTSTRONGSELLSIGNALS"))
{
mgParams.MACDRejectStrongSellSignals=commandArgs.Coalesce<bool>("MACDREJECTSTRONGSELLSIGNALS",true);
}
if(commandArgs.Has("MACDREJECTWEAKSELLSIGNALS"))
{
mgParams.MACDRejectWeakSellSignals=commandArgs.Coalesce<bool>("MACDREJECTWEAKSELLSIGNALS",true);
}
if(commandArgs.Has("MACDSIGNALDAYS"))
{
mgParams.MACDSignalDays=commandArgs.Coalesce<int>("MACDSIGNALDAYS",mgParams.MACDSignalDays);
}
if(commandArgs.Has("MACDSETUP"))
{
mgParams.MACDSetup=commandArgs.Coalesce<String>("MACDSETUP",mgParams.MACDSetup);
}
// **
MGSHQualityIndicator qualityIndicator=new MGSHQualityIndicator(MGSHQualityIndicator.QualityType.IDIndicator);
if(commandArgs.Has("QUALITYINDICATORTYPE")) qualityIndicator.Quality=MGSHQualityIndicator.ToQuality(commandArgs.Coalesce<String>("QUALITYINDICATORTYPE","IDINDICATOR"));
mgParams.QualityIndicatorType=qualityIndicator.ToString();
mgParams.UseLowSlopeBetaCheck=true;
if(commandArgs.Has("USELOWSLOPEBETACHECK")) mgParams.UseLowSlopeBetaCheck=commandArgs.Coalesce<bool>("USELOWSLOPEBETACHECK",true);
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();
mgParams.DisplayHeader();
List<MGSHBacktestResult> results=new List<MGSHBacktestResult>();
MGSHMomentumBacktest backtestMomentum=new MGSHMomentumBacktest();
results.Add(backtestMomentum.PerformBacktest(startDate,endDate,pathSessionFileName,mgParams));
}
}
}