Sonarcloud changes

This commit is contained in:
Miha
2022-04-19 23:29:04 -07:00
parent df9023b4d6
commit bbea1afb71
34 changed files with 110 additions and 1033 deletions
-201
View File
@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-114
View File
@@ -1,114 +0,0 @@
// ADD - adding TSeries+TSeries together, or TSeries+double, or double+TSeries
using System;
namespace QuantLib;
public class ADD_Series : TSeries
{
readonly TSeries _d1;
readonly TSeries _d2;
readonly double _dd;
readonly byte _type;
public ADD_Series(TSeries d1, TSeries d2)
{
this._d1 = d1;
this._d2 = d2;
this._dd = 0;
this._type = 1;
d1.Pub += this.Sub;
d2.Pub += this.Sub;
if (d1.Count > 0 && d2.Count > 0)
{
for (int i = 0; i < Math.Min(d1.Count, d2.Count); i++)
{
this.Add(d1[i], d2[i], false);
}
}
}
public ADD_Series(TSeries d1, double dd)
{
this._d1 = d1;
this._d2 = null;
this._dd = dd;
this._type = 2;
d1.Pub += this.Sub;
if (d1.Count > 0)
{
for (int i = 0; i < d1.Count; i++)
{
this.Add(d1[i], dd, false);
}
}
}
public ADD_Series(double dd, TSeries d1)
{
this._d1 = d1;
this._d2 = null;
this._dd = dd;
this._type = 3;
d1.Pub += this.Sub;
if (d1.Count > 0)
{
for (int i = 0; i < d1.Count; i++)
{
this.Add(d1[i], dd, false);
}
}
}
public void Add((System.DateTime t, double v) d1,
(System.DateTime t, double v) d2, bool update = false)
{
(System.DateTime t, double v) result =
((d1.t > d2.t) ? d1.t : d2.t, d1.v + d2.v);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add((System.DateTime t, double v) d1, double dd,
bool update = false)
{
(System.DateTime t, double v) result = (d1.t, d1.v + dd);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add(double dd, (System.DateTime t, double v) d1, bool update = false) => this.Add(d1, dd, update);
public void Add(bool update = false)
{
if (update || (this._d1.Count > 0 && this._d1.Count == this._d2.Count &&
this.Count != this._d1.Count))
{
if (this._type == 1)
{
this.Add(this._d1[this._d1.Count - 1], this._d2[this._d2.Count - 1],
update);
}
else if (this._type == 2)
{
this.Add(this._d1[this._d1.Count - 1], this._dd, update);
}
else
{
this.Add(this._dd, this._d1[this._d1.Count - 1], update);
}
}
}
public new void Sub(object source, TSeriesEventArgs e) => this.Add(e.update);
}
-42
View File
@@ -1,42 +0,0 @@
namespace QuantLib;
using System;
public abstract class Single_TSeries_Indicator : TSeries
{
protected readonly int _p;
protected readonly bool _NaN;
protected readonly TSeries _data;
// Default Constructor
protected Single_TSeries_Indicator(TSeries source, int period, bool useNaN)
{
this._data = source;
this._p = period;
this._NaN = useNaN;
this._data.Pub += this.Sub;
}
// overridable Add() method for the whole series (should be replaced with faster algo than default)
public virtual void Add(TSeries data)
{
for (int i = 0; i < data.Count; i++)
{
this.Add(data[i], false);
}
}
// overridable Add() method to add/update a single value at the end of the list
public virtual new void Add((System.DateTime t, double v) tuple, bool update) => base.Add(tuple, update);
// Add() without update parameter assumes this is an insert of new data (update=false)
public new void Add((System.DateTime t, double v) d) => this.Add(d, update: false);
// Add() without a tuple assumes add/update using the last item in the source as new data
public void Add(bool update) => this.Add(this._data[this._data.Count - 1], update);
// Add() without any parameters assumes this is an insert of new data using the last item in the source
public void Add() => this.Add(this._data[this._data.Count - 1], update: false);
// When event is triggered, call Add(bool update)
public new void Sub(object source, TSeriesEventArgs e) => this.Add(this._data[this._data.Count - 1], e.update);
}
-125
View File
@@ -1,125 +0,0 @@
// DIV - divide TSeries/TSeries , or TSeries/double, or double/TSeries
using System;
namespace QuantLib;
public class DIV_Series : TSeries
{
readonly TSeries _d1, _d2;
readonly double _dd;
readonly byte _type;
public DIV_Series(TSeries d1, TSeries d2)
{
this._d1 = d1;
this._d2 = d2;
this._type = 1;
d1.Pub += this.Sub;
d2.Pub += this.Sub;
if (d1.Count > 0 && d2.Count > 0)
{
for (int i = 0; i < Math.Min(d1.Count, d2.Count); i++)
{
this.Add(d1[i], d2[i], false);
}
}
}
public DIV_Series(TSeries d1, double dd)
{
this._d1 = d1;
this._d2 = d1;
this._dd = dd;
this._type = 2;
d1.Pub += this.Sub;
if (d1.Count > 0)
{
for (int i = 0; i < d1.Count; i++)
{
this.Add(d1[i], dd, false);
}
}
}
public DIV_Series(double dd, TSeries d1)
{
this._d1 = d1;
this._d2 = d1;
this._dd = dd;
this._type = 3;
d1.Pub += this.Sub;
if (d1.Count > 0)
{
for (int i = 0; i < d1.Count; i++)
{
this.Add(dd, d1[i], false);
}
}
}
public void Add((System.DateTime t, double v) d1,
(System.DateTime t, double v) d2, bool update = false)
{
(System.DateTime t, double v) result =
((d1.t > d2.t) ? d1.t : d2.t,
(d2.v > double.Epsilon) ? d1.v / d2.v : double.PositiveInfinity);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add((System.DateTime t, double v) d1, double dd,
bool update = false)
{
(System.DateTime t, double v) result =
(d1.t, (dd > double.Epsilon) ? d1.v / dd : double.PositiveInfinity);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add(double dd, (System.DateTime t, double v) d1,
bool update = false)
{
(System.DateTime t, double v) result =
(d1.t, (d1.v > double.Epsilon) ? dd / d1.v : double.PositiveInfinity);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add(bool update = false)
{
if (update || (this._d1.Count > 0 && this._d1.Count == this._d2.Count &&
this.Count != this._d1.Count))
{
if (this._type == 1)
{
this.Add(this._d1[this._d1.Count - 1], this._d2[this._d2.Count - 1],
update);
}
else if (this._type == 2)
{
this.Add(this._d1[this._d1.Count - 1], this._dd, update);
}
else
{
this.Add(this._dd, this._d1[this._d1.Count - 1], update);
}
}
}
public new void Sub(object source, TSeriesEventArgs e) { this.Add(e.update); }
}
+7 -10
View File
@@ -1,3 +1,4 @@
namespace QuanTAlib;
using System.Drawing;
using TradingPlatform.BusinessLayer;
@@ -6,7 +7,7 @@ public class WMAPE_chart : Indicator
#region Parameters
[InputParameter("Smoothing period", 0, 1, 999, 1, 1)]
private int Period = 10;
private readonly int Period = 10;
[InputParameter("Data source", 1, variants: new object[]{
"Open", 0,
@@ -20,7 +21,7 @@ public class WMAPE_chart : Indicator
"OHLC4", 8,
"Weighted (HLCC4)", 9
})]
private int DataSource = 8;
private readonly int DataSource = 8;
#endregion Parameters
@@ -40,17 +41,13 @@ public class WMAPE_chart : Indicator
protected override void OnInit()
{
this.ShortName = "WMAPE (" + QuantLib.TBars.SelectStr(this.DataSource) + ", " + this.Period + ")";
this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, useNaN: true);
this.ShortName = "WMAPE (" + QuanTAlib.TBars.SelectStr(this.DataSource) + ", " + this.Period + ")";
this.indicator = new(source: this.bars.Select(this.DataSource), period: this.Period, useNaN: true);
}
protected void OnNewData(bool update = false)
{
this.indicator.Add(update);
protected void OnNewData(bool update = false) => this.indicator.Add(update);
}
protected override void OnUpdate(UpdateArgs args)
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);
-117
View File
@@ -1,117 +0,0 @@
// MUL - multiply TSeries*TSeries together, or TSeries*double, or double*TSeries
using System;
namespace QuantLib;
public class MUL_Series : TSeries
{
readonly TSeries _d1, _d2;
readonly double _dd;
readonly byte _type;
public MUL_Series(TSeries d1, TSeries d2)
{
this._d1 = d1;
this._d2 = d2;
this._dd = 0;
this._type = 1;
d1.Pub += this.Sub;
d2.Pub += this.Sub;
if (d1.Count > 0 && d2.Count > 0)
{
for (int i = 0; i < Math.Min(d1.Count, d2.Count); i++)
{
this.Add(d1[i], d2[i], false);
}
}
}
public MUL_Series(TSeries d1, double dd)
{
this._d1 = d1;
this._d2 = d1;
this._dd = dd;
this._type = 2;
d1.Pub += this.Sub;
if (d1.Count > 0)
{
for (int i = 0; i < d1.Count; i++)
{
this.Add(d1[i], dd, false);
}
}
}
public MUL_Series(double dd, TSeries d1)
{
this._d1 = d1;
this._d2 = d1;
this._dd = dd;
this._type = 3;
d1.Pub += this.Sub;
if (d1.Count > 0)
{
for (int i = 0; i < d1.Count; i++)
{
this.Add(d1[i], dd, false);
}
}
}
public void Add((System.DateTime t, double v) d1,
(System.DateTime t, double v) d2, bool update = false)
{
(System.DateTime t, double v) result =
((d1.t > d2.t) ? d1.t : d2.t, d1.v * d2.v);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add((System.DateTime t, double v) d1, double dd,
bool update = false)
{
(System.DateTime t, double v) result = (d1.t, d1.v * dd);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add(double dd, (System.DateTime t, double v) d1,
bool update = false)
{
this.Add(d1, dd, update);
}
public void Add(bool update = false)
{
if (update || (this._d1.Count > 0 && this._d1.Count == this._d2.Count &&
this.Count != this._d1.Count))
{
if (this._type == 1)
{
this.Add(this._d1[this._d1.Count - 1], this._d2[this._d2.Count - 1],
update);
}
else if (this._type == 2)
{
this.Add(this._d1[this._d1.Count - 1], this._dd, update);
}
else
{
this.Add(this._dd, this._d1[this._d1.Count - 1], update);
}
}
}
public new void Sub(object source, TSeriesEventArgs e) { this.Add(e.update); }
}
-20
View File
@@ -1,20 +0,0 @@
using System;
using QuantLib;
public class RND_Feed : TBars
{
public RND_Feed(int days, double volatility = 0.05, double startvalue = 100.0)
{
Random rnd = new();
double c = startvalue;
for (int i = 0; i < days; 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 - days), o, h, l, c, v);
}
}
}
-125
View File
@@ -1,125 +0,0 @@
// SUB - subtracting TSeries-TSeries, or TSeries-double, or double-TSeries
using System;
namespace QuantLib;
public class SUB_Series : TSeries
{
readonly TSeries _d1, _d2;
readonly double _dd;
readonly byte _type;
public SUB_Series(TSeries d1, TSeries d2)
{
this._d1 = d1;
this._d2 = d2;
this._dd = 0;
this._type = 1;
d1.Pub += this.Sub;
d2.Pub += this.Sub;
if (d1.Count > 0 && d2.Count > 0)
{
for (int i = 0; i < Math.Min(d1.Count, d2.Count); i++)
{
this.Add(d1[i], d2[i], false);
}
}
}
public SUB_Series(TSeries d1, double dd)
{
this._d1 = d1;
this._d2 = d1;
this._dd = dd;
this._type = 2;
d1.Pub += this.Sub;
if (d1.Count > 0)
{
for (int i = 0; i < d1.Count; i++)
{
this.Add(d1[i], dd, false);
}
}
}
public SUB_Series(double dd, TSeries d1)
{
this._d1 = d1;
this._d2 = d1;
this._dd = dd;
this._type = 3;
d1.Pub += this.Sub;
if (d1.Count > 0)
{
for (int i = 0; i < d1.Count; i++)
{
this.Add(dd, d1[i], false);
}
}
}
public void Add((System.DateTime t, double v) d1,
(System.DateTime t, double v) d2, bool update = false)
{
(System.DateTime t, double v) result =
((d1.t > d2.t) ? d1.t : d2.t, d1.v - d2.v);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add((System.DateTime t, double v) d1, double dd,
bool update = false)
{
(System.DateTime t, double v) result = (d1.t, d1.v - dd);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add(double dd, (System.DateTime t, double v) d1,
bool update = false)
{
(System.DateTime t, double v) result = (d1.t, dd - d1.v);
if (update)
{
base[base.Count - 1] = result;
}
else
{
base.Add(result);
}
}
public void Add(bool update = false)
{
if (update || (this._d1.Count > 0 && this._d1.Count == this._d2.Count &&
this.Count != this._d1.Count))
{
if (this._type == 1)
{
this.Add(this._d1[this._d1.Count - 1], this._d2[this._d2.Count - 1],
update);
}
else if (this._type == 2)
{
this.Add(this._d1[this._d1.Count - 1], this._dd, update);
}
else
{
this.Add(this._dd, this._d1[this._d1.Count - 1], update);
}
}
}
public new void Sub(object source, TSeriesEventArgs e) { this.Add(e.update); }
}
-104
View File
@@ -1,104 +0,0 @@
namespace QuantLib;
using System;
public class TBars : System.Collections.Generic.List<(DateTime t, double o, double h, double l, double c, double v)>
{
private readonly TSeries _open = new();
private readonly TSeries _high = new();
private readonly TSeries _low = new();
private readonly TSeries _close = new();
private readonly TSeries _volume = new();
private readonly TSeries _hl2 = new();
private readonly TSeries _oc2 = new();
private readonly TSeries _ohl3 = new();
private readonly TSeries _hlc3 = new();
private readonly TSeries _ohlc4 = new();
private readonly TSeries _hlcc4 = new();
public TSeries Open => this._open;
public TSeries High => this._high;
public TSeries Low => this._low;
public TSeries Close => this._close;
public TSeries Volume => this._volume;
public TSeries HL2 => this._hl2;
public TSeries OC2 => this._oc2;
public TSeries OHL3 => this._ohl3;
public TSeries HLC3 => this._hlc3;
public TSeries OHLC4 => this._ohlc4;
public TSeries HLCC4 => this._hlcc4;
public TSeries Select(int source)
{
return source switch
{
0 => _open,
1 => _high,
2 => _low,
3 => _close,
4 => _hl2,
5 => _oc2,
6 => _ohl3,
7 => _hlc3,
8 => _ohlc4,
_ => _hlcc4,
};
}
public static string SelectStr(int source)
{
return source switch
{
0 => "Open",
1 => "High",
2 => "Low",
3 => "Close",
4 => "HL2",
5 => "OC2",
6 => "OHL3",
7 => "Typical",
8 => "Mean",
_ => "Weighted",
};
}
public void
Add((DateTime t, double o, double h, double l, double c, double v) i, bool update = false)
=> Add(i.t, i.o, i.h, i.l, i.c, i.v, update);
public void Add(DateTime t, decimal o, decimal h, decimal l, decimal c, decimal v, bool update = false)
=> Add(t, (double)o, (double)h, (double)l, (double)c, (double)v, update);
public void Add(DateTime t, double o, double h, double l, double c, double v, bool update = false)
{
if (update)
{
this[this.Count - 1] = (t, o, h, l, c, v);
_open[_open.Count - 1] = (t, o);
_high[_high.Count - 1] = (t, h);
_low[_low.Count - 1] = (t, l);
_close[_close.Count - 1] = (t, c);
_volume[_volume.Count - 1] = (t, v);
_hl2[_hl2.Count - 1] = (t, (h + l) * 0.5);
_oc2[_oc2.Count - 1] = (t, (o + c) * 0.5);
_ohl3[_ohl3.Count - 1] = (t, (o + h + l) * 0.333333333333333);
_hlc3[_hlc3.Count - 1] = (t, (h + l + c) * 0.333333333333333);
_ohlc4[_ohlc4.Count - 1] = (t, (o + h + l + c) * 0.25);
_hlcc4[_hlcc4.Count - 1] = (t, (h + l + c + c) * 0.25);
}
else
{
base.Add((t, o, h, l, c, v));
_open.Add((t, o));
_high.Add((t, h));
_low.Add((t, l));
_close.Add((t, c));
_volume.Add((t, v));
_hl2.Add((t, (h + l) * 0.5));
_oc2.Add((t, (o + c) * 0.5));
_ohl3.Add((t, (o + h + l) * 0.333333333333333));
_hlc3.Add((t, (h + l + c) * 0.333333333333333));
_ohlc4.Add((t, (o + h + l + c) * 0.25));
_hlcc4.Add((t, (h + l + c + c) * 0.25));
}
}
}
-72
View File
@@ -1,72 +0,0 @@
namespace QuantLib;
using System;
using System.Linq;
public class TSeries : System.Collections.Generic.List<(DateTime t, double v)>
{
// when asked for a (t,v) tuple, return the last (t,v) on the List
public static implicit operator (DateTime t, double v)(TSeries l) => l[l.Count - 1];
// when asked for a (double), return the value part of the last tuple on the list
public static implicit operator double(TSeries l) => l[l.Count - 1].v;
// when asked for a (DateTime), return the DateTime part of the last tuple on the list
public static implicit operator DateTime(TSeries l) => l[l.Count - 1].t;
public System.Collections.Generic.List<DateTime> t =>
this.Select(x => (DateTime)x.t).ToList();
public System.Collections.Generic.List<double> v =>
this.Select(x => (double)x.v).ToList();
public int Length => this.Count;
// add/update one (t,v) tuple to/at the end of the list
public void Add((DateTime t, double v) TValue, bool update = false)
{
if (update) { this[this.Count - 1] = TValue; }
else { base.Add(TValue); }
this.OnEvent(update);
}
public void Add(DateTime t, double v, bool update = false) => this.Add((t, v), update);
public void Add(double v, bool update = false) => this.Add((DateTime.Now, v), update);
// Broadcast handler - only to valid targets
protected virtual void OnEvent(bool update = false)
{
if (Pub != null && Pub.Target != this)
{
Pub(this, new TSeriesEventArgs { update = update });
}
}
// delegate used by event handler + event handler (Pub == publisher)
public delegate
void NewDataEventHandler(object source, TSeriesEventArgs args);
public event NewDataEventHandler Pub;
public void Sub(object source, TSeriesEventArgs e)
{
TSeries ss = (TSeries)source;
if (ss.Count > 0)
{
for (int i = 0; i < ss.Count; i++)
{
this.Add(ss[i]);
}
}
else
{
this.Add(ss[ss.Count - 1], e.update);
}
}
}
// EventArgs extension - carries the update field
public class TSeriesEventArgs : EventArgs
{
public bool update { get; set; }
}
+5 -5
View File
@@ -14,17 +14,17 @@ public class MAX_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((DateTime t, double v) d, bool update)
public override void Add((DateTime t, double v) TValue, bool update)
{
if (update) { this._buffer[this._buffer.Count - 1] = d.v; }
else { this._buffer.Add(d.v); }
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 _max = d.v;
double _max = TValue.v;
for (int i = 0; i < this._buffer.Count; i++)
{ _max = (this._buffer[i] > _max) ? this._buffer[i] : _max; }
var result = (d.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _max);
var result = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _max);
base.Add(result, update);
}
+5 -5
View File
@@ -14,17 +14,17 @@ public class MIN_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { this._buffer[this._buffer.Count - 1] = d.v; }
else { this._buffer.Add(d.v); }
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 _min = d.v;
double _min = TValue.v;
for (int i = 0; i < this._buffer.Count; i++)
{ _min = (this._buffer[i] < _min) ? this._buffer[i] : _min; }
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _min);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _min);
base.Add(result, update);
}
+7 -7
View File
@@ -24,15 +24,15 @@ public class TR_Series : Single_TBars_Indicator
if (this._bars.Count > 0) { base.Add(this._bars); }
}
public override void Add((DateTime t, double o, double h, double l, double c, double v) TValue, bool update = false)
public override void Add((DateTime t, double o, double h, double l, double c, double v) TBar, bool update)
{
if (_cm1 is double.NaN) { _cm1 = TValue.c; }
if (_cm1 is double.NaN) { _cm1 = TBar.c; }
double d1 = Math.Abs(TValue.h - TValue.l);
double d2 = Math.Abs(_cm1 - TValue.h);
double d3 = Math.Abs(_cm1 - TValue.l);
var ret = (TValue.t, (base.Count==0 && base._NaN) ? double.NaN : Math.Max(d1,Math.Max(d2,d3)) );
double d1 = Math.Abs(TBar.h - TBar.l);
double d2 = Math.Abs(_cm1 - TBar.h);
double d3 = Math.Abs(_cm1 - TBar.l);
var ret = (TBar.t, (base.Count==0 && base._NaN) ? double.NaN : Math.Max(d1,Math.Max(d2,d3)) );
base.Add(ret, update);
_cm1 = TValue.c;
_cm1 = TBar.c;
}
}
+3 -3
View File
@@ -26,17 +26,17 @@ public class ATR_Series : Single_TBars_Indicator
this._k = 1.0 / (double)(this._p);
this._k1m = 1.0 - this._k;
this._lastema = this._lastlastema = double.NaN;
if (_bars.Count > 0) { base.Add(_bars); }
if (this._bars.Count > 0) { base.Add(this._bars); }
}
public override void Add((DateTime t, double o, double h, double l, double c, double v) TBar, bool update = false)
public override void Add((DateTime t, double o, double h, double l, double c, double v) TBar, bool update)
{
if (update) {
this._lastema = this._lastlastema;
this._cm1 = this._lastcm1;
}
if (_cm1 is double.NaN) { _cm1 = TBar.c; }
if (this._cm1 is double.NaN) { this._cm1 = TBar.c; }
double d1 = Math.Abs(TBar.h - TBar.l);
double d2 = Math.Abs(_cm1 - TBar.h);
double d3 = Math.Abs(_cm1 - TBar.l);
+1 -1
View File
@@ -26,7 +26,7 @@ public class ATRP_Series : Single_TBars_Indicator
if (_bars.Count > 0) { base.Add(_bars); }
}
public override void Add((DateTime t, double o, double h, double l, double c, double v) TBar, bool update = false)
public override void Add((DateTime t, double o, double h, double l, double c, double v) TBar, bool update)
{
if (update) {
this._lastema = this._lastlastema;
+5 -5
View File
@@ -29,7 +29,7 @@ public class DEMA_Series : Single_TSeries_Indicator
if (_data.Count > 0) { base.Add(_data); }
}
public override void Add((DateTime t, double v) d, bool update = false)
public override void Add((DateTime t, double v) TValue, bool update)
{
if (update)
@@ -42,10 +42,10 @@ public class DEMA_Series : Single_TSeries_Indicator
if (this.Count < this._p)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
if (update) { _buffer[_buffer.Count - 1] = TValue.v; }
else
{
_buffer.Add(d.v);
_buffer.Add(TValue.v);
}
if (_buffer.Count > this._p) { _buffer.RemoveAt(0); }
@@ -57,7 +57,7 @@ public class DEMA_Series : Single_TSeries_Indicator
}
else
{
_ema1 = d.v * this._k + this._lastema1 * this._k1m;
_ema1 = TValue.v * this._k + this._lastema1 * this._k1m;
_ema2 = _ema1 * this._k + this._lastema2 * this._k1m;
}
@@ -67,7 +67,7 @@ public class DEMA_Series : Single_TSeries_Indicator
this._lastema1 = _ema1;
this._lastema2 = _ema2;
var ret = (d.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _dema);
var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _dema);
base.Add(ret, update);
}
}
+5 -5
View File
@@ -33,17 +33,17 @@ public class EMA_Series : Single_TSeries_Indicator
if (this._data.Count > 0) { base.Add(this._data); }
}
public override void Add((DateTime t, double v) d, bool update = false)
public override void Add((DateTime t, double v) TValue, bool update)
{
double _ema = 0;
if (update) { this._lastema = this._lastlastema; }
if (this.Count < this._p)
{
if (update) { this._buffer[this._buffer.Count - 1] = d.v; }
if (update) { this._buffer[this._buffer.Count - 1] = TValue.v; }
else
{
this._buffer.Add(d.v);
this._buffer.Add(TValue.v);
}
if (this._buffer.Count > this._p) { this._buffer.RemoveAt(0); }
@@ -52,13 +52,13 @@ public class EMA_Series : Single_TSeries_Indicator
}
else
{
_ema = d.v * this._k + this._lastema * this._k1m;
_ema = TValue.v * this._k + this._lastema * this._k1m;
}
this._lastlastema = this._lastema;
this._lastema = _ema;
var ret = (d.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _ema);
var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _ema);
base.Add(ret, update);
}
}
+6 -6
View File
@@ -31,7 +31,7 @@ public class HEMA_Series : Single_TSeries_Indicator
private double _lastema2, _lastlastema2;
private double _lastema3, _lastlastema3;
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update)
{
@@ -40,11 +40,11 @@ public class HEMA_Series : Single_TSeries_Indicator
this._lastema3 = this._lastlastema3;
}
double _ema1 = System.Double.IsNaN(this._lastema1)
? d.v
: d.v * this._k1 + this._lastema1 * (1 - this._k1);
? TValue.v
: TValue.v * this._k1 + this._lastema1 * (1 - this._k1);
double _ema2 = System.Double.IsNaN(this._lastema2)
? d.v
: d.v * this._k2 + this._lastema2 * (1 - this._k2);
? TValue.v
: TValue.v * this._k2 + this._lastema2 * (1 - this._k2);
double _rawhema = (2 * _ema1) - _ema2;
double _ema3 = System.Double.IsNaN(this._lastema3)
@@ -59,7 +59,7 @@ public class HEMA_Series : Single_TSeries_Indicator
this._lastema3 = _ema3;
(System.DateTime t, double v) result =
(d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ema3);
(TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ema3);
base.Add(result, update);
}
}
+5 -5
View File
@@ -32,17 +32,17 @@ public class RMA_Series : Single_TSeries_Indicator
if (_data.Count > 0) { base.Add(_data); }
}
public override void Add((DateTime t, double v) d, bool update = false)
public override void Add((DateTime t, double v) TValue, bool update)
{
double _ema = 0;
if (update) { this._lastema = this._lastlastema; }
if (this.Count < this._p)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
if (update) { _buffer[_buffer.Count - 1] = TValue.v; }
else
{
_buffer.Add(d.v);
_buffer.Add(TValue.v);
}
if (_buffer.Count > this._p) { _buffer.RemoveAt(0); }
@@ -51,13 +51,13 @@ public class RMA_Series : Single_TSeries_Indicator
}
else
{
_ema = d.v * _k + _lastema * _k1m;
_ema = TValue.v * _k + _lastema * _k1m;
}
this._lastlastema = this._lastema;
this._lastema = _ema;
var ret = (d.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _ema);
var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _ema);
base.Add(ret, update);
}
}
+4 -4
View File
@@ -24,17 +24,17 @@ public class SMA_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
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;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _sma);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _sma);
base.Add(result, update);
}
+5 -5
View File
@@ -31,7 +31,7 @@ public class TEMA_Series : Single_TSeries_Indicator
if (_data.Count > 0) { base.Add(_data); }
}
public override void Add((DateTime t, double v) d, bool update = false)
public override void Add((DateTime t, double v) TValue, bool update)
{
if (update)
@@ -45,10 +45,10 @@ public class TEMA_Series : Single_TSeries_Indicator
if (this.Count < this._p)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
if (update) { _buffer[_buffer.Count - 1] = TValue.v; }
else
{
_buffer.Add(d.v);
_buffer.Add(TValue.v);
}
if (_buffer.Count > this._p) { _buffer.RemoveAt(0); }
@@ -59,7 +59,7 @@ public class TEMA_Series : Single_TSeries_Indicator
}
else
{
_ema1 = d.v * this._k + this._lastema1 * this._k1m;
_ema1 = TValue.v * this._k + this._lastema1 * this._k1m;
_ema2 = _ema1 * this._k + this._lastema2 * this._k1m;
_ema3 = _ema2 * this._k + this._lastema3 * this._k1m;
}
@@ -73,7 +73,7 @@ public class TEMA_Series : Single_TSeries_Indicator
this._lastema2 = _ema2;
this._lastema3 = _ema3;
var ret = (d.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _tema);
var ret = (TValue.t, this.Count < this._p - 1 && this._NaN ? double.NaN : _tema);
base.Add(ret, update);
}
}
+4 -4
View File
@@ -22,17 +22,17 @@ public class WMA_Series : Single_TSeries_Indicator
private readonly System.Collections.Generic.List<double> _buffer = new();
private readonly System.Collections.Generic.List<double> _weights = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
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 _wma = 0;
for (int i = 0; i < _buffer.Count; i++) { _wma += _buffer[i] * this._weights[i]; }
_wma /= (this._buffer.Count * (this._buffer.Count + 1)) * 0.5;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _wma);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _wma);
base.Add(result, update);
}
+3 -3
View File
@@ -34,7 +34,7 @@ public class ZLEMA_Series : Single_TSeries_Indicator
if (base._data.Count > 0) { base.Add(base._data); }
}
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update)
{
@@ -42,14 +42,14 @@ public class ZLEMA_Series : Single_TSeries_Indicator
}
int _lag = (int)(0.5 * (_p - 1));
int _l = Math.Max(this._data.Count - _lag, 0);
double _lagdata = 1 * d.v - this._data[_l].v;
double _lagdata = 1 * TValue.v - this._data[_l].v;
double _ema = System.Double.IsNaN(this._lastema) ? _lagdata : _lagdata * this._k + this._lastema * this._k1m;
this._lastlastema = this._lastema;
this._lastema = _ema;
(System.DateTime t, double v) result =
(d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ema);
(TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ema);
base.Add(result, update);
}
+4 -4
View File
@@ -33,10 +33,10 @@ public class KURT_Series : Single_TSeries_Indicator
protected double _logbase = 2.0;
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { this._buffer[this._buffer.Count - 1] = d.v; }
else { this._buffer.Add(d.v); }
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 _n = this._buffer.Count;
@@ -56,7 +56,7 @@ public class KURT_Series : Single_TSeries_Indicator
double _Vx = _s2 / (_n - 1);
double _kurt = (_n > 3) ? (((_n * (_n + 1)) / ((_n - 1) * (_n - 2) * (_n - 3))) * (_s4 / (_Vx * _Vx)) - (3 * ((_n - 1) * (_n - 1) / ((_n - 2) * (_n - 3))))) : Double.NaN;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? Double.NaN : _kurt);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? Double.NaN : _kurt);
base.Add(result, update);
}
}
+4 -4
View File
@@ -22,10 +22,10 @@ public class MAD_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { this._buffer[this._buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
if (update) { this._buffer[this._buffer.Count - 1] = TValue.v; }
else { _buffer.Add(TValue.v); }
if (_buffer.Count > this._p && this._p != 0) { _buffer.RemoveAt(0); }
double _sma = 0;
@@ -36,7 +36,7 @@ public class MAD_Series : Single_TSeries_Indicator
for (int i = 0; i < _buffer.Count; i++) { _mad += Math.Abs(_buffer[i] - _sma); }
_mad /= this._buffer.Count;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _mad);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _mad);
base.Add(result, update);
}
}
+4 -4
View File
@@ -25,10 +25,10 @@ public class MAPE_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
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;
@@ -39,7 +39,7 @@ public class MAPE_Series : Single_TSeries_Indicator
for (int i = 0; i < _buffer.Count; i++) { _mape += (_buffer[i] != 0) ? Math.Abs(_buffer[i] - _sma) / Math.Abs(_buffer[i]) : double.PositiveInfinity; }
_mape /= this._buffer.Count;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _mape);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _mape);
base.Add(result, update);
}
}
+4 -4
View File
@@ -28,10 +28,10 @@ public class MED_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { this._buffer[this._buffer.Count - 1] = d.v; }
else { this._buffer.Add(d.v); }
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); }
System.Collections.Generic.List<double> _s = new(this._buffer);
@@ -40,7 +40,7 @@ public class MED_Series : Single_TSeries_Indicator
int _p2 = Math.Max(0, _s.Count / 2 - 1);
double _med = (_s.Count % 2 != 0) ? _s[_p1] : (_s[_p1] + _s[_p2]) / 2;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _med);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _med);
base.Add(result, update);
}
+4 -4
View File
@@ -18,10 +18,10 @@ public class MSE_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
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;
@@ -32,7 +32,7 @@ public class MSE_Series : Single_TSeries_Indicator
for (int i = 0; i < _buffer.Count; i++) { _mse += (_buffer[i] - _sma) * (_buffer[i] - _sma); }
_mse /= this._buffer.Count;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _mse);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _mse);
base.Add(result, update);
}
}
+4 -4
View File
@@ -23,10 +23,10 @@ public class PSDEV_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
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;
@@ -38,7 +38,7 @@ public class PSDEV_Series : Single_TSeries_Indicator
_pvar /= this._buffer.Count;
double _psdev = Math.Sqrt(_pvar);
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _psdev);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _psdev);
base.Add(result, update);
}
}
+4 -4
View File
@@ -23,10 +23,10 @@ public class PVAR_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
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;
@@ -37,7 +37,7 @@ public class PVAR_Series : Single_TSeries_Indicator
for (int i = 0; i < _buffer.Count; i++) { _pvar += (_buffer[i] - _sma) * (_buffer[i] - _sma); }
_pvar /= this._buffer.Count;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _pvar);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _pvar);
base.Add(result, update);
}
}
+4 -4
View File
@@ -23,10 +23,10 @@ public class SDEV_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { this._buffer[this._buffer.Count - 1] = d.v; }
else { this._buffer.Add(d.v); }
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;
@@ -38,7 +38,7 @@ public class SDEV_Series : Single_TSeries_Indicator
_svar /= (this._buffer.Count > 1) ? this._buffer.Count - 1 : 1; // Bessel's correction
double _ssdev = Math.Sqrt(_svar);
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ssdev);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ssdev);
base.Add(result, update);
}
}
+4 -4
View File
@@ -18,10 +18,10 @@ public class SMAPE_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
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;
@@ -32,7 +32,7 @@ public class SMAPE_Series : Single_TSeries_Indicator
for (int i = 0; i < _buffer.Count; i++) { _smape += Math.Abs(_buffer[i] - _sma) / (Math.Abs(_buffer[i]) + Math.Abs(_sma)); }
_smape /= this._buffer.Count;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _smape);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _smape);
base.Add(result, update);
}
}
+4 -4
View File
@@ -23,10 +23,10 @@ public class VAR_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { this._buffer[this._buffer.Count - 1] = d.v; }
else { this._buffer.Add(d.v); }
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;
@@ -37,7 +37,7 @@ public class VAR_Series : Single_TSeries_Indicator
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
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _svar);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _svar);
base.Add(result, update);
}
}
+5 -5
View File
@@ -1,4 +1,4 @@
namespace QuanTAlib;
namespace QuanTAlib;
using System;
/* <summary>
@@ -18,10 +18,10 @@ public class WMAPE_Series : Single_TSeries_Indicator
}
private readonly System.Collections.Generic.List<double> _buffer = new();
public override void Add((System.DateTime t, double v) d, bool update)
public override void Add((System.DateTime t, double v) TValue, bool update)
{
if (update) { _buffer[_buffer.Count - 1] = d.v; }
else { _buffer.Add(d.v); }
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;
@@ -37,7 +37,7 @@ public class WMAPE_Series : Single_TSeries_Indicator
}
_wmape /= _div;
var result = (d.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _wmape);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _wmape);
base.Add(result, update);
}
}