From 28025fbdd34b04ce62b90f16979c4b353c6520ef Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Sun, 6 Nov 2022 17:20:57 -0800 Subject: [PATCH] sdev, psdev, alphavantage --- Docs/mA-comparison.ipynb | 1135 ----------------- Docs/macd_example.ipynb | 159 --- Quantower/Indicators/JMA_chart.cs | 52 + .../{SSDEV_chart.cs => PSDEV_chart.cs} | 16 +- Quantower/Indicators/PSDEV_chart.cs~HEAD | 53 + ...art.cs~parent of 32615af... for dev branch | 53 + Quantower/Indicators/SDEV_chart.cs | 4 +- Quantower/Indicators/ZLMA_chart.cs | 11 +- Source/Feeds/Alphavantage_Feed.cs | 4 +- Source/Feeds/RND_Feed.cs | 54 +- Source/Indicators/JMA_Series.cs | 7 +- Source/QuanTAlib.csproj | 4 +- Source/Statistics/PSDEV_Series.cs | 44 + Source/Statistics/SDEV_Series.cs | 32 +- Source/Statistics/SSDEV_Series.cs | 44 - Tests/MovingAvg/JMA_Test.cs | 33 + Tests/Statistics/PSDEV_Test.cs | 4 +- Tests/Statistics/SDEV_Test .cs | 4 +- Tests/Validations/TA_LIB.cs | 10 - {Docs => docs}/.nojekyll | 0 docs/Comparing_w_TALIB.ipynb | 296 ++--- docs/LICENSE | 402 +++--- docs/QuantLib_test.ipynb | 610 ++++----- docs/coverage.md | 310 ++--- docs/getting_started.ipynb | 580 ++++----- docs/index.html | 50 +- docs/ma-comparison.dib | 244 ++++ docs/macd_example.ipynb | 190 +++ 28 files changed, 1860 insertions(+), 2545 deletions(-) delete mode 100644 Docs/mA-comparison.ipynb delete mode 100644 Docs/macd_example.ipynb create mode 100644 Quantower/Indicators/JMA_chart.cs rename Quantower/Indicators/{SSDEV_chart.cs => PSDEV_chart.cs} (78%) create mode 100644 Quantower/Indicators/PSDEV_chart.cs~HEAD create mode 100644 Quantower/Indicators/PSDEV_chart.cs~parent of 32615af... for dev branch create mode 100644 Source/Statistics/PSDEV_Series.cs delete mode 100644 Source/Statistics/SSDEV_Series.cs create mode 100644 Tests/MovingAvg/JMA_Test.cs rename {Docs => docs}/.nojekyll (100%) create mode 100644 docs/ma-comparison.dib create mode 100644 docs/macd_example.ipynb diff --git a/Docs/mA-comparison.ipynb b/Docs/mA-comparison.ipynb deleted file mode 100644 index fc3f5f30..00000000 --- a/Docs/mA-comparison.ipynb +++ /dev/null @@ -1,1135 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
Installed Packages
  • Plotly.NET, 3.0.1
  • Plotly.NET.Interactive, 3.0.2
  • QuanTAlib, 0.1.15
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/markdown": [ - "Loading extensions from `Plotly.NET.Interactive.dll`" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "#r \"nuget: Plotly.NET\"\n", - "#r \"nuget: Plotly.NET.Interactive\"\n", - "#r \"nuget: QuanTAlib\"\n", - "\n", - "using Plotly.NET;\n", - "using Plotly.NET.LayoutObjects;\n", - "using QuanTAlib;" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [], - "source": [ - "List x = new() {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96};\n", - "List Spike = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\n", - "List Impulse = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};\n", - "List Triangle = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2};\n", - "List Sawtooth = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};\n", - "List Sine = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0.39,0.56,0.72,0.84,0.93,0.99,1,0.97,0.91,0.81,0.68,0.52,0.33,0.14,-0.06,-0.26,-0.44,-0.61,-0.76,-0.87,-0.95,-0.99,-1,-0.96,-0.88,-0.77,-0.63,-0.46,-0.28,-0.08,0.12,0.31,0.49,0.66,0.79,0.9,0.97,1,0.99,0.94,0.85,0.73,0.58,0.41,0.22,0.02,-0.17,-0.37,-0.54,-0.7,-0.83,-0.92,-0.98,-1,-0.98,-0.92,-0.82,-0.69,-0.54,-0.36,-0.17,0.03,0.23,0.42,0.59,0.74};\n", - "List Chirp = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0.93,0.27,-0.59,-1,-0.71,0.05,0.75,1,0.67,0,-0.67,-0.99,-0.85,-0.34,0.31,0.81,1,0.82,0.35,-0.22,-0.71,-0.98,-0.95,-0.66,-0.2,0.31,0.72,0.96,0.98,0.78,0.43,-0.01,-0.43,-0.77,-0.96,-0.99,-0.85,-0.58,-0.23,0.16,0.51,0.79,0.95,1,0.92,0.73,0.47,0.15,-0.17,-0.47,-0.72,-0.9,-0.99,-0.99,-0.9,-0.74,-0.52,-0.26,0.01,0.28,0.53,0.73,0.88,0.97,1,0.97};\n", - "List White = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,0.03,-0.4,-0.47,0.19,-0.4,-0.23,0.31,0.41,0.19,0.16,-0.5,-0.31,-0.21,0.25,0.18,-0.48,-0.1,0.38,0.29,-0.38,-0.08,-0.21,0.34,0.01,-0.46,0.28,-0.48,0.11,0.02,-0.37,0.19,-0.2,0.1,0.24,0.08,-0.22,-0.12,0.15,0.36,-0.43,-0.03,-0.32,0.45,-0.5,-0.04,-0.04,-0.08,-0.18,0.13,-0.33,-0.19,0.36,-0.39,0.2,-0.31,0.28,-0.13,-0.07,-0.29,0.37,0.03,-0.25,-0.06,-0.3,-0.08,-0.09};\n", - "List Gauss = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,0,0.03,0.11,-0.1,-0.43,-0.08,0.36,-0.04,-0.04,-0.21,-0.3,0.26,0.2,0.28,0.2,0.27,-0.01,-0.1,-0.23,-0.13,-0.41,-0.23,-0.07,-0.21,0.32,-0.18,-0.48,0.3,0.46,-0.2,0.52,-0.81,-0.25,-0.21,-0.12,-0.18,0.18,0.52,0.29,0.44,0.18,-1.2,0.38,0.24,0.06,0.28,0.34,0.3,-0.13,0.19,-0.5,0.59,-0.36,0.22,-0.23,0.24,0.39,0.13,-0.33,-0.57,-0.23,0.49,-0.13,0.76,0.59,0.61};\n", - "List B = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0,-0.28,0.41,-0.54,0.65,-0.75,0.84,-0.91,0.96,-0.99,1,-0.99,0.96,-0.92,0.85,-0.77,0.67,-0.56,0.44,-0.3,0.17,-0.03,-0.11,0.25,-0.39,0.51,-0.63,0.73,-0.82,0.89,-0.95,0.98,-1,0.99,-0.97,0.93,-0.86,0.78,-0.69,0.58,-0.46,0.33,-0.19,0.05,0.09,-0.23,0.36,-0.49,0.61,-0.71,0.81,-0.88,0.94,-0.98,1,-1,0.98,-0.94,0.88,-0.8,0.71,-0.6,0.48,-0.35,0.22,-0.08,-0.06};\n", - "List HF = new() {-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,0,0.14,-0.76,-0.96,-0.28,0.66,0.99,0.41,-0.54,-1,-0.54,0.42,0.99,0.65,-0.29,-0.96,-0.75,0.15,0.91,0.84,-0.01,-0.85,-0.91,-0.13,0.76,0.96,0.27,-0.66,-0.99,-0.4,0.55,1,0.53,-0.43,-0.99,-0.64,0.3,0.96,0.75,-0.16,-0.92,-0.83,0.02,0.85,0.9,0.12,-0.77,-0.95,-0.26,0.67,0.99,0.4,-0.56,-1,-0.52,0.44,0.99,0.64,-0.3,-0.97,-0.74,0.17,0.92,0.83,-0.03,-0.86};\n", - "List ImpulseHF = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,0.05,-0.25,-0.32,-0.09,0.22,0.33,0.14,-0.18,-0.33,-0.18,0.14,0.33,0.22,-0.1,-0.32,-0.25,0.05,0.3,0.28,0,-0.28,-0.3,-0.04,0.25,0.32,0.09,-0.22,-0.33,-0.13,0.18,0.33,0.18,0.86,0.67,0.79,1.1,1.32,1.25,0.95,0.69,0.72,1.01,1.28,1.3,1.04,0.74,0.68,0.91,1.22,1.33,1.13,0.81,0.67,0.83,1.15,1.33,1.21,0.9,0.68,0.75,1.06,1.31,1.28,0.99,0.71};\n", - "List SawtoothHF = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,2.7,-0.8,-0.8,3.6,9.3,11.95,10.05,6.3,5,8.3,14.1,17.95,17.25,13.55,11.2,13.25,18.75,23.55,24.2,20.95,17.75,18.45,23.35,28.8,30.8,28.35,24.7,24.05,28,33.75,37,35.65,31.85,28.05,-3.2,1.5,4.8,3.75,-0.8,-4.6,-4.15,0.1,4.25,4.5,0.6,-3.85,-4.75,-1.3,3.35,4.95,2,-2.8,-5,-2.6,2.2,4.95,3.2,-1.5,-4.85,-3.7,0.85,4.6,4.15,-0.15,-4.3};\n", - "List SineG = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,0.59,0.83,0.74,0.5,0.91,1.36,0.93,0.87,0.6,0.38,0.78,0.53,0.42,0.14,0.01,-0.45,-0.71,-0.99,-1,-1.36,-1.22,-1.07,-1.17,-0.56,-0.95,-1.11,-0.16,0.18,-0.28,0.64,-0.5,0.24,0.45,0.67,0.72,1.15,1.52,1.28,1.38,1.03,-0.47,0.96,0.65,0.28,0.3,0.17,-0.07,-0.67,-0.51,-1.33,-0.33,-1.34,-0.78,-1.21,-0.68,-0.43,-0.56,-0.87,-0.93,-0.4,0.52,0.1,1.18,1.18,1.35};\n", - "List ChirpG = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1.3,0.3,-0.48,-1.1,-1.14,-0.03,1.11,0.96,0.63,-0.21,-0.97,-0.73,-0.65,-0.06,0.51,1.08,0.99,0.72,0.12,-0.35,-1.12,-1.21,-1.02,-0.87,0.12,0.13,0.24,1.26,1.44,0.58,0.95,-0.82,-0.68,-0.98,-1.08,-1.17,-0.67,-0.06,0.06,0.6,0.69,-0.41,1.33,1.24,0.98,1.01,0.81,0.45,-0.3,-0.28,-1.22,-0.31,-1.35,-0.77,-1.13,-0.5,-0.13,-0.13,-0.32,-0.29,0.3,1.22,0.75,1.73,1.59,1.58};\n", - "List Complex = new() {175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.44,176.27,176.04,176.99,175.49,175.68,174.34,176.4,174.05,174.4,174.2,176.16,175,177.72,174.33,176.96,174.62,174.76,170.9,171.12,171.05,170.01,169.24,172.64,171.96,175.72,174.16,175.81,177.3,178.38,176.75,177.19,175.55,178.49,176.52,178.45,178.04,178.25,177.8,176.97,172.94,174.92,173.98,172.29,171.19,172.54,172.11,175.32,175.63,176.65,173.8,176.04,172.74,175.24,171.84,171.54,172.17,171.85,172.38,170.78,173.49,173.69,171.71,174.38,173.99,174.83};\n", - "List Market = new() {68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,67.75,67.75,72.75,74.75,72.25,71.25,71.75,72.75,77.75,76,76,76,74.75,75.5,74.75,73.75,74,74.75,72.25,72.5,72.25,74.5,74.75,75.75,75.75,75.75,74.25,73.75,74.75,72,71.75,72.5,72.25,71,72,71.75,71.75,73.25,72.5,73.75,74,76.75,75.75,75,75.75,74.5,74.25,73.5,71.75,70.5,69,70.5,70,68.75,67.25,68.5,70.75,70,70.5,68.25,68.25,68.25,63.75,64.25};\n" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [], - "source": [ - "TSeries data = new();\n", - "\n", - "// change these two values - the period and the type of observed indicator\n", - "// currently available indicators are: DEMA_Series, EMA_Series, HEMA_Series, HMA_Series, JMA_Series, RMA_Series, SMA_Series, TEMA_Series, WMA_Series and ZLEMA_Series\n", - "int Period = 20;\n", - "ZLEMA_Series indicator=new(source: data, period: Period);\n", - "\n", - "//On charts below, blue line is the data input, the green line is a JMA reference" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Spike;\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Spike\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Impulse;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Impulse\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Triangle;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x, series, false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Triangle\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Sawtooth;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Sawtooth\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Sine;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Sine\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Chirp;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Chirp\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = White;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"White\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Gauss;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Gauss\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = B;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"B\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = HF;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"HF\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = ImpulseHF;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"ImpulseHF\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = SawtoothHF;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"SawtoothHF\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = SineG;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"SineG\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = ChirpG;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"ChirpG\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Complex;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Complex\");\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "
\r\n", - "\r\n", - "\n", - " \n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var series = Market;\n", - "data = new();\n", - "indicator=new(source: data, period: Period);\n", - "HMA_Series reference = new(source: data, period: Period);\n", - "for (int i=0; i(x,series,false,\"data\").WithLineStyle(Width: 1.0, Color: Color.fromString(\"blue\"));\n", - "GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,\"sig\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,\"ref\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"Maket\");\n", - "chart" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".NET (C#)", - "language": "C#", - "name": ".net-csharp" - }, - "language_info": { - "name": "C#" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Docs/macd_example.ipynb b/Docs/macd_example.ipynb deleted file mode 100644 index 2203d403..00000000 --- a/Docs/macd_example.ipynb +++ /dev/null @@ -1,159 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
Installed Packages
  • Plotly.NET, 2.0.0-preview.18
  • Plotly.NET.Interactive, 2.0.0-preview.18
  • QuantLib, 1.0.8
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/markdown": [ - "Loading extensions from `Plotly.NET.Interactive.dll`" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "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: QuanTAlib\"\n", - "\n", - "using Plotly.NET;\n", - "using Plotly.NET.LayoutObjects;\n", - "using QuanTAlib;" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
265
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "// defining the MACD model through clasess that connect to each other with Events\n", - "\n", - "YAHOO_Feed tsla = new(380, \"TSLA\");\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", - "SUB_Series macd = new(fast,slow); // macd is a SUBtraction of fast-slow\n", - "EMA_Series signal = new(macd,9); // signal is EMA of macd\n", - "SUB_Series histogram = new(macd, signal); // histogran is SUBtraction macd-signal\n", - "\n", - "slow.Count" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "//this is just a visualization of MACD using the (preview of) Plotly.NET\n", - "\n", - "var candles = Chart2D.Chart.Candlestick(tsla.Open.v, tsla.High.v, tsla.Low.v, tsla.Close.v, tsla.Open.t, \"candles\");\n", - "var ch1 = Chart2D.Chart.Line(macd.t,macd.v,false,\"macd\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", - "var ch2 = Chart2D.Chart.Line(signal.t,signal.v,false,\"signal\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "//GenericChart.GenericChart hist = Chart2D.Chart.Column(histogram.t,histogram.v).WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", - "\n", - "var chart = Chart.Combine(new []{candles,ch1,ch2}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"MACD using EMA\");\n", - "\n", - "chart" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".NET (C#)", - "language": "C#", - "name": ".net-csharp" - }, - "language_info": { - "file_extension": ".cs", - "mimetype": "text/x-csharp", - "name": "C#", - "pygments_lexer": "csharp", - "version": "9.0" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Quantower/Indicators/JMA_chart.cs b/Quantower/Indicators/JMA_chart.cs new file mode 100644 index 00000000..70c3b445 --- /dev/null +++ b/Quantower/Indicators/JMA_chart.cs @@ -0,0 +1,52 @@ +using System.Drawing; +using TradingPlatform.BusinessLayer; +namespace QuanTAlib; + +public class JMA_chart : Indicator +{ + #region Parameters + + [InputParameter("Smoothing period", 0, 1, 999, 1, 1)] + private int Period = 10; + + [InputParameter("Data source", 1, variants: new object[] + { "Open", 0, "High", 1, "Low", 2, "Close", 3, "HL2", 4, "OC2", 5, + "OHL3", 6, "HLC3", 7, "OHLC4", 8, "Weighted (HLCC4)", 9 })] + private int DataSource = 3; + + #endregion Parameters + + private TBars bars ; + + /////// + private JMA_Series indicator; + /////// + + public JMA_chart() + { + this.SeparateWindow = false; + this.Name = "JMA - Jurik Moving Average"; + this.Description = "Jurik Moving Average description"; + this.AddLineSeries("JMA", Color.RoyalBlue, 3, LineStyle.Solid); + } + + protected override void OnInit() + { + this.ShortName = + "JMA (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.bars = new(); + this.indicator = new(source: bars.Select(this.DataSource), + period: this.Period, useNaN: false); + } + protected override void OnUpdate(UpdateArgs args) + { + bool update = !(args.Reason == UpdateReason.NewBar || + args.Reason == UpdateReason.HistoricalBar); + this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), + this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), + this.GetPrice(PriceType.Close), + this.GetPrice(PriceType.Volume), update); + double result = this.indicator[this.indicator.Count - 1].v; + this.SetValue(result); + } +} diff --git a/Quantower/Indicators/SSDEV_chart.cs b/Quantower/Indicators/PSDEV_chart.cs similarity index 78% rename from Quantower/Indicators/SSDEV_chart.cs rename to Quantower/Indicators/PSDEV_chart.cs index b742ddc2..91b45426 100644 --- a/Quantower/Indicators/SSDEV_chart.cs +++ b/Quantower/Indicators/PSDEV_chart.cs @@ -2,7 +2,7 @@ using System.Drawing; using TradingPlatform.BusinessLayer; namespace QuanTAlib; -public class SSDEV_chart : Indicator +public class PSDEV_chart : Indicator { #region Parameters @@ -19,22 +19,22 @@ public class SSDEV_chart : Indicator private TBars bars; ///////dotnet - private SSDEV_Series indicator; + private PSDEV_Series indicator; /////// - public SSDEV_chart() + public PSDEV_chart() { this.SeparateWindow = true; - this.Name = "SSDEV - Sample Standard Deviation (Unbiased)"; - this.Description = "SSDEV description"; - this.AddLineSeries("SSDEV", Color.RoyalBlue, 3, LineStyle.Solid); + this.Name = "PSDEV - Population Standard Deviation (Biased)"; + this.Description = "PSDEV description"; + this.AddLineSeries("PSDEV", Color.RoyalBlue, 3, LineStyle.Solid); } protected override void OnInit() { - this.bars = new(); + this.bars = new(); this.ShortName = - "SSDEV (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + "PSDEV (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true); } diff --git a/Quantower/Indicators/PSDEV_chart.cs~HEAD b/Quantower/Indicators/PSDEV_chart.cs~HEAD new file mode 100644 index 00000000..91b45426 --- /dev/null +++ b/Quantower/Indicators/PSDEV_chart.cs~HEAD @@ -0,0 +1,53 @@ +using System.Drawing; +using TradingPlatform.BusinessLayer; +namespace QuanTAlib; + +public class PSDEV_chart : Indicator +{ + #region Parameters + + [InputParameter("Smoothing period", 0, 1, 999, 1, 1)] + private int Period = 10; + + [InputParameter("Data source", 1, variants: new object[] + { "Open", 0, "High", 1, "Low", 2, "Close", 3, "HL2", 4, "OC2", 5, + "OHL3", 6, "HLC3", 7, "OHLC4", 8, "Weighted (HLCC4)", 9 })] + private int DataSource = 8; + + #endregion Parameters + + private TBars bars; + + ///////dotnet + private PSDEV_Series indicator; + /////// + + public PSDEV_chart() + { + this.SeparateWindow = true; + this.Name = "PSDEV - Population Standard Deviation (Biased)"; + this.Description = "PSDEV description"; + this.AddLineSeries("PSDEV", Color.RoyalBlue, 3, LineStyle.Solid); + } + + protected override void OnInit() + { + this.bars = new(); + this.ShortName = + "PSDEV (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.indicator = new(source: bars.Select(this.DataSource), + period: this.Period, useNaN: true); + } + protected override void OnUpdate(UpdateArgs args) + { + bool update = !(args.Reason == UpdateReason.NewBar || + args.Reason == UpdateReason.HistoricalBar); + this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), + this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), + this.GetPrice(PriceType.Close), + this.GetPrice(PriceType.Volume), update); + double result = this.indicator[this.indicator.Count - 1].v; + + this.SetValue(result, 0); + } +} diff --git a/Quantower/Indicators/PSDEV_chart.cs~parent of 32615af... for dev branch b/Quantower/Indicators/PSDEV_chart.cs~parent of 32615af... for dev branch new file mode 100644 index 00000000..91b45426 --- /dev/null +++ b/Quantower/Indicators/PSDEV_chart.cs~parent of 32615af... for dev branch @@ -0,0 +1,53 @@ +using System.Drawing; +using TradingPlatform.BusinessLayer; +namespace QuanTAlib; + +public class PSDEV_chart : Indicator +{ + #region Parameters + + [InputParameter("Smoothing period", 0, 1, 999, 1, 1)] + private int Period = 10; + + [InputParameter("Data source", 1, variants: new object[] + { "Open", 0, "High", 1, "Low", 2, "Close", 3, "HL2", 4, "OC2", 5, + "OHL3", 6, "HLC3", 7, "OHLC4", 8, "Weighted (HLCC4)", 9 })] + private int DataSource = 8; + + #endregion Parameters + + private TBars bars; + + ///////dotnet + private PSDEV_Series indicator; + /////// + + public PSDEV_chart() + { + this.SeparateWindow = true; + this.Name = "PSDEV - Population Standard Deviation (Biased)"; + this.Description = "PSDEV description"; + this.AddLineSeries("PSDEV", Color.RoyalBlue, 3, LineStyle.Solid); + } + + protected override void OnInit() + { + this.bars = new(); + this.ShortName = + "PSDEV (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; + this.indicator = new(source: bars.Select(this.DataSource), + period: this.Period, useNaN: true); + } + protected override void OnUpdate(UpdateArgs args) + { + bool update = !(args.Reason == UpdateReason.NewBar || + args.Reason == UpdateReason.HistoricalBar); + this.bars.Add(this.Time(), this.GetPrice(PriceType.Open), + this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low), + this.GetPrice(PriceType.Close), + this.GetPrice(PriceType.Volume), update); + double result = this.indicator[this.indicator.Count - 1].v; + + this.SetValue(result, 0); + } +} diff --git a/Quantower/Indicators/SDEV_chart.cs b/Quantower/Indicators/SDEV_chart.cs index 17c87873..d920c6fa 100644 --- a/Quantower/Indicators/SDEV_chart.cs +++ b/Quantower/Indicators/SDEV_chart.cs @@ -25,14 +25,14 @@ public class SDEV_chart : Indicator public SDEV_chart() { this.SeparateWindow = true; - this.Name = "SDEV - Population Standard Deviation (Biased)"; + this.Name = "SDEV - Sample Standard Deviation (Unbiased)"; this.Description = "SDEV description"; this.AddLineSeries("SDEV", Color.RoyalBlue, 3, LineStyle.Solid); } protected override void OnInit() { - this.bars = new(); + this.bars = new(); this.ShortName = "SDEV (" + TBars.SelectStr(this.DataSource) + ", " + this.Period + ")"; this.indicator = new(source: bars.Select(this.DataSource), diff --git a/Quantower/Indicators/ZLMA_chart.cs b/Quantower/Indicators/ZLMA_chart.cs index eb054d72..35cddbdf 100644 --- a/Quantower/Indicators/ZLMA_chart.cs +++ b/Quantower/Indicators/ZLMA_chart.cs @@ -30,12 +30,12 @@ public class ZLMA_chart : Indicator private readonly int matype = 2; #endregion Parameters - + private TBars bars; - /////// + /////// private TSeries indicator; - /////// - + /////// + public ZLMA_chart() { this.SeparateWindow = false; @@ -72,7 +72,8 @@ public class ZLMA_chart : Indicator 4 => new TEMA_Series(source: zerolag, period: this.Period, useNaN: false), 5 => new HMA_Series(source: zerolag, period: this.Period, useNaN: false), 6 => new KAMA_Series(source: zerolag, period: this.Period, useNaN: false), - 7 => new SMMA_Series(source: zerolag, period: this.Period, useNaN: false), + 7 => new JMA_Series(source: zerolag, period: this.Period, useNaN: false), + 8 => new SMMA_Series(source: zerolag, period: this.Period, useNaN: false), _ => new EMA_Series(source: zerolag, period: this.Period, useNaN: false) }; } diff --git a/Source/Feeds/Alphavantage_Feed.cs b/Source/Feeds/Alphavantage_Feed.cs index 62d9be8d..046b9fa3 100644 --- a/Source/Feeds/Alphavantage_Feed.cs +++ b/Source/Feeds/Alphavantage_Feed.cs @@ -13,8 +13,6 @@ Alphavantage - Free API to collect quotes for stock, Forex and crypto. It requir */ -/* TODO: refactor into three feeds: FX, Crypto, Stock */ - public class Alphavantage_Feed : TBars { public enum Interval { Month, Week, Day, Hour, Min30, Min15, Min5, Min1} @@ -115,7 +113,7 @@ public class Alphavantage_Feed : TBars { Interval.Month => "_MONTHLY", Interval.Week => "_WEEKLY", - Interval.Day => "_DAILY_ADJUSTED", + Interval.Day => "_DAILY", Interval.Hour => "_INTRADAY&interval=60min", Interval.Min30 => "_INTRADAY&interval=30min", Interval.Min15 => "_INTRADAY&interval=15min", diff --git a/Source/Feeds/RND_Feed.cs b/Source/Feeds/RND_Feed.cs index 4834142e..b7c42e27 100644 --- a/Source/Feeds/RND_Feed.cs +++ b/Source/Feeds/RND_Feed.cs @@ -1,28 +1,28 @@ -namespace QuanTAlib; -using System; - -/* -Random Bars generator - used for testing, validation and fun - Returns 'bars' number of candles that follow common market movement. - volatility defines how 'jumpy' is the series of - startvalue defines beginning closing price that then guides the rest of series - - */ - -public class RND_Feed : TBars -{ - public RND_Feed(int bars, double volatility = 0.05, double startvalue = 100.0) - { - Random rnd = new(); - double c = startvalue; - for (int i = 0; i < bars; i++) - { - double o = Math.Round(c + c * (volatility * 0.1 * rnd.NextDouble() - 0.005), 2); - double h = Math.Round(o + c * volatility * rnd.NextDouble(), 2); - double l = Math.Round(o - c * volatility * rnd.NextDouble(), 2); - c = Math.Round(l + (h - l) * rnd.NextDouble(), 2); - double v = Math.Round(1000 * rnd.NextDouble(), 2); - this.Add(DateTime.Today.AddDays(i - bars), o, h, l, c, v); - } - } +namespace QuanTAlib; +using System; + +/* +Random Bars generator - used for testing, validation and fun + Returns 'bars' number of candles that follow common market movement. + volatility defines how 'jumpy' is the series of + startvalue defines beginning closing price that then guides the rest of series + + */ + +public class RND_Feed : TBars +{ + public RND_Feed(int bars, double volatility = 0.05, double startvalue = 100.0) + { + Random rnd = new(); + double c = startvalue; + for (int i = 0; i < bars; i++) + { + double o = Math.Round(c + c * (volatility * 0.1 * rnd.NextDouble() - 0.005), 2); + double h = Math.Round(o + c * volatility * rnd.NextDouble(), 2); + double l = Math.Round(o - c * volatility * rnd.NextDouble(), 2); + c = Math.Round(l + (h - l) * rnd.NextDouble(), 2); + double v = Math.Round(1000 * rnd.NextDouble(), 2); + this.Add(DateTime.Today.AddDays(i - bars), o, h, l, c, v); + } + } } \ No newline at end of file diff --git a/Source/Indicators/JMA_Series.cs b/Source/Indicators/JMA_Series.cs index 0b09d939..dfe2bf9a 100644 --- a/Source/Indicators/JMA_Series.cs +++ b/Source/Indicators/JMA_Series.cs @@ -19,9 +19,6 @@ Issues: */ -/* TODO: This indicator is not calculating results correctly - needs to be debugged */ - -/* public class JMA_Series : Single_TSeries_Indicator { private readonly System.Collections.Generic.List vbuffer10; @@ -159,6 +156,4 @@ public class JMA_Series : Single_TSeries_Indicator base.Add(result, update); } -} - -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/Source/QuanTAlib.csproj b/Source/QuanTAlib.csproj index 3ce4f983..7ab08bc8 100644 --- a/Source/QuanTAlib.csproj +++ b/Source/QuanTAlib.csproj @@ -13,7 +13,7 @@ Miha Kralj Miha Kralj readme.md - net6.0;netstandard2.0 + net7.0;net6.0;netstandard2.0 disable preview disable @@ -67,6 +67,6 @@ - + \ No newline at end of file diff --git a/Source/Statistics/PSDEV_Series.cs b/Source/Statistics/PSDEV_Series.cs new file mode 100644 index 00000000..454c9231 --- /dev/null +++ b/Source/Statistics/PSDEV_Series.cs @@ -0,0 +1,44 @@ +namespace QuanTAlib; +using System; + +/* +PSDEV: Population Standard Deviation + Population Standard Deviation is the square root of the biased variance, also knons as + Uncorrected Sample Standard Deviation + +Sources: + https://en.wikipedia.org/wiki/Standard_deviation#Uncorrected_sample_standard_deviation + +Remark: + PSDEV (Population Standard Deviation) is also known as a biased/uncorrected Standard Deviation. + For unbiased version that uses Bessel's correction, use SDEV instead. + + */ + +public class PSDEV_Series : Single_TSeries_Indicator +{ + public PSDEV_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN) + { + if (base._data.Count > 0) { base.Add(base._data); } + } + private readonly System.Collections.Generic.List _buffer = new(); + + public override void Add((System.DateTime t, double v) TValue, bool update) + { + if (update) { _buffer[_buffer.Count - 1] = TValue.v; } + else { _buffer.Add(TValue.v); } + if (_buffer.Count > this._p && this._p != 0) { _buffer.RemoveAt(0); } + + double _sma = 0; + for (int i = 0; i < _buffer.Count; i++) { _sma += _buffer[i]; } + _sma /= this._buffer.Count; + + double _pvar = 0; + for (int i = 0; i < _buffer.Count; i++) { _pvar += (_buffer[i] - _sma) * (_buffer[i] - _sma); } + _pvar /= this._buffer.Count; + double _psdev = Math.Sqrt(_pvar); + + var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _psdev); + base.Add(result, update); + } +} \ No newline at end of file diff --git a/Source/Statistics/SDEV_Series.cs b/Source/Statistics/SDEV_Series.cs index 0784d319..e58ff2dd 100644 --- a/Source/Statistics/SDEV_Series.cs +++ b/Source/Statistics/SDEV_Series.cs @@ -2,17 +2,17 @@ using System; /* -SDEV: Population Standard Deviation - Population Standard Deviation is the square root of the biased variance, also known as - Uncorrected Sample Standard Deviation +SDEV: (Corrected) Sample Standard Deviation + Sample Standard Deviaton uses Bessel's correction to correct the bias in the variance. Sources: - https://en.wikipedia.org/wiki/Standard_deviation#Uncorrected_sample_standard_deviation + https://en.wikipedia.org/wiki/Standard_deviation#Corrected_sample_standard_deviation + Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction Remark: - SDEV (Population Standard Deviation) is also known as a biased/uncorrected Standard Deviation. - For unbiased version that uses Bessel's correction, use SDEV instead. - + SSDEV (Sample Standard Deviation) is also known as a unbiased/corrected Standard Deviation. + For a population/biased/uncorrected Standard Deviation, use PSDEV instead + */ public class SDEV_Series : Single_TSeries_Indicator @@ -25,20 +25,20 @@ public class SDEV_Series : Single_TSeries_Indicator public override void Add((System.DateTime t, double v) TValue, bool update) { - if (update) { _buffer[_buffer.Count - 1] = TValue.v; } - else { _buffer.Add(TValue.v); } - if (_buffer.Count > this._p && this._p != 0) { _buffer.RemoveAt(0); } + if (update) { this._buffer[this._buffer.Count - 1] = TValue.v; } + else { this._buffer.Add(TValue.v); } + if (this._buffer.Count > this._p && this._p != 0) { this._buffer.RemoveAt(0); } double _sma = 0; - for (int i = 0; i < _buffer.Count; i++) { _sma += _buffer[i]; } + for (int i = 0; i < this._buffer.Count; i++) { _sma += this._buffer[i]; } _sma /= this._buffer.Count; - double _pvar = 0; - for (int i = 0; i < _buffer.Count; i++) { _pvar += (_buffer[i] - _sma) * (_buffer[i] - _sma); } - _pvar /= this._buffer.Count; - double _psdev = Math.Sqrt(_pvar); + double _svar = 0; + for (int i = 0; i < this._buffer.Count; i++) { _svar += (this._buffer[i] - _sma) * (this._buffer[i] - _sma); } + _svar /= (this._buffer.Count > 1) ? this._buffer.Count - 1 : 1; // Bessel's correction + double _ssdev = Math.Sqrt(_svar); - var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _psdev); + var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ssdev); base.Add(result, update); } } \ No newline at end of file diff --git a/Source/Statistics/SSDEV_Series.cs b/Source/Statistics/SSDEV_Series.cs deleted file mode 100644 index e5babd4d..00000000 --- a/Source/Statistics/SSDEV_Series.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace QuanTAlib; -using System; - -/* -SSDEV: (Corrected) Sample Standard Deviation - Sample Standard Deviaton uses Bessel's correction to correct the bias in the variance. - -Sources: - https://en.wikipedia.org/wiki/Standard_deviation#Corrected_sample_standard_deviation - Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction - -Remark: - SSDEV (Sample Standard Deviation) is also known as a unbiased/corrected Standard Deviation. - For a population/biased/uncorrected Standard Deviation, use SDEV instead - - */ - -public class SSDEV_Series : Single_TSeries_Indicator -{ - public SSDEV_Series(TSeries source, int period, bool useNaN = false) : base(source, period, useNaN) - { - if (base._data.Count > 0) { base.Add(base._data); } - } - private readonly System.Collections.Generic.List _buffer = new(); - - public override void Add((System.DateTime t, double v) TValue, bool update) - { - if (update) { this._buffer[this._buffer.Count - 1] = TValue.v; } - else { this._buffer.Add(TValue.v); } - if (this._buffer.Count > this._p && this._p != 0) { this._buffer.RemoveAt(0); } - - double _sma = 0; - for (int i = 0; i < this._buffer.Count; i++) { _sma += this._buffer[i]; } - _sma /= this._buffer.Count; - - double _svar = 0; - for (int i = 0; i < this._buffer.Count; i++) { _svar += (this._buffer[i] - _sma) * (this._buffer[i] - _sma); } - _svar /= (this._buffer.Count > 1) ? this._buffer.Count - 1 : 1; // Bessel's correction - double _ssdev = Math.Sqrt(_svar); - - var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ssdev); - base.Add(result, update); - } -} \ No newline at end of file diff --git a/Tests/MovingAvg/JMA_Test.cs b/Tests/MovingAvg/JMA_Test.cs new file mode 100644 index 00000000..c0df4051 --- /dev/null +++ b/Tests/MovingAvg/JMA_Test.cs @@ -0,0 +1,33 @@ +using Xunit; +using System; +using QuanTAlib; + +namespace MovingAvg; +public class JMA_Test +{ + [Fact] + public void Add_Test() + { + TSeries a = new() { 0, 1, 2, 3, 4, 5 }; + JMA_Series c = new(a, 3); + Assert.Equal(6, c.Count); + a.Add(5); + Assert.Equal(a.Count, c.Count); + a.Add(0, update: true); + Assert.Equal(a.Count, c.Count); + } + + [Fact] + public void Edge_Test() + { + TSeries a = new() { double.NaN, double.Epsilon, double.PositiveInfinity, double.MaxValue }; + JMA_Series c = new(a, 3); + Assert.Equal(a.Count, c.Count); + a.Add(double.NaN); + Assert.Equal(a.Count, c.Count); + a.Add(double.PositiveInfinity); + Assert.Equal(a.Count, c.Count); + + } + +} diff --git a/Tests/Statistics/PSDEV_Test.cs b/Tests/Statistics/PSDEV_Test.cs index 503f9a6d..29afa83a 100644 --- a/Tests/Statistics/PSDEV_Test.cs +++ b/Tests/Statistics/PSDEV_Test.cs @@ -9,7 +9,7 @@ public class PSDEV_Test public void Add_Test() { TSeries a = new() { 0, 1, 2, 3, 4, 5 }; - SDEV_Series c = new(a, 3); + PSDEV_Series c = new(a, 3); Assert.Equal(6, c.Count); a.Add(5); Assert.Equal(a.Count, c.Count); @@ -21,7 +21,7 @@ public class PSDEV_Test public void Edge_Test() { TSeries a = new() { double.NaN, double.Epsilon, double.PositiveInfinity, double.MaxValue }; - SDEV_Series c = new(a, 3); + PSDEV_Series c = new(a, 3); Assert.Equal(a.Count, c.Count); a.Add(double.NaN); Assert.Equal(a.Count, c.Count); diff --git a/Tests/Statistics/SDEV_Test .cs b/Tests/Statistics/SDEV_Test .cs index 9b50f719..c1f02a34 100644 --- a/Tests/Statistics/SDEV_Test .cs +++ b/Tests/Statistics/SDEV_Test .cs @@ -9,7 +9,7 @@ public class SDEV_Test public void Add_Test() { TSeries a = new() { 0, 1, 2, 3, 4, 5 }; - SSDEV_Series c = new(a, 3); + SDEV_Series c = new(a, 3); Assert.Equal(6, c.Count); a.Add(5); Assert.Equal(a.Count, c.Count); @@ -21,7 +21,7 @@ public class SDEV_Test public void Edge_Test() { TSeries a = new() { double.NaN, double.Epsilon, double.PositiveInfinity, double.MaxValue }; - SSDEV_Series c = new(a, 3); + SDEV_Series c = new(a, 3); Assert.Equal(a.Count, c.Count); a.Add(double.NaN); Assert.Equal(a.Count, c.Count); diff --git a/Tests/Validations/TA_LIB.cs b/Tests/Validations/TA_LIB.cs index 40ef39cb..ebfc1a68 100644 --- a/Tests/Validations/TA_LIB.cs +++ b/Tests/Validations/TA_LIB.cs @@ -129,14 +129,4 @@ MACD_Series QL = new(this.bars.Close, slow: 26, fast: 12, signal: 9, false); Core.Macd(this.inclose, 0, this.bars.Count - 1, outMacd: this.TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _); Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); } - - [Fact] - public void SDEV() - { - SDEV_Series QL = new(this.bars.Close, this.period, false); - Core.StdDev(this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _, this.period); - - Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); - } - } diff --git a/Docs/.nojekyll b/docs/.nojekyll similarity index 100% rename from Docs/.nojekyll rename to docs/.nojekyll diff --git a/docs/Comparing_w_TALIB.ipynb b/docs/Comparing_w_TALIB.ipynb index 48ca553d..4f245ac7 100644 --- a/docs/Comparing_w_TALIB.ipynb +++ b/docs/Comparing_w_TALIB.ipynb @@ -1,148 +1,148 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
Installed Packages
  • QuanTAlib, 0.1.10-beta
  • TALib.NETCore, 0.4.4
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "#r \"nuget: TALib.NETCore, 0.4.4\" \n", - "#r \"nuget: QuanTAlib, 0.1.10-beta\" \n", - "\n", - "using QuanTAlib;\n", - "using TALib;\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "ename": "Error", - "evalue": "(1,1): error CS0246: The type or namespace name 'YAHOO_Feed' could not be found (are you missing a using directive or an assembly reference?)", - "output_type": "error", - "traceback": [ - "(1,1): error CS0246: The type or namespace name 'YAHOO_Feed' could not be found (are you missing a using directive or an assembly reference?)" - ] - } - ], - "source": [ - "YAHOO_Feed aapl = new(2020,\"AAPL\");\n", - "TSeries data = aapl.Close;\n", - "\n", - "data.Count()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [], - "source": [ - "int period = 10;\n", - "\n", - "//QuanTAlib SMA algorithm\n", - "SMA_Series e = new(data, period, false); \n", - "\n", - "// direct call to SMA from TA-LIB - with stitching NaNs in front\n", - "int outBegIdx, outNbElement;\n", - "double[] output = new double[data.Count];\n", - "double[] nans = new double[period];\n", - "double[] ta_temp = new double[data.Count-period+1];\n", - "Array.Fill(nans, double.NaN);\n", - "Core.Sma(data.v.ToArray(), 0, data.Count-1, ta_temp, out outBegIdx, out outNbElement, period); //TA-LIB SMA method\n", - "nans.CopyTo(output,0);\n", - "ta_temp.CopyTo(output,period-1);\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "QuantLib\t TA-LIB\n", - "164.31\t\t 164.31\n", - "166.81\t\t 166.81\n", - "169.20\t\t 169.20\n", - "171.01\t\t 171.01\n", - "172.41\t\t 172.41\n", - "173.45\t\t 173.45\n", - "174.75\t\t 174.75\n", - "175.38\t\t 175.38\n", - "175.54\t\t 175.54\n", - "\n", - "1394\t\t 1394\n" - ] - } - ], - "source": [ - "// comparing the tail of QuanTAlib and TA-LIB\n", - "Console.Write($\"QuanTAlib\\t TA-LIB\\n\");\n", - "for (int i=data.Count-10; i
Installed Packages
  • QuanTAlib, 0.1.10-beta
  • TALib.NETCore, 0.4.4
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#r \"nuget: TALib.NETCore, 0.4.4\" \n", + "#r \"nuget: QuanTAlib, 0.1.10-beta\" \n", + "\n", + "using QuanTAlib;\n", + "using TALib;\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "ename": "Error", + "evalue": "(1,1): error CS0246: The type or namespace name 'YAHOO_Feed' could not be found (are you missing a using directive or an assembly reference?)", + "output_type": "error", + "traceback": [ + "(1,1): error CS0246: The type or namespace name 'YAHOO_Feed' could not be found (are you missing a using directive or an assembly reference?)" + ] + } + ], + "source": [ + "YAHOO_Feed aapl = new(2020,\"AAPL\");\n", + "TSeries data = aapl.Close;\n", + "\n", + "data.Count()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [], + "source": [ + "int period = 10;\n", + "\n", + "//QuanTAlib SMA algorithm\n", + "SMA_Series e = new(data, period, false); \n", + "\n", + "// direct call to SMA from TA-LIB - with stitching NaNs in front\n", + "int outBegIdx, outNbElement;\n", + "double[] output = new double[data.Count];\n", + "double[] nans = new double[period];\n", + "double[] ta_temp = new double[data.Count-period+1];\n", + "Array.Fill(nans, double.NaN);\n", + "Core.Sma(data.v.ToArray(), 0, data.Count-1, ta_temp, out outBegIdx, out outNbElement, period); //TA-LIB SMA method\n", + "nans.CopyTo(output,0);\n", + "ta_temp.CopyTo(output,period-1);\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "QuantLib\t TA-LIB\n", + "164.31\t\t 164.31\n", + "166.81\t\t 166.81\n", + "169.20\t\t 169.20\n", + "171.01\t\t 171.01\n", + "172.41\t\t 172.41\n", + "173.45\t\t 173.45\n", + "174.75\t\t 174.75\n", + "175.38\t\t 175.38\n", + "175.54\t\t 175.54\n", + "\n", + "1394\t\t 1394\n" + ] + } + ], + "source": [ + "// comparing the tail of QuanTAlib and TA-LIB\n", + "Console.Write($\"QuanTAlib\\t TA-LIB\\n\");\n", + "for (int i=data.Count-10; i
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "#r \"nuget:YahooFinanceApi;\" \n", - "#r \"nuget:QuanTAlib;\" \n", - "using YahooFinanceApi;\n", - "using QuanTAlib;\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Date\t\t Value\t SMA\t MAD\t STDDEV\t MSE\t MAPE\n", - " 2022-03-14\t 150.62\t 150.62\t 0.00\t 0.00\t 0.00\t 0.00\t\n", - "2022-03-15\t 155.09\t 152.85\t 2.24\t 3.16\t 5.00\t 0.01\t\n", - "2022-03-16\t 159.59\t 155.10\t 2.99\t 4.49\t 13.41\t 0.02\t\n", - "2022-03-17\t 160.62\t 156.48\t 3.62\t 4.59\t 15.77\t 0.02\t\n", - "2022-03-18\t 163.98\t 157.98\t 4.10\t 5.20\t 21.62\t 0.03\t\n", - "2022-03-21\t 165.38\t 160.93\t 3.00\t 4.03\t 13.02\t 0.02\t\n", - "2022-03-22\t 168.82\t 163.68\t 2.86\t 3.72\t 11.10\t 0.02\t\n", - "2022-03-23\t 170.21\t 165.80\t 2.97\t 3.84\t 11.78\t 0.02\t\n", - "2022-03-24\t 174.07\t 168.49\t 3.05\t 4.01\t 12.84\t 0.02\t\n", - "2022-03-25\t 174.72\t 170.64\t 3.00\t 3.86\t 11.92\t 0.02\t\n", - "2022-03-28\t 175.60\t 172.68\t 2.54\t 2.98\t 7.12\t 0.01\t\n", - "2022-03-29\t 178.96\t 174.71\t 2.06\t 3.14\t 7.90\t 0.01\t\n", - "2022-03-30\t 177.77\t 176.22\t 1.71\t 2.07\t 3.43\t 0.01\t\n", - "2022-03-31\t 174.61\t 176.33\t 1.63\t 1.94\t 3.01\t 0.01\t\n" - ] - } - ], - "source": [ - "TSeries data = new();\n", - "var history = await Yahoo.GetHistoricalAsync(\"AAPL\", DateTime.Today.AddDays(-19), DateTime.Now, Period.Daily);\n", - "SMA_Series sma = new(data, 5, false);\n", - "SUB_Series sub = new(sma.STDDEV,sma.MAD);\n", - "Console.Write($\"Date\\t\\t Value\\t SMA\\t MAD\\t STDDEV\\t MSE\\t MAPE\\n \");\n", - "foreach (var i in history) {\n", - " data.Add((i.DateTime, (double)i.Close));\n", - " Console.Write($\"{data[^1].t:yyyy-MM-dd}\\t {(double)data:f2}\\t {(double)sma:f2}\\t {(double)sma.MAD:f2}\\t {(double)sma.STDDEV:f2}\\t {(double)sma.MSE:f2}\\t {(double)sma.MAPE:f2}\\t\\n\");\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "date\t\t Value\t SMA\t WMA\t EMA\t HMA\t DEMA\t TEMA \tZLEMA \tJMA\r\n", - "2022-03-21\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\n", - "2022-03-22\t 168.82\t 167.10\t 167.67\t 166.53\t 166.91\t 167.29\t 167.80\t 167.67\t 168.29\n", - "2022-03-23\t 170.21\t 168.14\t 168.94\t 167.75\t 168.52\t 169.08\t 169.80\t 170.13\t 170.00\n", - "2022-03-24\t 174.07\t 169.62\t 170.99\t 169.86\t 171.53\t 172.15\t 173.27\t 173.19\t 173.30\n", - "2022-03-25\t 174.72\t 170.64\t 172.24\t 171.48\t 174.45\t 174.09\t 175.04\t 175.21\t 174.42\n", - "2022-03-28\t 175.60\t 172.68\t 173.89\t 172.85\t 175.90\t 175.51\t 176.18\t 175.85\t 175.23\n", - "2022-03-29\t 178.96\t 174.71\t 175.98\t 174.89\t 177.60\t 178.01\t 178.78\t 178.30\t 177.49\n", - "2022-03-30\t 177.77\t 176.22\t 177.00\t 175.85\t 178.50\t 178.57\t 178.81\t 178.85\t 177.95\n", - "2022-03-31\t 174.61\t 176.33\t 176.46\t 175.44\t 177.08\t 176.98\t 176.35\t 175.98\t 176.09\n" - ] - } - ], - "source": [ - "TSeries data = new();\n", - "var history = await Yahoo.GetHistoricalAsync(\"AAPL\", DateTime.Today.AddDays(-10), DateTime.Now, Period.Daily);\n", - "SMA_Series sma = new(data, 5);\n", - "WMA_Series wma = new(data, 5);\n", - "EMA_Series ema = new(data, 5);\n", - "HMA_Series hma = new(data, 5);\n", - "DEMA_Series dema = new(data, 5);\n", - "TEMA_Series tema = new(data, 5);\n", - "ZLEMA_Series zlema = new(data, 5);\n", - "JMA_Series jma = new(data, 5);\n", - "\n", - "Console.WriteLine($\"date\\t\\t Value\\t SMA\\t WMA\\t EMA\\t HMA\\t DEMA\\t TEMA \\tZLEMA \\tJMA\");\n", - "foreach (var i in history) {\n", - " data.Add((i.DateTime, (double)i.Close)); // adding data will signal dependant indicators\n", - "\n", - " Console.Write($\"{data[^1].t:yyyy-MM-dd}\\t {(double)data:f2}\\t {(double)sma:f2}\\t {(double)wma:f2}\\t {(double)ema:f2}\\t {(double)hma:f2}\\t {(double)dema:f2}\\t {(double)tema:f2}\\t {(double)zlema:f2}\\t {(double)jma:f2}\\n\");\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
indexItem1Item2
02022-03-21 00:00:00Z
165.380005
12022-03-22 00:00:00Z
167.9823694096766
22022-03-23 00:00:00Z
170.06602047454277
32022-03-24 00:00:00Z
173.24670154378663
42022-03-25 00:00:00Z
174.81344756154755
52022-03-28 00:00:00Z
175.53949324963583
62022-03-29 00:00:00Z
177.89435364830672
72022-03-30 00:00:00Z
178.39609966493987
82022-03-31 00:00:00Z
176.03431272212282
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "ADD_Series two = new(zlema, jma); // even when indicator is created later, it will grab the data from its source table\n", - "DIV_Series mean = new(two, 2); // this pair here calculates mean of ZLEMA and JMA indicators\n", - "\n", - "mean" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [], - "source": [ - "public class ALMA_Series : TSeries\n", - "{\n", - " private readonly int _p;\n", - " private readonly bool _NaN;\n", - " private readonly TSeries _data;\n", - " private readonly double _offset, _sigma;\n", - " private double _norm;\n", - " private readonly System.Collections.Generic.List _buffer = new();\n", - " private readonly System.Collections.Generic.List _weights = new();\n", - "\n", - " public ALMA_Series(TSeries source, int period, double offset = 0.85, double sigma = 6.0, bool useNaN = false)\n", - " {\n", - " this._p = period;\n", - " this._data = source;\n", - " this._NaN = useNaN;\n", - " _offset = offset;\n", - " _sigma = sigma;\n", - "\n", - " double _m = _offset * (_p - 1);\n", - " double _s = _p / _sigma;\n", - "\n", - " _norm = 0;\n", - " for (int i = 0; i < this._p; i++)\n", - " {\n", - " double wt = Math.Exp(-((i - _m) * (i - _m)) / (2 * _s * _s));\n", - " this._weights.Add(wt);\n", - " _norm += wt;\n", - " }\n", - "\n", - " source.Pub += this.Sub;\n", - " if (source.Count > 0)\n", - " {\n", - " for (int i = 0; i < source.Count; i++)\n", - " {\n", - " this.Add(source[i], false);\n", - " }\n", - " }\n", - "\n", - " }\n", - " public new void Add((System.DateTime t, double v) data, bool update = false)\n", - " {\n", - " if (update) { this._buffer[this._buffer.Count - 1] = data.v; } else { this._buffer.Add(data.v); }\n", - " if (this._buffer.Count > this._p) { this._buffer.RemoveAt(0); }\n", - "\n", - " double _wma = 0;\n", - " for (int i = 0; i < this._buffer.Count; i++) { _wma += this._buffer[i] * this._weights[i]; }\n", - " if (this._buffer.Count < this._p) {\n", - " _norm = 0;\n", - " for (int i = 0; i < this._buffer.Count; i++) { _norm += this._weights[i];}\n", - " }\n", - " _wma /= _norm;\n", - "\n", - " (System.DateTime t, double v) result = (data.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _wma);\n", - " if (update) { base[base.Count - 1] = result; } else { base.Add(result); }\n", - " }\n", - " public void Add(bool update = false)\n", - " {\n", - " this.Add(this._data[this._data.Count - 1], update);\n", - " }\n", - " public new void Sub(object source, TSeriesEventArgs e) { this.Add(this._data[this._data.Count - 1], e.update); }\n", - "\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [], - "source": [ - "TSeries data = new() {212.80, 214.06, 213.89, 214.66, 213.95, 213.95, 214.55, 214.02, 214.51, 213.75, 214.22, 213.43 };\n", - "ALMA_Series alma = new(data, period: 10, offset: 0.0, sigma: 6.0, useNaN: true);\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2022-03-31\t 212.80\t NaN\t \n", - "2022-03-31\t 214.06\t NaN\t \n", - "2022-03-31\t 213.89\t NaN\t \n", - "2022-03-31\t 214.66\t NaN\t \n", - "2022-03-31\t 213.95\t NaN\t \n", - "2022-03-31\t 213.95\t NaN\t \n", - "2022-03-31\t 214.55\t NaN\t \n", - "2022-03-31\t 214.02\t NaN\t \n", - "2022-03-31\t 214.51\t NaN\t \n", - "2022-03-31\t 213.75\t 213.58\t \n", - "2022-03-31\t 214.22\t 214.11\t \n", - "2022-03-31\t 213.43\t 214.17\t \n" - ] - } - ], - "source": [ - "for (int i=0; i
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#r \"nuget:YahooFinanceApi;\" \n", + "#r \"nuget:QuanTAlib;\" \n", + "using YahooFinanceApi;\n", + "using QuanTAlib;\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Date\t\t Value\t SMA\t MAD\t STDDEV\t MSE\t MAPE\n", + " 2022-03-14\t 150.62\t 150.62\t 0.00\t 0.00\t 0.00\t 0.00\t\n", + "2022-03-15\t 155.09\t 152.85\t 2.24\t 3.16\t 5.00\t 0.01\t\n", + "2022-03-16\t 159.59\t 155.10\t 2.99\t 4.49\t 13.41\t 0.02\t\n", + "2022-03-17\t 160.62\t 156.48\t 3.62\t 4.59\t 15.77\t 0.02\t\n", + "2022-03-18\t 163.98\t 157.98\t 4.10\t 5.20\t 21.62\t 0.03\t\n", + "2022-03-21\t 165.38\t 160.93\t 3.00\t 4.03\t 13.02\t 0.02\t\n", + "2022-03-22\t 168.82\t 163.68\t 2.86\t 3.72\t 11.10\t 0.02\t\n", + "2022-03-23\t 170.21\t 165.80\t 2.97\t 3.84\t 11.78\t 0.02\t\n", + "2022-03-24\t 174.07\t 168.49\t 3.05\t 4.01\t 12.84\t 0.02\t\n", + "2022-03-25\t 174.72\t 170.64\t 3.00\t 3.86\t 11.92\t 0.02\t\n", + "2022-03-28\t 175.60\t 172.68\t 2.54\t 2.98\t 7.12\t 0.01\t\n", + "2022-03-29\t 178.96\t 174.71\t 2.06\t 3.14\t 7.90\t 0.01\t\n", + "2022-03-30\t 177.77\t 176.22\t 1.71\t 2.07\t 3.43\t 0.01\t\n", + "2022-03-31\t 174.61\t 176.33\t 1.63\t 1.94\t 3.01\t 0.01\t\n" + ] + } + ], + "source": [ + "TSeries data = new();\n", + "var history = await Yahoo.GetHistoricalAsync(\"AAPL\", DateTime.Today.AddDays(-19), DateTime.Now, Period.Daily);\n", + "SMA_Series sma = new(data, 5, false);\n", + "SUB_Series sub = new(sma.STDDEV,sma.MAD);\n", + "Console.Write($\"Date\\t\\t Value\\t SMA\\t MAD\\t STDDEV\\t MSE\\t MAPE\\n \");\n", + "foreach (var i in history) {\n", + " data.Add((i.DateTime, (double)i.Close));\n", + " Console.Write($\"{data[^1].t:yyyy-MM-dd}\\t {(double)data:f2}\\t {(double)sma:f2}\\t {(double)sma.MAD:f2}\\t {(double)sma.STDDEV:f2}\\t {(double)sma.MSE:f2}\\t {(double)sma.MAPE:f2}\\t\\n\");\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "date\t\t Value\t SMA\t WMA\t EMA\t HMA\t DEMA\t TEMA \tZLEMA \tJMA\r\n", + "2022-03-21\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\t 165.38\n", + "2022-03-22\t 168.82\t 167.10\t 167.67\t 166.53\t 166.91\t 167.29\t 167.80\t 167.67\t 168.29\n", + "2022-03-23\t 170.21\t 168.14\t 168.94\t 167.75\t 168.52\t 169.08\t 169.80\t 170.13\t 170.00\n", + "2022-03-24\t 174.07\t 169.62\t 170.99\t 169.86\t 171.53\t 172.15\t 173.27\t 173.19\t 173.30\n", + "2022-03-25\t 174.72\t 170.64\t 172.24\t 171.48\t 174.45\t 174.09\t 175.04\t 175.21\t 174.42\n", + "2022-03-28\t 175.60\t 172.68\t 173.89\t 172.85\t 175.90\t 175.51\t 176.18\t 175.85\t 175.23\n", + "2022-03-29\t 178.96\t 174.71\t 175.98\t 174.89\t 177.60\t 178.01\t 178.78\t 178.30\t 177.49\n", + "2022-03-30\t 177.77\t 176.22\t 177.00\t 175.85\t 178.50\t 178.57\t 178.81\t 178.85\t 177.95\n", + "2022-03-31\t 174.61\t 176.33\t 176.46\t 175.44\t 177.08\t 176.98\t 176.35\t 175.98\t 176.09\n" + ] + } + ], + "source": [ + "TSeries data = new();\n", + "var history = await Yahoo.GetHistoricalAsync(\"AAPL\", DateTime.Today.AddDays(-10), DateTime.Now, Period.Daily);\n", + "SMA_Series sma = new(data, 5);\n", + "WMA_Series wma = new(data, 5);\n", + "EMA_Series ema = new(data, 5);\n", + "HMA_Series hma = new(data, 5);\n", + "DEMA_Series dema = new(data, 5);\n", + "TEMA_Series tema = new(data, 5);\n", + "ZLEMA_Series zlema = new(data, 5);\n", + "JMA_Series jma = new(data, 5);\n", + "\n", + "Console.WriteLine($\"date\\t\\t Value\\t SMA\\t WMA\\t EMA\\t HMA\\t DEMA\\t TEMA \\tZLEMA \\tJMA\");\n", + "foreach (var i in history) {\n", + " data.Add((i.DateTime, (double)i.Close)); // adding data will signal dependant indicators\n", + "\n", + " Console.Write($\"{data[^1].t:yyyy-MM-dd}\\t {(double)data:f2}\\t {(double)sma:f2}\\t {(double)wma:f2}\\t {(double)ema:f2}\\t {(double)hma:f2}\\t {(double)dema:f2}\\t {(double)tema:f2}\\t {(double)zlema:f2}\\t {(double)jma:f2}\\n\");\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
indexItem1Item2
02022-03-21 00:00:00Z
165.380005
12022-03-22 00:00:00Z
167.9823694096766
22022-03-23 00:00:00Z
170.06602047454277
32022-03-24 00:00:00Z
173.24670154378663
42022-03-25 00:00:00Z
174.81344756154755
52022-03-28 00:00:00Z
175.53949324963583
62022-03-29 00:00:00Z
177.89435364830672
72022-03-30 00:00:00Z
178.39609966493987
82022-03-31 00:00:00Z
176.03431272212282
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "ADD_Series two = new(zlema, jma); // even when indicator is created later, it will grab the data from its source table\n", + "DIV_Series mean = new(two, 2); // this pair here calculates mean of ZLEMA and JMA indicators\n", + "\n", + "mean" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [], + "source": [ + "public class ALMA_Series : TSeries\n", + "{\n", + " private readonly int _p;\n", + " private readonly bool _NaN;\n", + " private readonly TSeries _data;\n", + " private readonly double _offset, _sigma;\n", + " private double _norm;\n", + " private readonly System.Collections.Generic.List _buffer = new();\n", + " private readonly System.Collections.Generic.List _weights = new();\n", + "\n", + " public ALMA_Series(TSeries source, int period, double offset = 0.85, double sigma = 6.0, bool useNaN = false)\n", + " {\n", + " this._p = period;\n", + " this._data = source;\n", + " this._NaN = useNaN;\n", + " _offset = offset;\n", + " _sigma = sigma;\n", + "\n", + " double _m = _offset * (_p - 1);\n", + " double _s = _p / _sigma;\n", + "\n", + " _norm = 0;\n", + " for (int i = 0; i < this._p; i++)\n", + " {\n", + " double wt = Math.Exp(-((i - _m) * (i - _m)) / (2 * _s * _s));\n", + " this._weights.Add(wt);\n", + " _norm += wt;\n", + " }\n", + "\n", + " source.Pub += this.Sub;\n", + " if (source.Count > 0)\n", + " {\n", + " for (int i = 0; i < source.Count; i++)\n", + " {\n", + " this.Add(source[i], false);\n", + " }\n", + " }\n", + "\n", + " }\n", + " public new void Add((System.DateTime t, double v) data, bool update = false)\n", + " {\n", + " if (update) { this._buffer[this._buffer.Count - 1] = data.v; } else { this._buffer.Add(data.v); }\n", + " if (this._buffer.Count > this._p) { this._buffer.RemoveAt(0); }\n", + "\n", + " double _wma = 0;\n", + " for (int i = 0; i < this._buffer.Count; i++) { _wma += this._buffer[i] * this._weights[i]; }\n", + " if (this._buffer.Count < this._p) {\n", + " _norm = 0;\n", + " for (int i = 0; i < this._buffer.Count; i++) { _norm += this._weights[i];}\n", + " }\n", + " _wma /= _norm;\n", + "\n", + " (System.DateTime t, double v) result = (data.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _wma);\n", + " if (update) { base[base.Count - 1] = result; } else { base.Add(result); }\n", + " }\n", + " public void Add(bool update = false)\n", + " {\n", + " this.Add(this._data[this._data.Count - 1], update);\n", + " }\n", + " public new void Sub(object source, TSeriesEventArgs e) { this.Add(this._data[this._data.Count - 1], e.update); }\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [], + "source": [ + "TSeries data = new() {212.80, 214.06, 213.89, 214.66, 213.95, 213.95, 214.55, 214.02, 214.51, 213.75, 214.22, 213.43 };\n", + "ALMA_Series alma = new(data, period: 10, offset: 0.0, sigma: 6.0, useNaN: true);\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2022-03-31\t 212.80\t NaN\t \n", + "2022-03-31\t 214.06\t NaN\t \n", + "2022-03-31\t 213.89\t NaN\t \n", + "2022-03-31\t 214.66\t NaN\t \n", + "2022-03-31\t 213.95\t NaN\t \n", + "2022-03-31\t 213.95\t NaN\t \n", + "2022-03-31\t 214.55\t NaN\t \n", + "2022-03-31\t 214.02\t NaN\t \n", + "2022-03-31\t 214.51\t NaN\t \n", + "2022-03-31\t 213.75\t 213.58\t \n", + "2022-03-31\t 214.22\t 214.11\t \n", + "2022-03-31\t 213.43\t 214.17\t \n" + ] + } + ], + "source": [ + "for (int i=0; iVisual Studio Code\n", - "- Installed .NET 6 SDK\n", - "- Installed .NET Interactive Notebooks extension\n", - "\n", - "**For impatient**, here is a simple example of calculating three moving averages - SMA(data), EMA(SMA(data)) and WMA(EMA(SMA(data))) from 10 days of AAPL stock data using QuanTAlib:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "index\t data\t\t sma(data)\t ema(sma(data))\t wma(ema(sma(data)))\n", - "0\t 2022-03-23\t 170.21\t\t 170.21\t\t NaN\n", - "1\t 2022-03-24\t 172.14\t\t 170.85\t\t NaN\n", - "2\t 2022-03-25\t 173.00\t\t 171.57\t\t NaN\n", - "3\t 2022-03-28\t 173.65\t\t 172.26\t\t NaN\n", - "4\t 2022-03-29\t 174.71\t\t 173.08\t\t 172.07\n", - "5\t 2022-03-30\t 176.22\t\t 174.13\t\t 172.92\n", - "6\t 2022-03-31\t 176.33\t\t 174.86\t\t 173.74\n", - "7\t 2022-04-01\t 176.25\t\t 175.32\t\t 174.46\n", - "8\t 2022-04-04\t 176.82\t\t 175.82\t\t 175.09\n", - "9\t 2022-04-05\t 176.04\t\t 175.89\t\t 175.51\n", - "10\t 2022-04-06\t 174.85\t\t 175.55\t\t 175.62\n", - "11\t 2022-04-07\t 174.36\t\t 175.15\t\t 175.51\n" - ] - } - ], - "source": [ - "#r \"nuget:QuanTAlib;\"\n", - "using QuanTAlib;\n", - "\n", - "YAHOO_Feed aapl = new(15, \"AAPL\");\n", - "TSeries data = aapl.Close;\n", - "SMA_Series sma = new(source: data, period: 5, useNaN: false);\n", - "EMA_Series ema = new(sma, period: 5); // by default, indicators expose all data, no NaN values\n", - "WMA_Series wma = new(ema, 5, useNaN: true); // for the final calculation we can hide early data with NaNs\n", - "\n", - "Console.Write($\"index\\t data\\t\\t sma(data)\\t ema(sma(data))\\t wma(ema(sma(data)))\\n\");\n", - "for (int i=0; iindexItem1Item202022-04-07 00:00:00Z
105.3
12022-04-07 21:57:46Z
293.1
22022-04-07 21:57:46Z
0
32022-04-04 21:57:46Z
10
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "var item1 = (DateTime.Today, 105.3); // (DateTime, Value) tuple\n", - "double item2 = 293.1; // a simple double\n", - "\n", - "TSeries data = new();\n", - "data.Add(item1); // adding tuple variable\n", - "data.Add(item2); // QuanTAlib stamps the (double) with current time\n", - "data.Add(0); // directly adding a number (stamped with current time)\n", - "data.Add((DateTime.Now.AddDays(-3), 10)); // adding a tuple with timestamp 3 days ago\n", - "\n", - "data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "TSeries list can display only values (without timestamps) or only timestamps (without values) by using `.v` or `.t` properties" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
indexvalue
0
105.3
1
293.1
2
0
3
10
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "data.v" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The last element on the list can be accessed by .Last() or by [^1] - and using `.t` (time) and `.v` (value) properties. Also, casting a TSeries into (double) will return the value of the last element" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
10
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "bool IsTheSame = data.Last().v == data[^1].v;\n", - "double lastvalue = data;\n", - "\n", - "lastvalue" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All indicators are just modified TSeries classes; they get all required input during class construction (source of the datafeed, period...) and they automatically subscribe to events of the datafeed. Whenever datafeed gets a new value, indicator will calculate its own value. Indicators are also event publishers, so other indicators can subscribe to their results, chaining indicators together:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
indexvalue
0
Infinity
1
0.6666666666666666
2
0.3076923076923077
3
0.1951219512195122
4
0.1415929203539823
5
0.11072664359861592
6
0.09078014184397164
7
0.07687687687687687
8
0.06664931007550118
9
0.05881677197013211
10
0.2499389797412741
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "TSeries t1 = new() {0,1,2,3,4,5,6,7,8,9}; // t1 is loaded with data and activated as a publisher\n", - "EMA_Series t2 = new(t1, 3); // t2 will auto-load all history of t1 and wait for events from t1\n", - "ADD_Series t3 = new(t1, t2); // t3 is an ADDition of t1 and t2 - will also load history and wait for t2 events\n", - "DIV_Series t4 = new(1, t3); // t4 is calculating 1/t3 - and waiting for t3 events\n", - "\n", - "TSeries t5 = new(); // a wild indicator appeared! And it is empty!\n", - "t4.Pub += t5.Sub; // let us add a manual subscription to events coming from t4 - t5 is now listening to t4\n", - "t1.Add(0); // we add one new value to t1 - and trigger the full cascade of calculation! t5 is now full!\n", - "\n", - "t5.v" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# MACD compounded indicator\n", - "\n", - "With QuanTAlib we can chain indicators together, creating complex compounded indicators. For example, we can create Moving Average Convergence/Divergence (MACD) indicators by chaining all required operations in a sequence:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "vscode": { - "languageId": "dotnet-interactive.csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
indexvalue
0
0
1
0.08934530370370339
2
0.3599908358509947
3
0.5984373224068585
4
0.9604679820661939
5
1.17393637722238
6
1.295101583309171
7
1.5073770108948183
8
1.4718244887751928
9
1.1537265475126177
10
0.8550987734004014
11
0.8650928385987653
12
0.5867583008849087
13
0.15053155636913873
14
-0.13622024638714825
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "YAHOO_Feed aapl = new(20, \"AAPL\");\n", - "TSeries close = aapl.Close; // close will get data from history\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", - "SUB_Series macd = new(fast,slow); // macd is a SUBtraction: fast-slow\n", - "EMA_Series signal = new(macd,9); // signal is EMA of macd\n", - "SUB_Series histogram = new(macd, signal); // histogram is SUBtraction macd-signal\n", - "\n", - "histogram.v\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".NET (C#)", - "language": "C#", - "name": ".net-csharp" - }, - "language_info": { - "file_extension": ".cs", - "mimetype": "text/x-csharp", - "name": "C#", - "pygments_lexer": "csharp", - "version": "9.0" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Quick Start\n", + "\n", + "In order to use this .NET Interactive Notebook and play along with QuanTAlib (outside of making your own app or plugging QuanTAlib into Quantower platform), you will need:\n", + "\n", + "- Installed Visual Studio Code\n", + "- Installed .NET 6 SDK\n", + "- Installed .NET Interactive Notebooks extension\n", + "\n", + "**For impatient**, here is a simple example of calculating three moving averages - SMA(data), EMA(SMA(data)) and WMA(EMA(SMA(data))) from 10 days of AAPL stock data using QuanTAlib:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "index\t data\t\t sma(data)\t ema(sma(data))\t wma(ema(sma(data)))\n", + "0\t 2022-03-23\t 170.21\t\t 170.21\t\t NaN\n", + "1\t 2022-03-24\t 172.14\t\t 170.85\t\t NaN\n", + "2\t 2022-03-25\t 173.00\t\t 171.57\t\t NaN\n", + "3\t 2022-03-28\t 173.65\t\t 172.26\t\t NaN\n", + "4\t 2022-03-29\t 174.71\t\t 173.08\t\t 172.07\n", + "5\t 2022-03-30\t 176.22\t\t 174.13\t\t 172.92\n", + "6\t 2022-03-31\t 176.33\t\t 174.86\t\t 173.74\n", + "7\t 2022-04-01\t 176.25\t\t 175.32\t\t 174.46\n", + "8\t 2022-04-04\t 176.82\t\t 175.82\t\t 175.09\n", + "9\t 2022-04-05\t 176.04\t\t 175.89\t\t 175.51\n", + "10\t 2022-04-06\t 174.85\t\t 175.55\t\t 175.62\n", + "11\t 2022-04-07\t 174.36\t\t 175.15\t\t 175.51\n" + ] + } + ], + "source": [ + "#r \"nuget:QuanTAlib;\"\n", + "using QuanTAlib;\n", + "\n", + "YAHOO_Feed aapl = new(15, \"AAPL\");\n", + "TSeries data = aapl.Close;\n", + "SMA_Series sma = new(source: data, period: 5, useNaN: false);\n", + "EMA_Series ema = new(sma, period: 5); // by default, indicators expose all data, no NaN values\n", + "WMA_Series wma = new(ema, 5, useNaN: true); // for the final calculation we can hide early data with NaNs\n", + "\n", + "Console.Write($\"index\\t data\\t\\t sma(data)\\t ema(sma(data))\\t wma(ema(sma(data)))\\n\");\n", + "for (int i=0; iindexItem1Item202022-04-07 00:00:00Z
105.3
12022-04-07 21:57:46Z
293.1
22022-04-07 21:57:46Z
0
32022-04-04 21:57:46Z
10
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "var item1 = (DateTime.Today, 105.3); // (DateTime, Value) tuple\n", + "double item2 = 293.1; // a simple double\n", + "\n", + "TSeries data = new();\n", + "data.Add(item1); // adding tuple variable\n", + "data.Add(item2); // QuanTAlib stamps the (double) with current time\n", + "data.Add(0); // directly adding a number (stamped with current time)\n", + "data.Add((DateTime.Now.AddDays(-3), 10)); // adding a tuple with timestamp 3 days ago\n", + "\n", + "data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "TSeries list can display only values (without timestamps) or only timestamps (without values) by using `.v` or `.t` properties" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
indexvalue
0
105.3
1
293.1
2
0
3
10
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "data.v" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The last element on the list can be accessed by .Last() or by [^1] - and using `.t` (time) and `.v` (value) properties. Also, casting a TSeries into (double) will return the value of the last element" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
10
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "bool IsTheSame = data.Last().v == data[^1].v;\n", + "double lastvalue = data;\n", + "\n", + "lastvalue" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "All indicators are just modified TSeries classes; they get all required input during class construction (source of the datafeed, period...) and they automatically subscribe to events of the datafeed. Whenever datafeed gets a new value, indicator will calculate its own value. Indicators are also event publishers, so other indicators can subscribe to their results, chaining indicators together:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
indexvalue
0
Infinity
1
0.6666666666666666
2
0.3076923076923077
3
0.1951219512195122
4
0.1415929203539823
5
0.11072664359861592
6
0.09078014184397164
7
0.07687687687687687
8
0.06664931007550118
9
0.05881677197013211
10
0.2499389797412741
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "TSeries t1 = new() {0,1,2,3,4,5,6,7,8,9}; // t1 is loaded with data and activated as a publisher\n", + "EMA_Series t2 = new(t1, 3); // t2 will auto-load all history of t1 and wait for events from t1\n", + "ADD_Series t3 = new(t1, t2); // t3 is an ADDition of t1 and t2 - will also load history and wait for t2 events\n", + "DIV_Series t4 = new(1, t3); // t4 is calculating 1/t3 - and waiting for t3 events\n", + "\n", + "TSeries t5 = new(); // a wild indicator appeared! And it is empty!\n", + "t4.Pub += t5.Sub; // let us add a manual subscription to events coming from t4 - t5 is now listening to t4\n", + "t1.Add(0); // we add one new value to t1 - and trigger the full cascade of calculation! t5 is now full!\n", + "\n", + "t5.v" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# MACD compounded indicator\n", + "\n", + "With QuanTAlib we can chain indicators together, creating complex compounded indicators. For example, we can create Moving Average Convergence/Divergence (MACD) indicators by chaining all required operations in a sequence:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
indexvalue
0
0
1
0.08934530370370339
2
0.3599908358509947
3
0.5984373224068585
4
0.9604679820661939
5
1.17393637722238
6
1.295101583309171
7
1.5073770108948183
8
1.4718244887751928
9
1.1537265475126177
10
0.8550987734004014
11
0.8650928385987653
12
0.5867583008849087
13
0.15053155636913873
14
-0.13622024638714825
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "YAHOO_Feed aapl = new(20, \"AAPL\");\n", + "TSeries close = aapl.Close; // close will get data from history\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", + "SUB_Series macd = new(fast,slow); // macd is a SUBtraction: fast-slow\n", + "EMA_Series signal = new(macd,9); // signal is EMA of macd\n", + "SUB_Series histogram = new(macd, signal); // histogram is SUBtraction macd-signal\n", + "\n", + "histogram.v\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/x-csharp", + "name": "C#", + "pygments_lexer": "csharp", + "version": "9.0" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/docs/index.html b/docs/index.html index 07262eee..10426a54 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,25 +1,25 @@ - - - - - Document - - - - - - -
- - - - - - - - + + + + + Document + + + + + + +
+ + + + + + + + diff --git a/docs/ma-comparison.dib b/docs/ma-comparison.dib new file mode 100644 index 00000000..21dfd75a --- /dev/null +++ b/docs/ma-comparison.dib @@ -0,0 +1,244 @@ +#!csharp + +#r "nuget: Plotly.NET, 2.0.0-preview.18 " +#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.18 " +#r "nuget: QuanTAlib" + +using Plotly.NET; +using Plotly.NET.LayoutObjects; +using QuanTAlib; + +List x = new() {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96}; +List Spike = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +List Impulse = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; +List Triangle = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2}; +List Sawtooth = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +List Sine = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0.39,0.56,0.72,0.84,0.93,0.99,1,0.97,0.91,0.81,0.68,0.52,0.33,0.14,-0.06,-0.26,-0.44,-0.61,-0.76,-0.87,-0.95,-0.99,-1,-0.96,-0.88,-0.77,-0.63,-0.46,-0.28,-0.08,0.12,0.31,0.49,0.66,0.79,0.9,0.97,1,0.99,0.94,0.85,0.73,0.58,0.41,0.22,0.02,-0.17,-0.37,-0.54,-0.7,-0.83,-0.92,-0.98,-1,-0.98,-0.92,-0.82,-0.69,-0.54,-0.36,-0.17,0.03,0.23,0.42,0.59,0.74}; +List Chirp = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0.93,0.27,-0.59,-1,-0.71,0.05,0.75,1,0.67,0,-0.67,-0.99,-0.85,-0.34,0.31,0.81,1,0.82,0.35,-0.22,-0.71,-0.98,-0.95,-0.66,-0.2,0.31,0.72,0.96,0.98,0.78,0.43,-0.01,-0.43,-0.77,-0.96,-0.99,-0.85,-0.58,-0.23,0.16,0.51,0.79,0.95,1,0.92,0.73,0.47,0.15,-0.17,-0.47,-0.72,-0.9,-0.99,-0.99,-0.9,-0.74,-0.52,-0.26,0.01,0.28,0.53,0.73,0.88,0.97,1,0.97}; +List White = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,0.03,-0.4,-0.47,0.19,-0.4,-0.23,0.31,0.41,0.19,0.16,-0.5,-0.31,-0.21,0.25,0.18,-0.48,-0.1,0.38,0.29,-0.38,-0.08,-0.21,0.34,0.01,-0.46,0.28,-0.48,0.11,0.02,-0.37,0.19,-0.2,0.1,0.24,0.08,-0.22,-0.12,0.15,0.36,-0.43,-0.03,-0.32,0.45,-0.5,-0.04,-0.04,-0.08,-0.18,0.13,-0.33,-0.19,0.36,-0.39,0.2,-0.31,0.28,-0.13,-0.07,-0.29,0.37,0.03,-0.25,-0.06,-0.3,-0.08,-0.09}; +List Gauss = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,0,0.03,0.11,-0.1,-0.43,-0.08,0.36,-0.04,-0.04,-0.21,-0.3,0.26,0.2,0.28,0.2,0.27,-0.01,-0.1,-0.23,-0.13,-0.41,-0.23,-0.07,-0.21,0.32,-0.18,-0.48,0.3,0.46,-0.2,0.52,-0.81,-0.25,-0.21,-0.12,-0.18,0.18,0.52,0.29,0.44,0.18,-1.2,0.38,0.24,0.06,0.28,0.34,0.3,-0.13,0.19,-0.5,0.59,-0.36,0.22,-0.23,0.24,0.39,0.13,-0.33,-0.57,-0.23,0.49,-0.13,0.76,0.59,0.61}; +List B = new() {-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0.4,-0.4,0,-0.28,0.41,-0.54,0.65,-0.75,0.84,-0.91,0.96,-0.99,1,-0.99,0.96,-0.92,0.85,-0.77,0.67,-0.56,0.44,-0.3,0.17,-0.03,-0.11,0.25,-0.39,0.51,-0.63,0.73,-0.82,0.89,-0.95,0.98,-1,0.99,-0.97,0.93,-0.86,0.78,-0.69,0.58,-0.46,0.33,-0.19,0.05,0.09,-0.23,0.36,-0.49,0.61,-0.71,0.81,-0.88,0.94,-0.98,1,-1,0.98,-0.94,0.88,-0.8,0.71,-0.6,0.48,-0.35,0.22,-0.08,-0.06}; +List HF = new() {-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,-0.6,0.6,0,0.14,-0.76,-0.96,-0.28,0.66,0.99,0.41,-0.54,-1,-0.54,0.42,0.99,0.65,-0.29,-0.96,-0.75,0.15,0.91,0.84,-0.01,-0.85,-0.91,-0.13,0.76,0.96,0.27,-0.66,-0.99,-0.4,0.55,1,0.53,-0.43,-0.99,-0.64,0.3,0.96,0.75,-0.16,-0.92,-0.83,0.02,0.85,0.9,0.12,-0.77,-0.95,-0.26,0.67,0.99,0.4,-0.56,-1,-0.52,0.44,0.99,0.64,-0.3,-0.97,-0.74,0.17,0.92,0.83,-0.03,-0.86}; +List ImpulseHF = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,0.05,-0.25,-0.32,-0.09,0.22,0.33,0.14,-0.18,-0.33,-0.18,0.14,0.33,0.22,-0.1,-0.32,-0.25,0.05,0.3,0.28,0,-0.28,-0.3,-0.04,0.25,0.32,0.09,-0.22,-0.33,-0.13,0.18,0.33,0.18,0.86,0.67,0.79,1.1,1.32,1.25,0.95,0.69,0.72,1.01,1.28,1.3,1.04,0.74,0.68,0.91,1.22,1.33,1.13,0.81,0.67,0.83,1.15,1.33,1.21,0.9,0.68,0.75,1.06,1.31,1.28,0.99,0.71}; +List SawtoothHF = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,2.7,-0.8,-0.8,3.6,9.3,11.95,10.05,6.3,5,8.3,14.1,17.95,17.25,13.55,11.2,13.25,18.75,23.55,24.2,20.95,17.75,18.45,23.35,28.8,30.8,28.35,24.7,24.05,28,33.75,37,35.65,31.85,28.05,-3.2,1.5,4.8,3.75,-0.8,-4.6,-4.15,0.1,4.25,4.5,0.6,-3.85,-4.75,-1.3,3.35,4.95,2,-2.8,-5,-2.6,2.2,4.95,3.2,-1.5,-4.85,-3.7,0.85,4.6,4.15,-0.15,-4.3}; +List SineG = new() {-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0.2,-0.2,0,0,0.59,0.83,0.74,0.5,0.91,1.36,0.93,0.87,0.6,0.38,0.78,0.53,0.42,0.14,0.01,-0.45,-0.71,-0.99,-1,-1.36,-1.22,-1.07,-1.17,-0.56,-0.95,-1.11,-0.16,0.18,-0.28,0.64,-0.5,0.24,0.45,0.67,0.72,1.15,1.52,1.28,1.38,1.03,-0.47,0.96,0.65,0.28,0.3,0.17,-0.07,-0.67,-0.51,-1.33,-0.33,-1.34,-0.78,-1.21,-0.68,-0.43,-0.56,-0.87,-0.93,-0.4,0.52,0.1,1.18,1.18,1.35}; +List ChirpG = new() {0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,0,0.01,1.3,0.3,-0.48,-1.1,-1.14,-0.03,1.11,0.96,0.63,-0.21,-0.97,-0.73,-0.65,-0.06,0.51,1.08,0.99,0.72,0.12,-0.35,-1.12,-1.21,-1.02,-0.87,0.12,0.13,0.24,1.26,1.44,0.58,0.95,-0.82,-0.68,-0.98,-1.08,-1.17,-0.67,-0.06,0.06,0.6,0.69,-0.41,1.33,1.24,0.98,1.01,0.81,0.45,-0.3,-0.28,-1.22,-0.31,-1.35,-0.77,-1.13,-0.5,-0.13,-0.13,-0.32,-0.29,0.3,1.22,0.75,1.73,1.59,1.58}; +List Complex = new() {175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.1,175.6,175.44,176.27,176.04,176.99,175.49,175.68,174.34,176.4,174.05,174.4,174.2,176.16,175,177.72,174.33,176.96,174.62,174.76,170.9,171.12,171.05,170.01,169.24,172.64,171.96,175.72,174.16,175.81,177.3,178.38,176.75,177.19,175.55,178.49,176.52,178.45,178.04,178.25,177.8,176.97,172.94,174.92,173.98,172.29,171.19,172.54,172.11,175.32,175.63,176.65,173.8,176.04,172.74,175.24,171.84,171.54,172.17,171.85,172.38,170.78,173.49,173.69,171.71,174.38,173.99,174.83}; +List Market = new() {68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,68.75,68.25,67.75,67.75,72.75,74.75,72.25,71.25,71.75,72.75,77.75,76,76,76,74.75,75.5,74.75,73.75,74,74.75,72.25,72.5,72.25,74.5,74.75,75.75,75.75,75.75,74.25,73.75,74.75,72,71.75,72.5,72.25,71,72,71.75,71.75,73.25,72.5,73.75,74,76.75,75.75,75,75.75,74.5,74.25,73.5,71.75,70.5,69,70.5,70,68.75,67.25,68.5,70.75,70,70.5,68.25,68.25,68.25,63.75,64.25}; + +#!csharp + +TSeries data = new(); + +// change these two values - the period and the type of observed indicator +// currently available indicators are: DEMA_Series, EMA_Series, HEMA_Series, HMA_Series, JMA_Series, RMA_Series, SMA_Series, TEMA_Series, WMA_Series and ZLEMA_Series +int Period = 20; +HMA_Series indicator=new(source: data, period: Period); + +//On charts below, blue line is the data input, the green line is a JMA reference + +#!csharp + +var series = Spike; +ZLEMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Spike"); +chart + +#!csharp + +var series = Impulse; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Impulse"); +chart + +#!csharp + +var series = Triangle; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x, series, false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Triangle"); +chart + +#!csharp + +var series = Sawtooth; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Sawtooth"); +chart + +#!csharp + +var series = Sine; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Sine"); +chart + +#!csharp + +var series = Chirp; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Chirp"); +chart + +#!csharp + +var series = White; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("White"); +chart + +#!csharp + +var series = Gauss; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Gauss"); +chart + +#!csharp + +var series = B; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("B"); +chart + +#!csharp + +var series = HF; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("HF"); +chart + +#!csharp + +var series = ImpulseHF; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("ImpulseHF"); +chart + +#!csharp + +var series = SawtoothHF; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("SawtoothHF"); +chart + +#!csharp + +var series = SineG; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("SineG"); +chart + +#!csharp + +var series = ChirpG; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("ChirpG"); +chart + +#!csharp + +var series = Complex; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Complex"); +chart + +#!csharp + +var series = Market; +data = new(); +indicator=new(source: data, period: Period); +JMA_Series reference = new(source: data, period: Period); +for (int i=0; i(x,series,false,"data").WithLineStyle(Width: 1.0, Color: Color.fromString("blue")); +GenericChart.GenericChart ch2 = Chart2D.Chart.Line(x,indicator.v,false,"sig").WithLineStyle(Width: 2, Color: Color.fromString("red")); +GenericChart.GenericChart ch3 = Chart2D.Chart.Line(x,reference.v,false,"ref").WithLineStyle(Width: 1.5, Color: Color.fromString("green")); +var chart = Chart.Combine(new []{ch1,ch2,ch3}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle("Maket"); +chart diff --git a/docs/macd_example.ipynb b/docs/macd_example.ipynb new file mode 100644 index 00000000..04a4d6ff --- /dev/null +++ b/docs/macd_example.ipynb @@ -0,0 +1,190 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
Installed Packages
  • Plotly.NET, 2.0.0
  • Plotly.NET.Interactive, 2.0.0
  • QuanTAlib, 0.1.13
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "Loading extensions from `Plotly.NET.Interactive.dll`" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "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\"\n", + "#r \"nuget: Plotly.NET.Interactive, 2.0.0\"\n", + "#r \"nuget: QuanTAlib\"\n", + "\n", + "using Plotly.NET;\n", + "using Plotly.NET.LayoutObjects;\n", + "using QuanTAlib;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
380
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// defining the MACD model through clasess that connect to each other with Events\n", + "\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", + "SUB_Series macd = new(fast,slow); // macd is a SUBtraction of fast-slow\n", + "EMA_Series signal = new(macd,9); // signal is EMA of macd\n", + "SUB_Series histogram = new(macd, signal); // histogran is SUBtraction macd-signal\n", + "\n", + "slow.Count" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
indexvalue
0
99.6
1
100.93
2
100.36
3
96.83
4
95.39
5
96.34
6
97.6
7
98.7
8
100.11
9
101.38
10
101.09
11
100.31
12
97.19
13
96.13
14
93.34
15
91.46
16
91.65
17
91.63
18
90.39
19
91.69
(360 more)
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "tsla.Open.v" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "vscode": { + "languageId": "dotnet-interactive.csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\r\n", + "
\r\n", + "
\r\n", + "\r\n", + "\r\n", + " \r\n", + "
(tsla.Open.v, tsla.High.v, tsla.Low.v, tsla.Close.v, tsla.Open.t, \"candles\");\n", + "var ch1 = Chart2D.Chart.Line(macd.t,macd.v,false,\"macd\").WithLineStyle(Width: 2, Color: Color.fromString(\"red\"));\n", + "var ch2 = Chart2D.Chart.Line(signal.t,signal.v,false,\"signal\").WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", + "//GenericChart.GenericChart hist = Chart2D.Chart.Column(histogram.t,histogram.v).WithLineStyle(Width: 1.5, Color: Color.fromString(\"green\"));\n", + "\n", + "var chart = Chart.Combine(new []{candles,ch1,ch2}).WithSize(1200,400).WithMargin(Margin.init(1,1,60,1,1,false)).WithTitle(\"MACD using EMA\");\n", + "\n", + "chart" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/x-csharp", + "name": "C#", + "pygments_lexer": "csharp", + "version": "9.0" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +}