mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-14 00:28:05 +00:00
54 KiB
54 KiB
In [ ]:
// This is .NET Interactive Notebook. It can run in VS.Code with .NET interactive extension installed
#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;Installed Packages
- Plotly.NET, 2.0.0-preview.18
- Plotly.NET.Interactive, 2.0.0-preview.18
- QuantLib, 1.0.8
In [ ]:
// defining the MACD model through clasess that connect to each other with Events
YAHOO_Feed tsla = new(380, "TSLA");
TSeries close = tsla.Close; // close will get data from YAHOO tsla feed
EMA_Series slow = new(close,26); // slow gets data from slow through pub-sub eventing
EMA_Series fast = new(close,12); // fast gets data from slow (via eventing)
SUB_Series macd = new(fast,slow); // macd is a SUBtraction of fast-slow
EMA_Series signal = new(macd,9); // signal is EMA of macd
SUB_Series histogram = new(macd, signal); // histogran is SUBtraction macd-signal
slow.Count265
In [ ]:
//this is just a visualization of MACD using the (preview of) Plotly.NET
var candles = Chart2D.Chart.Candlestick<double, double, double, double, DateTime, string>(tsla.Open.v, tsla.High.v, tsla.Low.v, tsla.Close.v, tsla.Open.t, "candles");
var ch1 = Chart2D.Chart.Line<DateTime,double,bool>(macd.t,macd.v,false,"macd").WithLineStyle(Width: 2, Color: Color.fromString("red"));
var ch2 = Chart2D.Chart.Line<DateTime,double,bool>(signal.t,signal.v,false,"signal").WithLineStyle(Width: 1.5, Color: Color.fromString("green"));
//GenericChart.GenericChart hist = Chart2D.Chart.Column<DateTime,double,string,bool,bool>(histogram.t,histogram.v).WithLineStyle(Width: 1.5, Color: Color.fromString("green"));
var chart = Chart.Combine(new []{candles,ch1,ch2}).WithSize(1200,400).WithMargin(Margin.init<int, int, int, int, int, bool>(1,1,60,1,1,false)).WithTitle("MACD using EMA");
chart