mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-14 00:28:05 +00:00
Add new EQUITY_Series and updates to docs, Calculations, Indicators, Strategies, Tests, and .github/workflows
15 KiB
15 KiB
In [1]:
#r "nuget:QuanTAlib;"
using QuanTAlib;
Yahoo_Feed aapl = new("AAPL", 10);
TSeries data = aapl.Close;
SMA_Series sma = new(source: data, period: 5, useNaN: false);
EMA_Series ema = new(sma, period: 5); // by default, indicators expose all data, no NaN values
WMA_Series wma = new(ema, 5, useNaN: true); // for the final calculation we can hide early data with NaNs
Console.Write($"index\t data\t\t sma(data)\t ema(sma(data))\t wma(ema(sma(data)))\n");
for (int i=0; i<aapl.Count; i++)
Console.Write($"{i}\t {data[i].t:yyyy-MM-dd}\t {sma[i].v:f2}\t\t {ema[i].v:f2}\t\t {wma[i].v:f2}\n");index data sma(data) ema(sma(data)) wma(ema(sma(data))) 0 2023-03-27 158.28 158.28 NaN 1 2023-03-28 157.97 158.12 NaN 2 2023-03-29 158.90 158.38 NaN 3 2023-03-30 159.77 158.73 NaN 4 2023-03-31 160.79 159.14 158.69 5 2023-04-03 162.37 160.22 159.25 6 2023-04-04 163.97 161.47 160.10 7 2023-04-05 164.56 162.50 161.07 8 2023-04-06 165.02 163.34 162.04
In [2]:
var item1 = (DateTime.Today, 105.3); // (DateTime, Value) tuple
double item2 = 293.1; // a simple double
TSeries data = new();
data.Add(item1); // adding tuple variable
data.Add(item2); // QuanTAlib stamps the (double) with current time
data.Add(0); // directly adding a number (stamped with current time)
data.Add((DateTime.Now.AddDays(-3), 10)); // adding a tuple with timestamp 3 days ago
data| index | value | ||||
|---|---|---|---|---|---|
| 0 |
|
| Item1 | 2023-04-07 00:00:00Z |
| Item2 | 105.3 |
(4/7/2023 2:34:48 PM, 293.1)
| Item1 | 2023-04-07 14:34:48Z |
| Item2 | 293.1 |
(4/7/2023 2:34:48 PM, 0)
| Item1 | 2023-04-07 14:34:48Z |
| Item2 | 0 |
(4/4/2023 2:34:48 PM, 10)
| Item1 | 2023-04-04 14:34:48Z |
| Item2 | 10 |
In [3]:
data.v[ 105.3, 293.1, 0, 10 ]
In [4]:
bool IsTheSame = data.Last().v == data[^1].v;
double lastvalue = data;
lastvalue10
In [5]:
TSeries t1 = new() {0,1,2,3,4,5,6,7,8,9}; // t1 is loaded with data and activated as a publisher
EMA_Series t2 = new(t1, 3); // t2 will auto-load all history of t1 and wait for events from t1
ADD_Series t3 = new(t1, t2); // t3 is an ADDition of t1 and t2 - will also load history and wait for t2 events
DIV_Series t4 = new(1, t3); // t4 is calculating 1/t3 - and waiting for t3 events
TSeries t5 = new(); // a wild indicator appeared! And it is empty!
t4.Pub += t5.Sub; // let us add a manual subscription to events coming from t4 - t5 is now listening to t4
t1.Add(0); // we add one new value to t1 - and trigger the full cascade of calculation! t5 is now full!
t5.v[ Infinity, 0.6666666666666666, 0.3333333333333333, 0.2, 0.14285714285714285, 0.1111111111111111, 0.09090909090909091, 0.07692307692307693, 0.06666666666666667, 0.058823529411764705, 0.25 ]
In [6]:
Yahoo_Feed aapl = new("AAPL", 100);
TSeries close = aapl.Close; // close will get data from history
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: fast-slow
EMA_Series signal = new(macd,9); // signal is EMA of macd
SUB_Series histogram = new(macd, signal); // histogram is SUBtraction macd-signal
histogram.v
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.000974358974349343, -0.03456027049873228, -0.13792617985566447, -0.4729486712049916, -0.825402881197467, -0.8902360596814031, -0.9360607784903126, -0.7333381872239422 ... (79 more) ]