Fix ImageHelper not rendering images due to issue in PointMapping.
Some checks failed
Build .NET Project / build (push) Has been cancelled
Some checks failed
Build .NET Project / build (push) Has been cancelled
This commit is contained in:
@@ -191,10 +191,12 @@ namespace MarketData.CNNProcessing
|
||||
if(null==NoiseArray)NoiseArray=new double[]{0.00};
|
||||
if(testCase.TypeGenerate.Equals(TestCase.GenerateType.BollingerBand))
|
||||
{
|
||||
testCase.PathFileNames.Add(CreateFileName("T",testCase.Symbol,testCase.DayCount,0,0,0,TestCase.CaseType.Test,TestCase.GenerateType.BollingerBand,testCase.PurchaseDate));
|
||||
ProcessBollingerBandData(testCase,PenWidthArray[0],NoiseArray[0]);
|
||||
}
|
||||
else if(testCase.TypeGenerate.Equals(TestCase.GenerateType.BollingerBandWithVIX))
|
||||
{
|
||||
testCase.PathFileNames.Add(CreateFileName("T",testCase.Symbol,testCase.DayCount,0,0,0,TestCase.CaseType.Test,TestCase.GenerateType.BollingerBandWithVIX,testCase.PurchaseDate));
|
||||
ProcessBollingerBandDataWithVolatility(testCase,PenWidthArray[0],NoiseArray[0]);
|
||||
}
|
||||
}
|
||||
@@ -243,35 +245,14 @@ namespace MarketData.CNNProcessing
|
||||
imageHelper.CreateImage(Width,Height,pointMapping);
|
||||
imageHelper.Fill(FillBrush);
|
||||
|
||||
LineSegments lineSegments=new LineSegments();
|
||||
for(int index=0;index<close.Length && DrawPrice;index++)
|
||||
{
|
||||
if(0==index)continue;
|
||||
SKPoint p1=new SKPoint(index-1,(int)close[index-1]);
|
||||
SKPoint p2=new SKPoint(index,(int)close[index]);
|
||||
lineSegments.Add(p1,p2);
|
||||
}
|
||||
imageHelper.DrawPath(DrawingBrush,penWidth,lineSegments);
|
||||
// draw price
|
||||
if(DrawPrice)imageHelper.DrawSeries(DrawingBrushRed,penWidth,close);
|
||||
|
||||
lineSegments.Clear();
|
||||
for(int index=0;index<k.Length;index++)
|
||||
{
|
||||
if(0==index)continue;
|
||||
SKPoint p1=new SKPoint(index-1,(int)k[index-1]);
|
||||
SKPoint p2=new SKPoint(index,(int)k[index]);
|
||||
lineSegments.Add(p1,p2);
|
||||
}
|
||||
imageHelper.DrawPath(DrawingBrush,penWidth,lineSegments);
|
||||
// draw k
|
||||
imageHelper.DrawSeries(DrawingBrushRed,penWidth,k);
|
||||
|
||||
lineSegments.Clear();
|
||||
for(int index=0;index<l.Length;index++)
|
||||
{
|
||||
if(0==index)continue;
|
||||
SKPoint p1=new SKPoint(index-1,(int)l[index-1]);
|
||||
SKPoint p2=new SKPoint(index,(int)l[index]);
|
||||
lineSegments.Add(p1,p2);
|
||||
}
|
||||
imageHelper.DrawPath(DrawingBrush,penWidth,lineSegments);
|
||||
// draw l
|
||||
imageHelper.DrawSeries(DrawingBrushRed,penWidth,l);
|
||||
|
||||
if(0.00!=noise)imageHelper.AddNoise(NoiseColor,noise);
|
||||
|
||||
@@ -349,48 +330,17 @@ namespace MarketData.CNNProcessing
|
||||
imageHelper.CreateImage(Width,Height,pointMapping);
|
||||
imageHelper.Fill(FillBrush);
|
||||
|
||||
LineSegments lineSegments=new LineSegments();
|
||||
// draw volatility
|
||||
for(int index=0;index<v.Length;index++)
|
||||
{
|
||||
if(0==index)continue;
|
||||
SKPoint p1=new SKPoint(index-1,(int)v[index-1]);
|
||||
SKPoint p2=new SKPoint(index,(int)v[index]);
|
||||
lineSegments.Add(p1,p2);
|
||||
}
|
||||
imageHelper.DrawPath(DrawingBrushRed,penWidth,lineSegments);
|
||||
imageHelper.DrawSeries(DrawingBrushRed,penWidth,v);
|
||||
|
||||
// draw prices
|
||||
lineSegments.Clear();
|
||||
for(int index=0;index<close.Length && DrawPrice;index++)
|
||||
{
|
||||
if(0==index)continue;
|
||||
SKPoint p1=new SKPoint(index-1,(int)close[index-1]);
|
||||
SKPoint p2=new SKPoint(index,(int)close[index]);
|
||||
lineSegments.Add(p1,p2);
|
||||
}
|
||||
imageHelper.DrawPath(DrawingBrush,penWidth,lineSegments);
|
||||
if(DrawPrice)imageHelper.DrawSeries(DrawingBrush,penWidth,close);
|
||||
|
||||
// draw k
|
||||
lineSegments.Clear();
|
||||
for(int index=0;index<k.Length;index++)
|
||||
{
|
||||
if(0==index)continue;
|
||||
SKPoint p1=new SKPoint(index-1,(int)k[index-1]);
|
||||
SKPoint p2=new SKPoint(index,(int)k[index]);
|
||||
lineSegments.Add(p1,p2);
|
||||
}
|
||||
imageHelper.DrawPath(DrawingBrush,penWidth,lineSegments);
|
||||
imageHelper.DrawSeries(DrawingBrush,penWidth,k);
|
||||
|
||||
// draw l
|
||||
lineSegments.Clear();
|
||||
for(int index=0;index<l.Length;index++)
|
||||
{
|
||||
if(0==index)continue;
|
||||
SKPoint p1=new SKPoint(index-1,(int)l[index-1]);
|
||||
SKPoint p2=new SKPoint(index,(int)l[index]);
|
||||
lineSegments.Add(p1,p2);
|
||||
}
|
||||
imageHelper.DrawPath(DrawingBrush,penWidth,lineSegments);
|
||||
imageHelper.DrawSeries(DrawingBrush,penWidth,l);
|
||||
|
||||
if(0.00!=noise)imageHelper.AddNoise(NoiseColor,noise);
|
||||
if(testCase.TypeOutput.Equals(TestCase.OutputType.OutputFile))
|
||||
|
||||
@@ -597,7 +597,7 @@ namespace MarketData.CNNProcessing
|
||||
using SKPaint paint = new SKPaint();
|
||||
paint.Style = SKPaintStyle.Stroke;
|
||||
paint.StrokeWidth = strokeWidth; // Set the desired stroke width
|
||||
paint.Color = SKColors.Black;
|
||||
paint.Color = color;
|
||||
foreach (LineSegment lineSegment in lineSegments)
|
||||
{
|
||||
SKPoint txSrcPoint = pointMapping.MapPoint(lineSegment.P1);
|
||||
@@ -605,7 +605,47 @@ namespace MarketData.CNNProcessing
|
||||
canvas.DrawLine(txSrcPoint, txDstPoint, paint);
|
||||
}
|
||||
}
|
||||
// public void DrawPath(SKColor color, float strokeWidth, LineSegments lineSegments)
|
||||
// {
|
||||
// Validate();
|
||||
|
||||
// using SKCanvas canvas = new SKCanvas(bitmap);
|
||||
// using SKPaint paint = new SKPaint();
|
||||
// paint.Style = SKPaintStyle.Stroke;
|
||||
// paint.StrokeWidth = strokeWidth; // Set the desired stroke width
|
||||
// paint.Color = SKColors.Black;
|
||||
// foreach (LineSegment lineSegment in lineSegments)
|
||||
// {
|
||||
// SKPoint txSrcPoint = pointMapping.MapPoint(lineSegment.P1);
|
||||
// SKPoint txDstPoint = pointMapping.MapPoint(lineSegment.P2);
|
||||
// canvas.DrawLine(txSrcPoint, txDstPoint, paint);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void DrawSeries(SKColor color, float strokeWidth, float[] data)
|
||||
{
|
||||
Validate();
|
||||
if (data == null || data.Length < 2)
|
||||
return;
|
||||
using SKCanvas canvas = new SKCanvas(bitmap);
|
||||
using SKPaint paint = new SKPaint
|
||||
{
|
||||
Style = SKPaintStyle.Stroke,
|
||||
StrokeWidth = strokeWidth,
|
||||
Color = color,
|
||||
IsAntialias = false
|
||||
};
|
||||
using SKPath path = new SKPath();
|
||||
SKPoint first = pointMapping.MapPoint(new SKPoint(0, data[0]));
|
||||
path.MoveTo(first);
|
||||
for (int i = 1; i < data.Length; i++)
|
||||
{
|
||||
SKPoint pt = pointMapping.MapPoint(new SKPoint(i, data[i]));
|
||||
path.LineTo(pt);
|
||||
}
|
||||
canvas.DrawPath(path, paint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a circle on the bitmap
|
||||
/// </summary>
|
||||
|
||||
@@ -29,7 +29,9 @@ namespace MarketData.CNNProcessing
|
||||
XMargin = pointMapping.XMargin;
|
||||
YMargin = pointMapping.YMargin;
|
||||
XDataExtent = pointMapping.XDataExtent;
|
||||
XDataExtentMin = pointMapping.XDataExtentMin;
|
||||
YDataExtent = pointMapping.YDataExtent;
|
||||
YDataExtentMin = pointMapping.YDataExtentMin;
|
||||
XScalingFactor = pointMapping.XScalingFactor;
|
||||
YScalingFactor = pointMapping.YScalingFactor;
|
||||
}
|
||||
@@ -43,15 +45,22 @@ namespace MarketData.CNNProcessing
|
||||
/// <returns></returns>
|
||||
public SKPoint MapPoint(SKPoint sourcePoint)
|
||||
{
|
||||
SKPoint mappedPoint = new SKPoint((int)((sourcePoint.X - XDataExtentMin) * XScalingFactor), (int)((Height - 1) - ((sourcePoint.Y - YDataExtentMin) * YScalingFactor)));
|
||||
mappedPoint.X += (int)XMargin; // offset by the xMargin
|
||||
mappedPoint.Y -= (int)YMargin; // offset by the yMargin
|
||||
if (mappedPoint.X > XDataExtent) mappedPoint.X = (int)XDataExtent; // constrain X to XDataExtent
|
||||
if (mappedPoint.Y > YDataExtent) mappedPoint.Y = (int)YDataExtent; // constrain Y to YDataExtent
|
||||
if (mappedPoint.X < XDataExtentMin) mappedPoint.X = (int)XDataExtentMin; // constrain X to XDataExtentMin
|
||||
if (mappedPoint.Y < YDataExtentMin) mappedPoint.Y = (int)YDataExtentMin; // constrain Y to YDataExtentMin
|
||||
return mappedPoint;
|
||||
}
|
||||
SKPoint mappedPoint = new SKPoint(
|
||||
(float)((sourcePoint.X - XDataExtentMin) * XScalingFactor),
|
||||
(float)((Height - 1) - ((sourcePoint.Y - YDataExtentMin) * YScalingFactor))
|
||||
);
|
||||
|
||||
mappedPoint.X += (float)XMargin;
|
||||
mappedPoint.Y -= (float)YMargin;
|
||||
|
||||
// Clamp to image bounds
|
||||
if (mappedPoint.X > Width - 1) mappedPoint.X = (float)(Width - 1);
|
||||
if (mappedPoint.Y > Height - 1) mappedPoint.Y = (float)(Height - 1);
|
||||
if (mappedPoint.X < 0) mappedPoint.X = 0;
|
||||
if (mappedPoint.Y < 0) mappedPoint.Y = 0;
|
||||
|
||||
return mappedPoint;
|
||||
}
|
||||
// TranslatePoint will only translate the given point from an upper left origin system to a bottom left origin system
|
||||
public SKPoint TranslatePoint(SKPoint sourcePoint)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using MarketData;
|
||||
using MarketData.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http.Headers;
|
||||
using MarketData.CNNProcessing;
|
||||
|
||||
|
||||
namespace MarketDataUnitTests;
|
||||
@@ -145,6 +146,26 @@ public class MarketDataUnitTestClass
|
||||
Assert.IsTrue(null != prices, "No Price from DailyPricesYahoo");
|
||||
}
|
||||
|
||||
// [TestMethod]
|
||||
// public void CNNPredictionTest()
|
||||
// {
|
||||
// String cnnHostName = "10.0.0.240";
|
||||
// CMCandidate cmCandidate = new CMCandidate();
|
||||
// CMParams cmParams = new CMParams();
|
||||
|
||||
// cmParams.UseCNN = true;
|
||||
// cmParams.UseCNNHost = "http://" + cnnHostName + ":5000";
|
||||
// cmParams.UseCNNDayCount = 270;
|
||||
// cmParams.UseCNNRewardPercentDecimal = 0.25;
|
||||
|
||||
// cmCandidate.Symbol = "MIDD";
|
||||
// cmCandidate.TradeDate = DateTime.Parse("07-01-2024");
|
||||
|
||||
// bool result = CMMomentumGenerator.PredictCandidate(cmCandidate, cmParams);
|
||||
|
||||
// Assert.IsTrue(result);
|
||||
// }
|
||||
|
||||
[TestMethod]
|
||||
public void CNNPredictionTest()
|
||||
{
|
||||
@@ -154,7 +175,7 @@ public class MarketDataUnitTestClass
|
||||
|
||||
cmParams.UseCNN = true;
|
||||
cmParams.UseCNNHost = "http://" + cnnHostName + ":5000";
|
||||
cmParams.UseCNNDayCount = 270;
|
||||
cmParams.UseCNNDayCount = 90;
|
||||
cmParams.UseCNNRewardPercentDecimal = 0.25;
|
||||
|
||||
cmCandidate.Symbol = "MIDD";
|
||||
@@ -163,7 +184,59 @@ public class MarketDataUnitTestClass
|
||||
bool result = CMMomentumGenerator.PredictCandidate(cmCandidate, cmParams);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CNNGenerateOutputFileVIX()
|
||||
{
|
||||
DataProcessor dataProcessor=new DataProcessor();
|
||||
int imageDimensions=224;
|
||||
dataProcessor.Width=imageDimensions;
|
||||
dataProcessor.Height=imageDimensions;
|
||||
dataProcessor.PenWidth=1;
|
||||
|
||||
String cnnHostName = "10.0.0.240";
|
||||
CMCandidate cmCandidate = new CMCandidate();
|
||||
CMParams cmParams = new CMParams();
|
||||
|
||||
cmParams.UseCNN = true;
|
||||
cmParams.UseCNNHost = "http://" + cnnHostName + ":5000";
|
||||
cmParams.UseCNNDayCount = 90;
|
||||
cmParams.UseCNNRewardPercentDecimal = 0.25;
|
||||
|
||||
cmCandidate.Symbol = "MIDD";
|
||||
cmCandidate.TradeDate = DateTime.Parse("07-01-2024");
|
||||
|
||||
TestCase testCase=new TestCase(cmCandidate.Symbol,cmCandidate.TradeDate,cmParams.UseCNNDayCount,TestCase.CaseType.Test,TestCase.GenerateType.BollingerBandWithVIX,TestCase.OutputType.OutputFile);
|
||||
dataProcessor.ProcessData(testCase);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CNNGenerateOutputFileBand()
|
||||
{
|
||||
DataProcessor dataProcessor=new DataProcessor();
|
||||
int imageDimensions=224;
|
||||
dataProcessor.Width=imageDimensions;
|
||||
dataProcessor.Height=imageDimensions;
|
||||
dataProcessor.PenWidth=1;
|
||||
|
||||
String cnnHostName = "10.0.0.240";
|
||||
CMCandidate cmCandidate = new CMCandidate();
|
||||
CMParams cmParams = new CMParams();
|
||||
|
||||
cmParams.UseCNN = true;
|
||||
cmParams.UseCNNHost = "http://" + cnnHostName + ":5000";
|
||||
cmParams.UseCNNDayCount = 90;
|
||||
cmParams.UseCNNRewardPercentDecimal = 0.25;
|
||||
|
||||
cmCandidate.Symbol = "MIDD";
|
||||
cmCandidate.TradeDate = DateTime.Parse("07-01-2024");
|
||||
|
||||
TestCase testCase=new TestCase(cmCandidate.Symbol,cmCandidate.TradeDate,cmParams.UseCNNDayCount,TestCase.CaseType.Test,TestCase.GenerateType.BollingerBand,TestCase.OutputType.OutputFile);
|
||||
dataProcessor.ProcessData(testCase);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void PremarketRetrieval()
|
||||
|
||||
Reference in New Issue
Block a user