Skip to content

Commit

Permalink
add finance demos to cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
swharden committed Jul 27, 2019
1 parent 05f14a6 commit 6ee5c3b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,7 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs
doc/cookbook/images/30_Signal.png
doc/cookbook/images/31_Signal_With_Antialiasing_Off.png
doc/cookbook/images/31_Signal_With_Antialiasing_Off.png
doc/cookbook/images/30_Signal.png
4 changes: 4 additions & 0 deletions demos/ScottPlotCookbook/CookBookManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void GenerateAllFigures(int width, int height, string outputFolderName =
hashes.Add(recipies.Figure_64_Manual_Grid_Spacing());
hashes.Add(recipies.Figure_65_Histogram());
hashes.Add(recipies.Figure_66_CPH());
hashes.Add(recipies.Figure_67_Candlestick());
hashes.Add(recipies.Figure_68_OHLC());

ValidateImageHashes(hashes.ToArray());

Expand Down Expand Up @@ -193,6 +195,8 @@ public void ValidateImageHashes(string[] hashLines)
knownHahes += "DCC984120C142F91AF13438641BC15FE 64_Manual_Grid_Spacing()\n";
knownHahes += "7789995EFF9D69CB6132AEEDC8083687 65_Histogram()\n";
knownHahes += "F3A1F0FC4E0027E0DDE4B6950DF3B534 66_CPH()\n";
knownHahes += "79698A6E3CC91FDD36810332C05C58D9 67_Candlestick()\n";
knownHahes += "8DA76CAA67E3AB76C70E63F48B7ABCE6 68_OHLC()\n";

string hashCodeNeeded = "";

Expand Down
38 changes: 38 additions & 0 deletions demos/ScottPlotCookbook/Recipes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,5 +822,43 @@ public string Figure_66_CPH()
Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
return name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap());
}

public string Figure_67_Candlestick()
{
string name = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", "");
string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png");

Random rand = new Random(0);
int pointCount = 60;
ScottPlot.OHLC[] ohlcs = ScottPlot.DataGen.RandomStockPrices(rand, pointCount);

var plt = new ScottPlot.Plot(width, height);
plt.Title("Candlestick Chart");
plt.YLabel("Stock Price (USD)");
plt.XLabel("Day (into Q4)");
plt.PlotCandlestick(ohlcs);
plt.SaveFig(fileName);
Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
return name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap());
}

public string Figure_68_OHLC()
{
string name = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", "");
string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png");

Random rand = new Random(0);
int pointCount = 60;
ScottPlot.OHLC[] ohlcs = ScottPlot.DataGen.RandomStockPrices(rand, pointCount);

var plt = new ScottPlot.Plot(width, height);
plt.Title("Open/High/Low/Close (OHLC) Chart");
plt.YLabel("Stock Price (USD)");
plt.XLabel("Day (into Q4)");
plt.PlotOHLC(ohlcs);
plt.SaveFig(fileName);
Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
return name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap());
}
}
}

0 comments on commit 6ee5c3b

Please sign in to comment.