Implement new CNN Client code
This commit is contained in:
@@ -129,19 +129,31 @@ namespace MarketData.Generator.CMMomentum
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// This method is made public in order that it can be tested
|
||||
/// <summary>
|
||||
/// PredictCandidate - 2026 convnext version - Be sure that the model parameters has 90 days in UseCNNDayCount
|
||||
/// If we need to revert back to CNNClient.Model.resnet50_20241024_270 then uncomment the below method and update cmParams.UseCNNDayCount=270
|
||||
/// </summary>
|
||||
/// <param name="cmCandidate"></param>
|
||||
/// <param name="cmParams"></param>
|
||||
/// <returns></returns>
|
||||
public static bool PredictCandidate(CMCandidate cmCandidate,CMParams cmParams)
|
||||
{
|
||||
try
|
||||
{
|
||||
CNNClient cnnClient=new CNNClient(cmParams.UseCNNHost);
|
||||
DataProcessor dataProcessor=new DataProcessor();
|
||||
dataProcessor.Width=128;
|
||||
dataProcessor.Height=128;
|
||||
int imageDimensions=224;
|
||||
dataProcessor.Width=imageDimensions;
|
||||
dataProcessor.Height=imageDimensions;
|
||||
dataProcessor.PenWidth=1;
|
||||
TestCase testCase=new TestCase(cmCandidate.Symbol,cmCandidate.TradeDate,cmParams.UseCNNDayCount,TestCase.CaseType.Test,TestCase.GenerateType.BollingerBand,TestCase.OutputType.OutputStream);
|
||||
if(90!=cmParams.UseCNNDayCount)
|
||||
{
|
||||
throw new InvalidDataException("CNNClient.Model.convnext must be used with cmParams.UseCNNDayCount=90.");
|
||||
}
|
||||
TestCase testCase=new TestCase(cmCandidate.Symbol,cmCandidate.TradeDate,cmParams.UseCNNDayCount,TestCase.CaseType.Test,TestCase.GenerateType.BollingerBandWithVIX,TestCase.OutputType.OutputStream);
|
||||
dataProcessor.ProcessData(testCase);
|
||||
String prediction = cnnClient.Predict(CNNClient.Model.resnet50_20241024_270,testCase.LastStream);
|
||||
Stream streamResult = cnnClient.ProcessImage(testCase.LastStream); // process the image through PIL
|
||||
String prediction = cnnClient.Predict(CNNClient.Model.convnext,streamResult);
|
||||
prediction=prediction.Substring(prediction.IndexOf("-->"));
|
||||
int result=int.Parse(Utility.BetweenString(prediction,"[[","]"));
|
||||
if(1==result)
|
||||
@@ -157,5 +169,34 @@ namespace MarketData.Generator.CMMomentum
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Keep this until happy with the new model
|
||||
// This method is made public in order that it can be tested
|
||||
// public static bool PredictCandidate(CMCandidate cmCandidate,CMParams cmParams)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// CNNClient cnnClient=new CNNClient(cmParams.UseCNNHost);
|
||||
// DataProcessor dataProcessor=new DataProcessor();
|
||||
// dataProcessor.Width=128;
|
||||
// dataProcessor.Height=128;
|
||||
// dataProcessor.PenWidth=1;
|
||||
// TestCase testCase=new TestCase(cmCandidate.Symbol,cmCandidate.TradeDate,cmParams.UseCNNDayCount,TestCase.CaseType.Test,TestCase.GenerateType.BollingerBand,TestCase.OutputType.OutputStream);
|
||||
// dataProcessor.ProcessData(testCase);
|
||||
// String prediction = cnnClient.Predict(CNNClient.Model.resnet50_20241024_270,testCase.LastStream);
|
||||
// prediction=prediction.Substring(prediction.IndexOf("-->"));
|
||||
// int result=int.Parse(Utility.BetweenString(prediction,"[[","]"));
|
||||
// if(1==result)
|
||||
// {
|
||||
// cmCandidate.Score*=(1.00+cmParams.UseCNNRewardPercentDecimal); // increase the score by the percentage indicated in the params settings
|
||||
// cmCandidate.CNNPrediction=true;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// catch(Exception exception)
|
||||
// {
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Error encountered calling convolutional model at {0}. Exception was {1}",cmParams.UseCNNHost,exception.ToString()));
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user