Add changes to all models to eliminate selling and immediately buying back the same security as this is considered a Wash Trade and is illegal.
Some checks failed
Build .NET Project / build (push) Has been cancelled

This commit is contained in:
2026-03-19 19:49:09 -04:00
parent 230e2b931f
commit e48588c13a
5 changed files with 22 additions and 13 deletions

View File

@@ -622,7 +622,7 @@ namespace MarketData.Generator.CMTrend
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("TradeDate ({0}) must be greater than or equal to the max position date ({1}) in the trade file.",TradeDate.ToShortDateString(),ActivePositions.Select(x => x.PurchaseDate).Max().ToShortDateString()));
return result;
}
ManageOpenPositions(TradeDate);
List<String> closedSymbols = ManageOpenPositions(TradeDate); // get any closed positions so we can avoid selling and buying (wash trades)
ManageCandidates(TradeDate);
// ************************************************************************************************************************************************************************
// **************************************************************************** N E W P O S I T I O N S *****************************************************************
@@ -640,7 +640,7 @@ namespace MarketData.Generator.CMTrend
result.Success=true;
return result;
}
Positions positions=BuyCandidates(TradeDate,CashBalance,ActivePositions.GetSymbols());
Positions positions=BuyCandidates(TradeDate,CashBalance,new List<String>(ActivePositions.GetSymbols().Concat(closedSymbols)));
if(null != positions && 0!=positions.Count)
{
MDTrace.WriteLine(LogLevel.DEBUG,"******************** B U Y ********************");
@@ -735,7 +735,7 @@ namespace MarketData.Generator.CMTrend
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("TradeDate ({0}) must be greater than or equal to the max position date ({1}) in the trade file.",TradeDate.ToShortDateString(),ActivePositions.Select(x => x.PurchaseDate).Max().ToShortDateString()));
return result;
}
ManageOpenPositions(TradeDate);
List<String> closedSymbols = ManageOpenPositions(TradeDate);
ManageCandidates(TradeDate);
if(ActivePositions.PositionsOn(TradeDate)>=Parameters.MaxDailyPositions)
{
@@ -743,7 +743,7 @@ namespace MarketData.Generator.CMTrend
result.Success=true;
continue;
}
Positions positions=BuyCandidates(TradeDate,CashBalance,ActivePositions.GetSymbols());
Positions positions=BuyCandidates(TradeDate,CashBalance,new List<String>(ActivePositions.GetSymbols().Concat(closedSymbols)));
if(null!=positions&&0!=positions.Count)
{
MDTrace.WriteLine(LogLevel.DEBUG,"******************** B U Y ********************");
@@ -885,9 +885,10 @@ namespace MarketData.Generator.CMTrend
// ***********************************************************************************************************************************************************************
// *********************************************************************** M A N A G E O P E N P O S I T I O N S *****************************************************
// ***********************************************************************************************************************************************************************
private void ManageOpenPositions(DateTime tradeDate)
private List<String> ManageOpenPositions(DateTime tradeDate)
{
if(0==ActivePositions.Count) return;
List<String> closedSymbols = new List<String>();
if(0==ActivePositions.Count) return closedSymbols;
Positions closedPositions = new Positions();
foreach(Position position in ActivePositions)
{
@@ -960,6 +961,8 @@ namespace MarketData.Generator.CMTrend
ActivePositions.Remove(closedPosition);
}
}
if(closedPositions.Count>0)closedSymbols = closedPositions.ConvertAll(x => x.Symbol);
return closedSymbols;
}
// **********************************************************************************************************************************************************