Add logic to all models to avoid selling and immediately buying back the same security as this is considered a Wash Trade and is illegal.
This commit is contained in:
@@ -623,7 +623,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); // capture any closed symbols so we don't re-enter immediately (wash trades)
|
||||
ManageCandidates(TradeDate);
|
||||
// ************************************************************************************************************************************************************************
|
||||
// **************************************************************************** N E W P O S I T I O N S *****************************************************************
|
||||
@@ -641,7 +641,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); // capture any closed symbols so we don't re-enter immediately (wash trades)
|
||||
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 ********************");
|
||||
@@ -884,11 +884,11 @@ 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();
|
||||
// List<Position> closedPositions=new List<Position>();
|
||||
foreach(Position position in ActivePositions)
|
||||
{
|
||||
Price price=GBPriceCache.GetInstance().GetPrice(position.Symbol,tradeDate);
|
||||
@@ -960,6 +960,8 @@ namespace MarketData.Generator.CMTrend
|
||||
ActivePositions.Remove(closedPosition);
|
||||
}
|
||||
}
|
||||
if(closedPositions.Count>0)closedSymbols = closedPositions.ConvertAll(x => x.Symbol);
|
||||
return closedSymbols;
|
||||
}
|
||||
|
||||
// **********************************************************************************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user