Push MarketData Changes.
This commit is contained in:
@@ -3,27 +3,75 @@ using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using MarketData.Utils;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
|
||||
namespace MarketData.CNNProcessing
|
||||
{
|
||||
public class CNNProcessor
|
||||
{
|
||||
private static int dayCount=270;
|
||||
private static int width=128;
|
||||
private static int height=128;
|
||||
private static int dayCount=270; // This is the default days
|
||||
private static int width=128; // This is the default width
|
||||
private static int height=128; // THis is the defaukt height
|
||||
|
||||
private CNNProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
public static void GenerateTraining()
|
||||
/// <summary>
|
||||
/// GenerateTraining - This is the new one. Please refer to the CNNImageProcessor project for information on how to call this method.
|
||||
/// </summary>
|
||||
/// <param name="avoid">This is the collection of avoid holdings</param>
|
||||
/// <param name="good">This is the collection of good holdings</param>
|
||||
/// <param name="dimension">The image dimensions. for example 224 for 224x224 or 128 for 128x128</param>
|
||||
/// <param name="histDays">This is the number of histDays. For example I used 90 for convnext</param>
|
||||
/// <param name="generateType">The type. For example I used BollingerBandWithVIX which is a bollinger band with ^VIX overay for convnext</param>
|
||||
/// <param name="rootFolder"></param>
|
||||
public static void GenerateTraining(List<Holding> avoid, List<Holding> good, int dimension, int histDays,TestCase.GenerateType generateType=TestCase.GenerateType.BollingerBandWithVIX,String rootFolder=@"C:\boneyard\DeepLearning\ModelInputData\")
|
||||
{
|
||||
TestCases testCases=new TestCases();
|
||||
DataProcessor dataProcessor=new DataProcessor();
|
||||
dataProcessor.Width=dimension;
|
||||
dataProcessor.Height=dimension;
|
||||
dataProcessor.PenWidthArray=new float[]{.75f,1.00f,1.12f};
|
||||
|
||||
if(!rootFolder.EndsWith(@"\"))rootFolder+=@"\";
|
||||
// [0] Data - The avoid data
|
||||
foreach(Holding holding in avoid)
|
||||
{
|
||||
testCases.Add(new TestCase(holding.Symbol,holding.PurchaseDate,histDays,TestCase.CaseType.Training,generateType));
|
||||
}
|
||||
dataProcessor.SetOutputFolderPath(rootFolder+"0");
|
||||
dataProcessor.ClearFolderPath();
|
||||
dataProcessor.ProcessData(testCases);
|
||||
testCases.Clear();
|
||||
|
||||
// [1] Data - The good data
|
||||
foreach(Holding holding in good)
|
||||
{
|
||||
testCases.Add(new TestCase(holding.Symbol,holding.PurchaseDate,histDays,TestCase.CaseType.Training,generateType));
|
||||
}
|
||||
dataProcessor.SetOutputFolderPath(rootFolder+"1");
|
||||
dataProcessor.ClearFolderPath();
|
||||
dataProcessor.ProcessData(testCases);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GenerateTraining - This is the old methof training the resnet model. Please see above
|
||||
/// </summary>
|
||||
/// <param name="rootFolder"></param>
|
||||
public static void GenerateTraining(String rootFolder=@"C:\boneyard\DeepLearning\ModelInputData\")
|
||||
{
|
||||
TestCases testCases=new TestCases();
|
||||
DataProcessor dataProcessor=new DataProcessor();
|
||||
dataProcessor.Width=width;
|
||||
dataProcessor.Height=height;
|
||||
dataProcessor.PenWidthArray=new float[]{.50f,.75f,1.00f,1.12f,1.25f,1.31f,1.37f,1.50f,1.56f,1.62f,1.75f,1.87f,2.00f};
|
||||
// dataProcessor.PenWidthArray=new float[]{.50f,.75f,1.00f,1.12f,1.25f,1.31f,1.37f,1.50f,1.56f,1.62f,1.75f,1.87f,2.00f};
|
||||
|
||||
// Testing with 20,000 images in each set so reducing this use of pens to just one. It was producing 260,000 images for each classification,
|
||||
// takings many hours to build the datasets
|
||||
dataProcessor.PenWidthArray=new float[]{.75f,1.00f,1.12f};
|
||||
|
||||
if(!rootFolder.EndsWith(@"\"))rootFolder+=@"\";
|
||||
// [0] Data - The avoid data
|
||||
testCases.Add(new TestCase("CENX",DateTime.Parse("03/31/2022"),270,TestCase.CaseType.Training,TestCase.GenerateType.BollingerBand));
|
||||
testCases.Add(new TestCase("ICPT",DateTime.Parse("12/31/2019"),270,TestCase.CaseType.Training,TestCase.GenerateType.BollingerBand));
|
||||
@@ -56,8 +104,8 @@ namespace MarketData.CNNProcessing
|
||||
testCases.Add(new TestCase("INBX",DateTime.Parse("01/31/2024"),270,TestCase.CaseType.Training,TestCase.GenerateType.BollingerBand));
|
||||
testCases.Add(new TestCase("WYNN",DateTime.Parse("02/28/2023"),270,TestCase.CaseType.Training,TestCase.GenerateType.BollingerBand));
|
||||
|
||||
|
||||
dataProcessor.SetOutputFolderPath(@"C:\boneyard\DeepLearning\ModelInputData\0");
|
||||
// ****
|
||||
dataProcessor.SetOutputFolderPath(rootFolder+"0");
|
||||
dataProcessor.ProcessData(testCases);
|
||||
testCases.Clear();
|
||||
|
||||
@@ -102,7 +150,8 @@ namespace MarketData.CNNProcessing
|
||||
testCases.Add(new TestCase("DOCU",DateTime.Parse("05/30/2020"),270,TestCase.CaseType.Training,TestCase.GenerateType.BollingerBand));
|
||||
testCases.Add(new TestCase("SIG",DateTime.Parse("10/30/2020"),270,TestCase.CaseType.Training,TestCase.GenerateType.BollingerBand));
|
||||
|
||||
dataProcessor.SetOutputFolderPath(@"C:\boneyard\DeepLearning\ModelInputData\1");
|
||||
// ***
|
||||
dataProcessor.SetOutputFolderPath(rootFolder+"1");
|
||||
dataProcessor.ProcessData(testCases);
|
||||
}
|
||||
|
||||
@@ -204,4 +253,76 @@ namespace MarketData.CNNProcessing
|
||||
Console.WriteLine("");
|
||||
}
|
||||
}
|
||||
|
||||
public class Holding
|
||||
{
|
||||
public String Symbol {get;set;}
|
||||
public DateTime PurchaseDate {get; set; }
|
||||
public double PurchasePrice {get;set;}
|
||||
public DateTime SellDate {get; set; }
|
||||
public double SellPrice {get;set;}
|
||||
public double GainLoss{ get; set;}
|
||||
public double GainLossPercent {get;set;}
|
||||
private static readonly string[] DateFormats = { "MM/dd/yyyy", "M/dd/yyyy", "M/d/yyyy" };
|
||||
private static readonly CultureInfo UsCulture = CultureInfo.GetCultureInfo("en-US");
|
||||
|
||||
public static String Heading
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Symbol,Shares,Purchase Date,Purchase Price,Sell Date,Sell Price,Exposure,Beta,BetaMonths,SharpeRatio,RiskAdjustedWeight,RiskAdjustedAllocation,TargetBetaOverBeta,Score,CNN Prediction,Market Value,Gain Loss,Gain Loss (%)";
|
||||
}
|
||||
}
|
||||
|
||||
public String ToTestCase()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("testCases.Add(new TestCase(").Append("\"").Append(Symbol).Append("\"").Append(",");
|
||||
sb.Append("DateTime.Parse(").Append("\"").Append(Utility.DateTimeToStringMMSDDSYYYY(PurchaseDate)).Append("\")").Append(",");
|
||||
sb.Append("270,TestCase.CaseType.Training,TestCase.GenerateType.BollingerBand));");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(Symbol).Append(",");
|
||||
sb.Append(","); // shares
|
||||
sb.Append(PurchaseDate.ToShortDateString()).Append(",");
|
||||
sb.Append(Utility.FormatNumber(PurchasePrice,3)).Append(",");
|
||||
sb.Append(SellDate.ToShortDateString()).Append(",");
|
||||
sb.Append(Utility.FormatNumber(SellPrice,3)).Append(",");
|
||||
sb.Append(","); //exposure
|
||||
sb.Append(","); //beta
|
||||
sb.Append(","); //bta months
|
||||
sb.Append(","); //sharpe ratio
|
||||
sb.Append(","); //risk adjusted weight
|
||||
sb.Append(","); //RiskAdjustedAllocation
|
||||
sb.Append(","); //TargetBetaOverBeta
|
||||
sb.Append(","); //Score
|
||||
sb.Append(","); //CNNPrediction
|
||||
sb.Append(","); //Market Value
|
||||
sb.Append(Utility.FormatNumber(GainLoss,3)).Append(",");
|
||||
sb.Append(Utility.FormatNumber(GainLossPercent,3));
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
public static Holding FromString(string strLine)
|
||||
{
|
||||
string[] items = strLine.Split(',');
|
||||
|
||||
Holding holding = new Holding();
|
||||
holding.Symbol = items[0];
|
||||
if(string.IsNullOrEmpty(holding.Symbol))return null;
|
||||
holding.PurchaseDate = DateTime.ParseExact(items[2], DateFormats, UsCulture, DateTimeStyles.AssumeLocal);
|
||||
holding.PurchasePrice = double.Parse(items[3], UsCulture);
|
||||
holding.SellDate = DateTime.ParseExact(items[4], DateFormats, UsCulture, DateTimeStyles.AssumeLocal);
|
||||
holding.SellPrice = double.Parse(items[5], UsCulture);
|
||||
holding.GainLoss = double.Parse(items[16], UsCulture);
|
||||
holding.GainLossPercent = double.Parse(items[17].TrimEnd('%'), UsCulture) / 100.0;
|
||||
|
||||
return holding;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user