From e7b77527476fe88cffcf28438a363fc21a64fd30 Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Tue, 10 May 2022 13:27:27 -0700 Subject: [PATCH] GBM_Feed --- .github/workflows/main_automation.yml | 4 +- Source/Basics/GBM_Feed.cs | 60 ++++++++++++++++++++++++++ docs/.nojekyll | 1 + docs/macd_example.ipynb | 61 ++++++++++++++++++++------- 4 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 Source/Basics/GBM_Feed.cs diff --git a/.github/workflows/main_automation.yml b/.github/workflows/main_automation.yml index 0b08acd9..99070ddc 100644 --- a/.github/workflows/main_automation.yml +++ b/.github/workflows/main_automation.yml @@ -92,11 +92,11 @@ jobs: run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/mihakralj/index.json -# --skip-duplicate + --skip-duplicate - name: Push package to nuget.org if: ${{ github.ref == 'refs/heads/main' }} run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' --api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }} --source https://api.nuget.org/v3/index.json -# --skip-duplicate \ No newline at end of file + --skip-duplicate \ No newline at end of file diff --git a/Source/Basics/GBM_Feed.cs b/Source/Basics/GBM_Feed.cs new file mode 100644 index 00000000..1fbf6040 --- /dev/null +++ b/Source/Basics/GBM_Feed.cs @@ -0,0 +1,60 @@ +namespace QuanTAlib; +using System; + +/* +GBM - Geometric Brownian Motion is a random simulator of market movement, returning List + GBM can be used for testing indicators, validation and Monte Carlo simulations of strategies. + + Sample usage: + GBM-Random data = new(); // generates 1 year (252) list of bars + GBM-Random data = new(Bars: 1000); // generates 1,000 bars + GBM-Random data = new(Bars: 252, Volatility: 0.05, Drift: 0.0005, Seed: 100.0) + + Parameters + Bars: number of bars (quotes) requested + Volatility: how dymamic/volatile the series should be; default is 1 + Drift: incremental drift due to annual interest rate; default is 5% + Seed: starting value of the random series; should not be 0 + + */ + +public class GBM_Feed : TBars +{ + double seed; + readonly double drift, volatility; + public GBM_Feed(int Bars = 252, double Volatility = 1.0, double Drift = 0.05, double Seed = 100.0) { + seed = Seed; + volatility = Volatility*0.01; + drift = Drift*0.01; + for (int i = 0; i OCMin)? 2*OCMin-Low : Low; + + double Volume = GBM_value(seed*10, volatility*2, Drift:0); + + base.Add((timestamp, Open, High, Low, Close, Volume), update); + seed = Close; + } + + private double GBM_value (double Seed, double Volatility, double Drift) { + Random rnd = new((int)(DateTime.UtcNow.Ticks)); + double U1 = 1.0-rnd.NextDouble(); + double U2 = 1.0-rnd.NextDouble(); + double Z = Math.Sqrt(-2.0 * Math.Log(U1)) * Math.Sin(2.0 * Math.PI * U2); + return Seed * Math.Exp( Drift - (Volatility*Volatility*0.5) + Volatility * Z); + } +} \ No newline at end of file diff --git a/docs/.nojekyll b/docs/.nojekyll index e69de29b..8b137891 100644 --- a/docs/.nojekyll +++ b/docs/.nojekyll @@ -0,0 +1 @@ + diff --git a/docs/macd_example.ipynb b/docs/macd_example.ipynb index c8667082..04a4d6ff 100644 --- a/docs/macd_example.ipynb +++ b/docs/macd_example.ipynb @@ -15,7 +15,7 @@ { "data": { "text/html": [ - "
Installed Packages
  • Plotly.NET, 2.0.0-preview.18
  • Plotly.NET.Interactive, 2.0.0-preview.18
  • QuantLib, 1.0.8
" + "
Installed Packages
  • Plotly.NET, 2.0.0
  • Plotly.NET.Interactive, 2.0.0
  • QuanTAlib, 0.1.13
" ] }, "metadata": {}, @@ -34,8 +34,8 @@ "source": [ "// This is .NET Interactive Notebook. It can run in VS.Code with .NET interactive extension installed\n", "\n", - "#r \"nuget: Plotly.NET, 2.0.0-preview.18\"\n", - "#r \"nuget: Plotly.NET.Interactive, 2.0.0-preview.18\"\n", + "#r \"nuget: Plotly.NET, 2.0.0\"\n", + "#r \"nuget: Plotly.NET.Interactive, 2.0.0\"\n", "#r \"nuget: QuanTAlib\"\n", "\n", "using Plotly.NET;\n", @@ -58,7 +58,7 @@ { "data": { "text/html": [ - "
265
" + "
380
" ] }, "metadata": {}, @@ -68,7 +68,7 @@ "source": [ "// defining the MACD model through clasess that connect to each other with Events\n", "\n", - "YAHOO_Feed tsla = new(380, \"TSLA\");\n", + "RND_Feed tsla = new(380);\n", "TSeries close = tsla.Close; // close will get data from YAHOO tsla feed\n", "EMA_Series slow = new(close,26); // slow gets data from slow through pub-sub eventing\n", "EMA_Series fast = new(close,12); // fast gets data from slow (via eventing)\n", @@ -94,31 +94,62 @@ { "data": { "text/html": [ - "
\n", - "\n" + " renderPlotly_6cd8b1753a7c4c719b8d7aa4e0a44b7a();\r\n", + " }\r\n", + "\r\n", + "\r\n", + " \r\n", + "