mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-19 11:08:05 +00:00
Auto stash before rebase of "origin/main"
This commit is contained in:
+125
-124
@@ -1,124 +1,125 @@
|
|||||||
namespace QuanTAlib;
|
namespace QuanTAlib;
|
||||||
using System;
|
using System;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
/* <summary>
|
/* <summary>
|
||||||
Alphavantage - Free API to collect quotes for stock, Forex and crypto. It requires a (free) API key
|
Alphavantage - Free API to collect quotes for stock, Forex and crypto. It requires a (free) API key
|
||||||
Get API key at https://www.alphavantage.co/support/#api-key
|
Get API key at https://www.alphavantage.co/support/#api-key
|
||||||
Parameters:
|
Parameters:
|
||||||
Symbol: stock ("AAPL"), crypto ("BTC") or forex pair (divided by dash: "USD-EUR")
|
Symbol: stock ("AAPL"), crypto ("BTC") or forex pair (divided by dash: "USD-EUR")
|
||||||
Extended: if true, return 2,000 rows. if false, return 100 rows
|
Extended: if true, return 2,000 rows. if false, return 100 rows
|
||||||
Interval: enum with options of Month, Week, Day, Hour, Min30, Min15, Min5, Min1
|
Interval: enum with options of Month, Week, Day, Hour, Min30, Min15, Min5, Min1
|
||||||
APIkey: unique Alphavantage API key
|
APIkey: unique Alphavantage API key
|
||||||
|
|
||||||
</summary> */
|
</summary> */
|
||||||
|
|
||||||
public class Alphavantage_Feed : TBars
|
public class Alphavantage_Feed : TBars
|
||||||
{
|
{
|
||||||
public enum Interval { Month, Week, Day, Hour, Min30, Min15, Min5, Min1}
|
public enum Interval { Month, Week, Day, Hour, Min30, Min15, Min5, Min1}
|
||||||
public Alphavantage_Feed(string Symbol = "IBM", bool Extended = false, Interval Interval = Interval.Day, string APIkey = "demo")
|
public Alphavantage_Feed(string Symbol = "IBM", bool Extended = false, Interval Interval = Interval.Day, string APIkey = "demo")
|
||||||
{
|
{
|
||||||
|
|
||||||
string outputsize = "compact";
|
string outputsize = "compact";
|
||||||
if (Extended) { outputsize = "full"; }
|
if (Extended) { outputsize = "full"; }
|
||||||
System.Net.Http.HttpClient client = new();
|
System.Net.Http.HttpClient client = new();
|
||||||
JsonElement json = new();
|
JsonElement json = new();
|
||||||
var tokens = Symbol.Split('-');
|
var tokens = Symbol.Split('-');
|
||||||
if (tokens.Length > 1)
|
if (tokens.Length > 1)
|
||||||
{
|
{
|
||||||
string req = "https://www.alphavantage.co/query?function=FX" + GetInterval(Interval) + "&from_symbol=" + tokens[0] + "&to_symbol=" + tokens[1] + "&outputsize=" + outputsize + "&apikey=" + APIkey;
|
string req = "https://www.alphavantage.co/query?function=FX" + GetInterval(Interval) + "&from_symbol=" + tokens[0] + "&to_symbol=" + tokens[1] + "&outputsize=" + outputsize + "&apikey=" + APIkey;
|
||||||
var msg = client.GetStringAsync(req).Result;
|
var msg = client.GetStringAsync(req).Result;
|
||||||
var jres = JsonSerializer.Deserialize<JsonDocument>(msg).RootElement;
|
var jres = JsonSerializer.Deserialize<JsonDocument>(msg).RootElement;
|
||||||
switch (Interval)
|
switch (Interval)
|
||||||
{
|
{
|
||||||
case Interval.Month: jres.TryGetProperty("Time Series FX (Monthly)", out json); break;
|
case Interval.Month: jres.TryGetProperty("Time Series FX (Monthly)", out json); break;
|
||||||
case Interval.Week: jres.TryGetProperty("Time Series FX (Weekly)", out json); break;
|
case Interval.Week: jres.TryGetProperty("Time Series FX (Weekly)", out json); break;
|
||||||
case Interval.Day: jres.TryGetProperty("Time Series FX (Daily)", out json); break;
|
case Interval.Day: jres.TryGetProperty("Time Series FX (Daily)", out json); break;
|
||||||
case Interval.Hour: jres.TryGetProperty("Time Series FX (60min)", out json); break;
|
case Interval.Hour: jres.TryGetProperty("Time Series FX (60min)", out json); break;
|
||||||
case Interval.Min30: jres.TryGetProperty("Time Series FX (30min)", out json); break;
|
case Interval.Min30: jres.TryGetProperty("Time Series FX (30min)", out json); break;
|
||||||
case Interval.Min15: jres.TryGetProperty("Time Series FX (15min)", out json); break;
|
case Interval.Min15: jres.TryGetProperty("Time Series FX (15min)", out json); break;
|
||||||
case Interval.Min5: jres.TryGetProperty("Time Series FX (5min)", out json); break;
|
case Interval.Min5: jres.TryGetProperty("Time Series FX (5min)", out json); break;
|
||||||
case Interval.Min1: jres.TryGetProperty("Time Series FX (1min)", out json); break;
|
case Interval.Min1: jres.TryGetProperty("Time Series FX (1min)", out json); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (json.ValueKind == JsonValueKind.Undefined)
|
if (json.ValueKind == JsonValueKind.Undefined)
|
||||||
{
|
{
|
||||||
string req = "https://www.alphavantage.co/query?function=TIME_SERIES" + GetInterval(Interval) + "&symbol=" + Symbol + "&outputsize=" + outputsize + "&apikey=" + APIkey;
|
string req = "https://www.alphavantage.co/query?function=TIME_SERIES" + GetInterval(Interval) + "&symbol=" + Symbol + "&outputsize=" + outputsize + "&apikey=" + APIkey;
|
||||||
var msg = client.GetStringAsync(req).Result;
|
var msg = client.GetStringAsync(req).Result;
|
||||||
var jres = JsonSerializer.Deserialize<JsonDocument>(msg).RootElement;
|
var jres = JsonSerializer.Deserialize<JsonDocument>(msg).RootElement;
|
||||||
switch (Interval)
|
switch (Interval)
|
||||||
{
|
{
|
||||||
case Interval.Month: jres.TryGetProperty("Monthly Time Series", out json); break;
|
case Interval.Month: jres.TryGetProperty("Monthly Time Series", out json); break;
|
||||||
case Interval.Week: jres.TryGetProperty("Weekly Time Series", out json); break;
|
case Interval.Week: jres.TryGetProperty("Weekly Time Series", out json); break;
|
||||||
case Interval.Day: jres.TryGetProperty("Time Series (Daily)", out json); break;
|
case Interval.Day: jres.TryGetProperty("Time Series (Daily)", out json); break;
|
||||||
case Interval.Hour: jres.TryGetProperty("Time Series (60min)", out json); break;
|
case Interval.Hour: jres.TryGetProperty("Time Series (60min)", out json); break;
|
||||||
case Interval.Min30: jres.TryGetProperty("Time Series (30min)", out json); break;
|
case Interval.Min30: jres.TryGetProperty("Time Series (30min)", out json); break;
|
||||||
case Interval.Min15: jres.TryGetProperty("Time Series (15min)", out json); break;
|
case Interval.Min15: jres.TryGetProperty("Time Series (15min)", out json); break;
|
||||||
case Interval.Min5: jres.TryGetProperty("Time Series (5min)", out json); break;
|
case Interval.Min5: jres.TryGetProperty("Time Series (5min)", out json); break;
|
||||||
case Interval.Min1: jres.TryGetProperty("Time Series (1min)", out json); break;
|
case Interval.Min1: jres.TryGetProperty("Time Series (1min)", out json); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (json.ValueKind == JsonValueKind.Undefined)
|
if (json.ValueKind == JsonValueKind.Undefined)
|
||||||
{
|
{
|
||||||
string req;
|
string req;
|
||||||
if ((int)Interval < 3) { req = "https://www.alphavantage.co/query?function=DIGITAL_CURRENCY" + GetInterval(Interval) + "&symbol=" + Symbol + "&market=USD&&outputsize=" + outputsize + "&apikey=" + APIkey; }
|
if ((int)Interval < 3) { req = "https://www.alphavantage.co/query?function=DIGITAL_CURRENCY" + GetInterval(Interval) + "&symbol=" + Symbol + "&market=USD&&outputsize=" + outputsize + "&apikey=" + APIkey; }
|
||||||
else { req = "https://www.alphavantage.co/query?function=CRYPTO" + GetInterval(Interval) + "&symbol=" + Symbol + "&market=USD&&outputsize=" + outputsize + "&apikey=" + APIkey; }
|
else { req = "https://www.alphavantage.co/query?function=CRYPTO" + GetInterval(Interval) + "&symbol=" + Symbol + "&market=USD&&outputsize=" + outputsize + "&apikey=" + APIkey; }
|
||||||
var msg = client.GetStringAsync(req).Result;
|
var msg = client.GetStringAsync(req).Result;
|
||||||
var jres = JsonSerializer.Deserialize<JsonDocument>(msg).RootElement;
|
var jres = JsonSerializer.Deserialize<JsonDocument>(msg).RootElement;
|
||||||
switch (Interval)
|
switch (Interval)
|
||||||
{
|
{
|
||||||
case Interval.Month: jres.TryGetProperty("Time Series (Digital Currency Monthly)", out json); break;
|
case Interval.Month: jres.TryGetProperty("Time Series (Digital Currency Monthly)", out json); break;
|
||||||
case Interval.Week: jres.TryGetProperty("Time Series (Digital Currency Weekly)", out json); break;
|
case Interval.Week: jres.TryGetProperty("Time Series (Digital Currency Weekly)", out json); break;
|
||||||
case Interval.Day: jres.TryGetProperty("Time Series (Digital Currency Daily)", out json); break;
|
case Interval.Day: jres.TryGetProperty("Time Series (Digital Currency Daily)", out json); break;
|
||||||
case Interval.Hour: jres.TryGetProperty("Time Series Crypto (60min)", out json); break;
|
case Interval.Hour: jres.TryGetProperty("Time Series Crypto (60min)", out json); break;
|
||||||
case Interval.Min30: jres.TryGetProperty("Time Series Crypto (30min)", out json); break;
|
case Interval.Min30: jres.TryGetProperty("Time Series Crypto (30min)", out json); break;
|
||||||
case Interval.Min15: jres.TryGetProperty("Time Series Crypto (15min)", out json); break;
|
case Interval.Min15: jres.TryGetProperty("Time Series Crypto (15min)", out json); break;
|
||||||
case Interval.Min5: jres.TryGetProperty("Time Series Crypto (5min)", out json); break;
|
case Interval.Min5: jres.TryGetProperty("Time Series Crypto (5min)", out json); break;
|
||||||
case Interval.Min1: jres.TryGetProperty("Time Series Crypto (1min)", out json); break;
|
case Interval.Min1: jres.TryGetProperty("Time Series Crypto (1min)", out json); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (json.ValueKind != JsonValueKind.Undefined)
|
if (json.ValueKind != JsonValueKind.Undefined)
|
||||||
{
|
{
|
||||||
foreach (var val in json.EnumerateObject()) { base.Add(GetOHLC(val)); }
|
foreach (var val in json.EnumerateObject()) { base.Add(GetOHLC(val)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private static (DateTime t, double o, double h, double l, double c, double v) GetOHLC(JsonProperty json)
|
private static (DateTime t, double o, double h, double l, double c, double v) GetOHLC(JsonProperty json)
|
||||||
{
|
{
|
||||||
double o, h, l, c, v;
|
double o, h, l, c, v;
|
||||||
o = h = l = c = v = 0;
|
o = h = l = c = v = 0;
|
||||||
DateTime date = Convert.ToDateTime(json.Name);
|
DateTime date = Convert.ToDateTime(json.Name);
|
||||||
foreach (var val in json.Value.EnumerateObject())
|
foreach (var val in json.Value.EnumerateObject())
|
||||||
{
|
{
|
||||||
switch (val.Name)
|
switch (val.Name)
|
||||||
{
|
{
|
||||||
case "1. open": o = Convert.ToDouble(val.Value.ToString()); break;
|
case "1. open": o = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "1b. open (USD)": o = Convert.ToDouble(val.Value.ToString()); break;
|
case "1b. open (USD)": o = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "2. high": h = Convert.ToDouble(val.Value.ToString()); break;
|
case "2. high": h = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "2b. high (USD)": h = Convert.ToDouble(val.Value.ToString()); break;
|
case "2b. high (USD)": h = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "3. low": l = Convert.ToDouble(val.Value.ToString()); break;
|
case "3. low": l = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "3b. low (USD)": l = Convert.ToDouble(val.Value.ToString()); break;
|
case "3b. low (USD)": l = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "4. close": c = Convert.ToDouble(val.Value.ToString()); break;
|
case "4. close": c = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "4b. close (USD)": c = Convert.ToDouble(val.Value.ToString()); break;
|
case "4b. close (USD)": c = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "5. adjusted close": c = Convert.ToDouble(val.Value.ToString()); break;
|
case "5. adjusted close": c = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "5. volume": v = Convert.ToDouble(val.Value.ToString()); break;
|
case "5. volume": v = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
case "6. volume": v = Convert.ToDouble(val.Value.ToString()); break;
|
case "6. volume": v = Convert.ToDouble(val.Value.ToString()); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (date, o, h, l, c, v);
|
return (date, o, h, l, c, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetInterval(Interval interval = Interval.Day) => interval switch
|
private static string GetInterval(Interval interval = Interval.Day) => interval switch
|
||||||
{
|
{
|
||||||
Interval.Month => "_MONTHLY",
|
Interval.Month => "_MONTHLY",
|
||||||
Interval.Week => "_WEEKLY",
|
Interval.Week => "_WEEKLY",
|
||||||
Interval.Day => "_DAILY",
|
Interval.Day => "_DAILY",
|
||||||
Interval.Hour => "_INTRADAY&interval=60min",
|
Interval.Hour => "_INTRADAY&interval=60min",
|
||||||
Interval.Min30 => "_INTRADAY&interval=30min",
|
Interval.Min30 => "_INTRADAY&interval=30min",
|
||||||
Interval.Min15 => "_INTRADAY&interval=15min",
|
Interval.Min15 => "_INTRADAY&interval=15min",
|
||||||
Interval.Min5 => "_INTRADAY&interval=5min",
|
Interval.Min5 => "_INTRADAY&interval=5min",
|
||||||
Interval.Min1 => "_INTRADAY&interval=1min",
|
Interval.Min1 => "_INTRADAY&interval=1min",
|
||||||
_ => "_DAILY"
|
_ => "_DAILY"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+59
-59
@@ -1,60 +1,60 @@
|
|||||||
namespace QuanTAlib;
|
namespace QuanTAlib;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
/* <summary>
|
/* <summary>
|
||||||
GBM - Geometric Brownian Motion is a random simulator of market movement, returning List<Quote>
|
GBM - Geometric Brownian Motion is a random simulator of market movement, returning List<Quote>
|
||||||
GBM can be used for testing indicators, validation and Monte Carlo simulations of strategies.
|
GBM can be used for testing indicators, validation and Monte Carlo simulations of strategies.
|
||||||
|
|
||||||
Sample usage:
|
Sample usage:
|
||||||
GBM-Random data = new(); // generates 1 year (252) list of bars
|
GBM-Random data = new(); // generates 1 year (252) list of bars
|
||||||
GBM-Random data = new(Bars: 1000); // generates 1,000 bars
|
GBM-Random data = new(Bars: 1000); // generates 1,000 bars
|
||||||
GBM-Random data = new(Bars: 252, Volatility: 0.05, Drift: 0.0005, Seed: 100.0)
|
GBM-Random data = new(Bars: 252, Volatility: 0.05, Drift: 0.0005, Seed: 100.0)
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
Bars: number of bars (quotes) requested
|
Bars: number of bars (quotes) requested
|
||||||
Volatility: how dymamic/volatile the series should be; default is 1
|
Volatility: how dymamic/volatile the series should be; default is 1
|
||||||
Drift: incremental drift due to annual interest rate; default is 5%
|
Drift: incremental drift due to annual interest rate; default is 5%
|
||||||
Seed: starting value of the random series; should not be 0
|
Seed: starting value of the random series; should not be 0
|
||||||
|
|
||||||
</summary> */
|
</summary> */
|
||||||
|
|
||||||
public class GBM_Feed : TBars
|
public class GBM_Feed : TBars
|
||||||
{
|
{
|
||||||
double seed;
|
double seed;
|
||||||
readonly double drift, volatility;
|
readonly double drift, volatility;
|
||||||
public GBM_Feed(int Bars = 252, double Volatility = 1.0, double Drift = 0.05, double Seed = 100.0) {
|
public GBM_Feed(int Bars = 252, double Volatility = 1.0, double Drift = 0.05, double Seed = 100.0) {
|
||||||
seed = Seed;
|
seed = Seed;
|
||||||
volatility = Volatility*0.01;
|
volatility = Volatility*0.01;
|
||||||
drift = Drift*0.01;
|
drift = Drift*0.01;
|
||||||
for (int i = 0; i <Bars; i++) {
|
for (int i = 0; i <Bars; i++) {
|
||||||
DateTime Timestamp = DateTime.Today.AddDays(i - Bars);
|
DateTime Timestamp = DateTime.Today.AddDays(i - Bars);
|
||||||
this.Add(Timestamp);
|
this.Add(Timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(DateTime timestamp, bool update = false) {
|
public void Add(DateTime timestamp, bool update = false) {
|
||||||
double Open = GBM_value(seed, volatility*volatility, drift);
|
double Open = GBM_value(seed, volatility*volatility, drift);
|
||||||
double Close = GBM_value(Open, volatility, drift);
|
double Close = GBM_value(Open, volatility, drift);
|
||||||
|
|
||||||
double OCMax = Math.Max(Open,Close);
|
double OCMax = Math.Max(Open,Close);
|
||||||
double High = (GBM_value(seed, volatility*0.5, 0));
|
double High = (GBM_value(seed, volatility*0.5, 0));
|
||||||
High = (High<OCMax)? 2*OCMax-High : High;
|
High = (High<OCMax)? 2*OCMax-High : High;
|
||||||
|
|
||||||
double OCMin = Math.Min(Open,Close);
|
double OCMin = Math.Min(Open,Close);
|
||||||
double Low = (GBM_value(seed, volatility*0.5, 0));
|
double Low = (GBM_value(seed, volatility*0.5, 0));
|
||||||
Low = (Low>OCMin)? 2*OCMin-Low : Low;
|
Low = (Low>OCMin)? 2*OCMin-Low : Low;
|
||||||
|
|
||||||
double Volume = GBM_value(seed*10, volatility*2, Drift:0);
|
double Volume = GBM_value(seed*10, volatility*2, Drift:0);
|
||||||
|
|
||||||
base.Add((timestamp, Open, High, Low, Close, Volume), update);
|
base.Add((timestamp, Open, High, Low, Close, Volume), update);
|
||||||
seed = Close;
|
seed = Close;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double GBM_value (double Seed, double Volatility, double Drift) {
|
private static double GBM_value (double Seed, double Volatility, double Drift) {
|
||||||
Random rnd = new((int)(DateTime.UtcNow.Ticks));
|
Random rnd = new((int)(DateTime.UtcNow.Ticks));
|
||||||
double U1 = 1.0-rnd.NextDouble();
|
double U1 = 1.0-rnd.NextDouble();
|
||||||
double U2 = 1.0-rnd.NextDouble();
|
double U2 = 1.0-rnd.NextDouble();
|
||||||
double Z = Math.Sqrt(-2.0 * Math.Log(U1)) * Math.Sin(2.0 * Math.PI * U2);
|
double Z = Math.Sqrt(-2.0 * Math.Log(U1)) * Math.Sin(2.0 * Math.PI * U2);
|
||||||
return Seed * Math.Exp( Drift - (Volatility*Volatility*0.5) + Volatility * Z);
|
return Seed * Math.Exp( Drift - (Volatility*Volatility*0.5) + Volatility * Z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,68 +1,68 @@
|
|||||||
namespace QuanTAlib;
|
namespace QuanTAlib;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
/* <summary>
|
/* <summary>
|
||||||
ALMA: Arnaud Legoux Moving Average
|
ALMA: Arnaud Legoux Moving Average
|
||||||
The ALMA moving average uses the curve of the Normal (Gauss) distribution, which
|
The ALMA moving average uses the curve of the Normal (Gauss) distribution, which
|
||||||
can be shifted from 0 to 1. This allows regulating the smoothness and high
|
can be shifted from 0 to 1. This allows regulating the smoothness and high
|
||||||
sensitivity of the indicator. Sigma is another parameter that is responsible for
|
sensitivity of the indicator. Sigma is another parameter that is responsible for
|
||||||
the shape of the curve coefficients. This moving average reduces lag of the data
|
the shape of the curve coefficients. This moving average reduces lag of the data
|
||||||
in conjunction with smoothing to reduce noise.
|
in conjunction with smoothing to reduce noise.
|
||||||
|
|
||||||
|
|
||||||
Sources:
|
Sources:
|
||||||
https://phemex.com/academy/what-is-arnaud-legoux-moving-averages
|
https://phemex.com/academy/what-is-arnaud-legoux-moving-averages
|
||||||
https://www.prorealcode.com/prorealtime-indicators/alma-arnaud-legoux-moving-average/
|
https://www.prorealcode.com/prorealtime-indicators/alma-arnaud-legoux-moving-average/
|
||||||
|
|
||||||
</summary> */
|
</summary> */
|
||||||
|
|
||||||
public class ALMA_Series : Single_TSeries_Indicator
|
public class ALMA_Series : Single_TSeries_Indicator
|
||||||
{
|
{
|
||||||
private readonly System.Collections.Generic.List<double> _buffer = new();
|
private readonly System.Collections.Generic.List<double> _buffer = new();
|
||||||
private readonly double[] _weight;
|
private readonly double[] _weight;
|
||||||
private double _norm;
|
private double _norm;
|
||||||
private readonly double _offset, _sigma;
|
private readonly double _offset, _sigma;
|
||||||
|
|
||||||
public ALMA_Series(TSeries source, int period, double offset = 0.85, double sigma = 6.0, bool useNaN = false)
|
public ALMA_Series(TSeries source, int period, double offset = 0.85, double sigma = 6.0, bool useNaN = false)
|
||||||
: base(source, period, useNaN)
|
: base(source, period, useNaN)
|
||||||
{
|
{
|
||||||
_offset = offset;
|
_offset = offset;
|
||||||
_sigma = sigma;
|
_sigma = sigma;
|
||||||
_weight = new double[period];
|
_weight = new double[period];
|
||||||
|
|
||||||
if (this._data.Count > 0) { base.Add(this._data); }
|
if (this._data.Count > 0) { base.Add(this._data); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Add((System.DateTime t, double v) TValue, bool update)
|
public override void Add((System.DateTime t, double v) TValue, bool update)
|
||||||
{
|
{
|
||||||
if (update) { this._buffer[this._buffer.Count - 1] = TValue.v; }
|
if (update) { this._buffer[this._buffer.Count - 1] = TValue.v; }
|
||||||
else { this._buffer.Add(TValue.v); }
|
else { this._buffer.Add(TValue.v); }
|
||||||
if (this._buffer.Count > this._p) { this._buffer.RemoveAt(0); }
|
if (this._buffer.Count > this._p) { this._buffer.RemoveAt(0); }
|
||||||
|
|
||||||
if (this._buffer.Count <= _p) { calc_weights(); }
|
if (this._buffer.Count <= _p) { calc_weights(); }
|
||||||
|
|
||||||
double _weightedSum = 0;
|
double _weightedSum = 0;
|
||||||
for (int i = 0; i < this._buffer.Count; i++) { _weightedSum += _weight[i] * _buffer[i]; }
|
for (int i = 0; i < this._buffer.Count; i++) { _weightedSum += _weight[i] * _buffer[i]; }
|
||||||
double _alma = _weightedSum / _norm;
|
double _alma = _weightedSum / _norm;
|
||||||
|
|
||||||
var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _alma);
|
var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _alma);
|
||||||
base.Add(ret, update);
|
base.Add(ret, update);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calc_weights()
|
private void calc_weights()
|
||||||
{
|
{
|
||||||
int _len = this._buffer.Count;
|
int _len = this._buffer.Count;
|
||||||
_norm = 0;
|
_norm = 0;
|
||||||
double _m = _offset * (_len - 1);
|
double _m = _offset * (_len - 1);
|
||||||
double _s = _len / _sigma;
|
double _s = _len / _sigma;
|
||||||
for (int i = 0; i < _len; i++)
|
for (int i = 0; i < _len; i++)
|
||||||
{
|
{
|
||||||
double _wt = Math.Exp(-((i - _m) * (i - _m)) / (2 * _s * _s));
|
double _wt = Math.Exp(-((i - _m) * (i - _m)) / (2 * _s * _s));
|
||||||
_weight[i] = _wt;
|
_weight[i] = _wt;
|
||||||
_norm += _wt;
|
_norm += _wt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
//class with customer record
|
||||||
|
public class customer
|
||||||
+71
-71
@@ -1,72 +1,72 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>0.1.14</Version>
|
<Version>0.1.14</Version>
|
||||||
<releaseNotes>
|
<releaseNotes>
|
||||||
</releaseNotes>
|
</releaseNotes>
|
||||||
<Title>QuanTAlib</Title>
|
<Title>QuanTAlib</Title>
|
||||||
<Product>Library of Technical Indicators for .NET</Product>
|
<Product>Library of Technical Indicators for .NET</Product>
|
||||||
<Description>Quantitative Technical Analysis library for both real-time (streaming) and historical data analysis</Description>
|
<Description>Quantitative Technical Analysis library for both real-time (streaming) and historical data analysis</Description>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<RepositoryUrl>https://github.com/mihakralj/QuanTAlib</RepositoryUrl>
|
<RepositoryUrl>https://github.com/mihakralj/QuanTAlib</RepositoryUrl>
|
||||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
<Authors>Miha Kralj</Authors>
|
<Authors>Miha Kralj</Authors>
|
||||||
<Copyright>Miha Kralj</Copyright>
|
<Copyright>Miha Kralj</Copyright>
|
||||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||||
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
|
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
|
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
|
||||||
<NeutralLanguage>en-US</NeutralLanguage>
|
<NeutralLanguage>en-US</NeutralLanguage>
|
||||||
<RootNamespace>QuanTAlib</RootNamespace>
|
<RootNamespace>QuanTAlib</RootNamespace>
|
||||||
<AssemblyName>QuanTAlib</AssemblyName>
|
<AssemblyName>QuanTAlib</AssemblyName>
|
||||||
<IsPublishable>True</IsPublishable>
|
<IsPublishable>True</IsPublishable>
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||||
<DebugType>embedded</DebugType>
|
<DebugType>embedded</DebugType>
|
||||||
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<PackageTags>
|
<PackageTags>
|
||||||
Indicators;Stock;Market;Technical;Analysis;Algorithmic;Trading;Trade;Trend;Momentum;Finance;Algorithm;Algo;
|
Indicators;Stock;Market;Technical;Analysis;Algorithmic;Trading;Trade;Trend;Momentum;Finance;Algorithm;Algo;
|
||||||
AlgoTrading;Financial;Strategy;Chart;Charting;Oscillator;Overlay;Equity;Bitcoin;Crypto;Cryptocurrency;Forex;
|
AlgoTrading;Financial;Strategy;Chart;Charting;Oscillator;Overlay;Equity;Bitcoin;Crypto;Cryptocurrency;Forex;
|
||||||
Quantitative;Historical;Quotes;
|
Quantitative;Historical;Quotes;
|
||||||
</PackageTags>
|
</PackageTags>
|
||||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
<PackageLicenseFile></PackageLicenseFile>
|
<PackageLicenseFile></PackageLicenseFile>
|
||||||
<SynchReleaseVersion>false</SynchReleaseVersion>
|
<SynchReleaseVersion>false</SynchReleaseVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>True</Optimize>
|
<Optimize>True</Optimize>
|
||||||
<WarningLevel>7</WarningLevel>
|
<WarningLevel>7</WarningLevel>
|
||||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||||
<PlatformTarget>anycpu</PlatformTarget>
|
<PlatformTarget>anycpu</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
<DebugType></DebugType>
|
<DebugType></DebugType>
|
||||||
<Optimize>True</Optimize>
|
<Optimize>True</Optimize>
|
||||||
<WarningLevel>7</WarningLevel>
|
<WarningLevel>7</WarningLevel>
|
||||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||||
<PlatformTarget>anycpu</PlatformTarget>
|
<PlatformTarget>anycpu</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PackageIcon>QuanTAlib2.png</PackageIcon>
|
<PackageIcon>QuanTAlib2.png</PackageIcon>
|
||||||
<PackageIconUrl>https://raw.githubusercontent.com/mihakralj/QuanTAlib/main/.github/QuanTAlib2.png</PackageIconUrl>
|
<PackageIconUrl>https://raw.githubusercontent.com/mihakralj/QuanTAlib/main/.github/QuanTAlib2.png</PackageIconUrl>
|
||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\Docs\readme.md">
|
<None Include="..\Docs\readme.md">
|
||||||
<Pack>True</Pack>
|
<Pack>True</Pack>
|
||||||
<PackagePath></PackagePath>
|
<PackagePath></PackagePath>
|
||||||
</None>
|
</None>
|
||||||
<None Include="..\.github\QuanTAlib2.png">
|
<None Include="..\.github\QuanTAlib2.png">
|
||||||
<Pack>True</Pack>
|
<Pack>True</Pack>
|
||||||
<Visible>False</Visible>
|
<Visible>False</Visible>
|
||||||
<PackagePath></PackagePath>
|
<PackagePath></PackagePath>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.0-preview.4.22229.4" />
|
<PackageReference Include="System.Text.Json" Version="7.0.0-preview.4.22229.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
|
|||||||
+190
-190
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user