Code cleanup and optimization of CMTModel, code cleanup MGSH, added ConsoleColor to MDTrace.
This commit is contained in:
@@ -95,7 +95,7 @@ namespace MarketData.Generator.CMTrend
|
||||
}
|
||||
// Current Price Check
|
||||
Price currentPrice=prices[0];
|
||||
if(currentPrice.Date!=tradeDate)
|
||||
if(currentPrice.Date.Date!=tradeDate.Date)
|
||||
{
|
||||
cmtCandidate.Violation=true;
|
||||
cmtCandidate.Symbol=symbol;
|
||||
@@ -203,8 +203,13 @@ namespace MarketData.Generator.CMTrend
|
||||
|
||||
// Trend #8 check. Evaluate the RSI
|
||||
// generate a 14 day standard RSI with 30 days of pricing data
|
||||
RSICollection rsiCollection=RSIGenerator.GenerateRSI(symbol,currentPrice.Date,30);
|
||||
if(null==rsiCollection||0==rsiCollection.Count||rsiCollection[rsiCollection.Count-1].RSI<cmtParams.MinRSI)
|
||||
Prices rsiPrices=GBPriceCache.GetInstance().GetPrices(symbol,currentPrice.Date,30);
|
||||
RSICollection rsiCollection=RSIGenerator.GenerateRSI(rsiPrices);
|
||||
double rsi=rsiCollection[rsiCollection.Count-1].RSI;
|
||||
|
||||
// RSICollection rsiCollection=RSIGenerator.GenerateRSI(symbol,currentPrice.Date,30);
|
||||
// double rsi=rsiCollection[rsiCollection.Count-1].RSI;
|
||||
if(null==rsiCollection||0==rsiCollection.Count||rsi<cmtParams.MinRSI)
|
||||
{
|
||||
cmtCandidate.Violation=true;
|
||||
cmtCandidate.Symbol=symbol;
|
||||
|
||||
@@ -34,11 +34,8 @@ namespace MarketData.Generator.CMTrend
|
||||
}
|
||||
}
|
||||
// *****************************************************************************
|
||||
public class CMTSessionManager
|
||||
public static class CMTSessionManager
|
||||
{
|
||||
private CMTSessionManager()
|
||||
{
|
||||
}
|
||||
public static bool SaveSession(CMTSessionParams sessionParams,String pathSessionFile)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace MarketData.Generator.CMTrend
|
||||
try
|
||||
{
|
||||
List<String> symbols=PricingDA.GetSymbols();
|
||||
Dictionary<String,DateTime> latestDates = PricingDA.GetLatestDates(symbols);
|
||||
symbols=symbols.Where(x => latestDates.ContainsKey(x) && latestDates[x].Date>=tradeDate.Date).ToList();
|
||||
for(int index=0;index<symbols.Count;index++)
|
||||
{
|
||||
String symbol=symbols[index];
|
||||
|
||||
@@ -536,8 +536,8 @@ namespace MarketData.Generator.MGSHMomentum
|
||||
AnalysisDate=analysisDate;
|
||||
|
||||
if(startDate != TradeDate)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"Unexpectd StartDate. Start Date:{startDate.ToShortDateString()} Trade Date:{TradeDate.ToShortDateString()}");
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,ConsoleColor.Red,$"Unexpectd StartDate. Start Date:{startDate.ToShortDateString()} Trade Date:{TradeDate.ToShortDateString()}");
|
||||
return new MGSHBacktestResult(false, CashBalance);
|
||||
}
|
||||
|
||||
@@ -826,6 +826,14 @@ namespace MarketData.Generator.MGSHMomentum
|
||||
{
|
||||
EvaluateStopPrice(analysisDate, price, position);
|
||||
}
|
||||
else
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("[UpdateStopLimitsForActivePositions] No stop adjustment for {0} on {1} because low price {2} is less then or equal to the purchase price {3}.",
|
||||
position.Symbol,
|
||||
analysisDate.ToShortDateString(),
|
||||
Utility.FormatCurrency(price.Low),
|
||||
Utility.FormatCurrency(position.PurchasePrice)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(0!=closedPositions.Count)
|
||||
@@ -1063,8 +1071,8 @@ namespace MarketData.Generator.MGSHMomentum
|
||||
{
|
||||
List<MGSHPosition> positions=ActivePositions[slotIndex];
|
||||
if(null==positions||0==positions.Count)continue;
|
||||
exposure+=(from Position position in positions select position.Exposure).Sum();
|
||||
marketValue+=(from Position position in positions select position.MarketValue).Sum();
|
||||
exposure+=(from MGSHPosition position in positions select position.Exposure).Sum();
|
||||
marketValue+=(from MGSHPosition position in positions select position.MarketValue).Sum();
|
||||
}
|
||||
gainLoss.Exposure=exposure;
|
||||
gainLoss.MarketValue=marketValue;
|
||||
|
||||
@@ -66,13 +66,19 @@ namespace MarketData.Generator
|
||||
}
|
||||
rsiCollection=new RSICollection(rsiCollection.Skip(rsiDayCount).ToList());
|
||||
return rsiCollection;
|
||||
// return rsiCollection;
|
||||
}
|
||||
|
||||
public static RSICollection GenerateRSI(String symbol,DateTime analysisDate,int priceCount,int rsiDayCount=14)
|
||||
{
|
||||
if(priceCount<rsiDayCount)priceCount=(rsiDayCount*2)+1;
|
||||
Prices prices=PricingDA.GetPrices(symbol,analysisDate,priceCount);
|
||||
if(null==prices||priceCount!=prices.Count)return null;
|
||||
return GenerateRSI(prices, rsiDayCount);
|
||||
}
|
||||
|
||||
public static RSICollection GenerateRSI(Prices prices,int rsiDayCount=14)
|
||||
{
|
||||
if(null==prices || prices.Count<(rsiDayCount*2))return null;
|
||||
RSICollection rsiCollection=new RSICollection();
|
||||
for(int index=prices.Count-1;index>=0;index--)
|
||||
{
|
||||
@@ -119,7 +125,6 @@ namespace MarketData.Generator
|
||||
}
|
||||
rsiCollection=new RSICollection(rsiCollection.Skip(rsiDayCount).ToList());
|
||||
return rsiCollection;
|
||||
// return rsiCollection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,20 @@ namespace MarketData
|
||||
Console.WriteLine(message);
|
||||
Flush();
|
||||
}
|
||||
|
||||
/// <summary>WriteLine - Writes a line of text to trace log.</summary>
|
||||
/// <param name="message">string content of message to write.</param>
|
||||
/// <returns>void</returns>
|
||||
public static void WriteLine(LogLevel logLevel,ConsoleColor consoleColor,string message)
|
||||
{
|
||||
if(MDTrace.logLevel<logLevel)return;
|
||||
Trace.WriteLine(GetCallerIP()+GetThreadRep()+GetLogLevelRep()+"["+DateTime.Now.ToString()+"]"+" "+GetMethodInfo()+message);
|
||||
ConsoleColor currentColor=Console.ForegroundColor;
|
||||
Console.ForegroundColor = consoleColor;
|
||||
Console.WriteLine(message);
|
||||
Console.ForegroundColor=currentColor;
|
||||
Flush();
|
||||
}
|
||||
/// <summary>Indent - set trace log indentation.</summary>
|
||||
/// <returns>void</returns>
|
||||
// [Conditional("TRACE")]
|
||||
|
||||
Reference in New Issue
Block a user