Revert "for dev branch"

This reverts commit 32615af18b.
This commit is contained in:
Miha Kralj
2022-11-06 17:23:33 -08:00
parent 28025fbdd3
commit 09a014f6ed
9 changed files with 77 additions and 68 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ public class PSDEV_chart : Indicator
private TBars bars; private TBars bars;
///////dotnet ///////dotnet
private PSDEV_Series indicator; private SDEV_Series indicator;
/////// ///////
public PSDEV_chart() public PSDEV_chart()
+1 -1
View File
@@ -19,7 +19,7 @@ public class SDEV_chart : Indicator
private TBars bars; private TBars bars;
///////dotnet ///////dotnet
private SDEV_Series indicator; private SSDEV_Series indicator;
/////// ///////
public SDEV_chart() public SDEV_chart()
+1 -1
View File
@@ -113,7 +113,7 @@ public class Alphavantage_Feed : TBars
{ {
Interval.Month => "_MONTHLY", Interval.Month => "_MONTHLY",
Interval.Week => "_WEEKLY", Interval.Week => "_WEEKLY",
Interval.Day => "_DAILY", Interval.Day => "_DAILY_ADJUSTED",
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",
-44
View File
@@ -1,44 +0,0 @@
namespace QuanTAlib;
using System;
/* <summary>
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.
</summary> */
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<double> _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);
}
}
+16 -16
View File
@@ -2,17 +2,17 @@
using System; using System;
/* <summary> /* <summary>
SDEV: (Corrected) Sample Standard Deviation SDEV: Population Standard Deviation
Sample Standard Deviaton uses Bessel's correction to correct the bias in the variance. Population Standard Deviation is the square root of the biased variance, also knons as
Uncorrected Sample Standard Deviation
Sources: Sources:
https://en.wikipedia.org/wiki/Standard_deviation#Corrected_sample_standard_deviation https://en.wikipedia.org/wiki/Standard_deviation#Uncorrected_sample_standard_deviation
Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
Remark: Remark:
SSDEV (Sample Standard Deviation) is also known as a unbiased/corrected Standard Deviation. SDEV (Population Standard Deviation) is also known as a biased/uncorrected Standard Deviation.
For a population/biased/uncorrected Standard Deviation, use PSDEV instead For unbiased version that uses Bessel's correction, use SDEV instead.
</summary> */ </summary> */
public class SDEV_Series : Single_TSeries_Indicator 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) public override void Add((System.DateTime t, double v) TValue, bool update)
{ {
if (update) { this._buffer[this._buffer.Count - 1] = TValue.v; } if (update) { _buffer[_buffer.Count - 1] = TValue.v; }
else { this._buffer.Add(TValue.v); } else { _buffer.Add(TValue.v); }
if (this._buffer.Count > this._p && this._p != 0) { this._buffer.RemoveAt(0); } if (_buffer.Count > this._p && this._p != 0) { _buffer.RemoveAt(0); }
double _sma = 0; double _sma = 0;
for (int i = 0; i < this._buffer.Count; i++) { _sma += this._buffer[i]; } for (int i = 0; i < _buffer.Count; i++) { _sma += _buffer[i]; }
_sma /= this._buffer.Count; _sma /= this._buffer.Count;
double _svar = 0; double _pvar = 0;
for (int i = 0; i < this._buffer.Count; i++) { _svar += (this._buffer[i] - _sma) * (this._buffer[i] - _sma); } for (int i = 0; i < _buffer.Count; i++) { _pvar += (_buffer[i] - _sma) * (_buffer[i] - _sma); }
_svar /= (this._buffer.Count > 1) ? this._buffer.Count - 1 : 1; // Bessel's correction _pvar /= this._buffer.Count;
double _ssdev = Math.Sqrt(_svar); double _psdev = Math.Sqrt(_pvar);
var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _ssdev); var result = (TValue.t, (this.Count < this._p - 1 && this._NaN) ? double.NaN : _psdev);
base.Add(result, update); base.Add(result, update);
} }
} }
+44
View File
@@ -0,0 +1,44 @@
namespace QuanTAlib;
using System;
/* <summary>
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 PSDEV instead
</summary> */
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<double> _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);
}
}
+2 -2
View File
@@ -9,7 +9,7 @@ public class PSDEV_Test
public void Add_Test() public void Add_Test()
{ {
TSeries a = new() { 0, 1, 2, 3, 4, 5 }; TSeries a = new() { 0, 1, 2, 3, 4, 5 };
PSDEV_Series c = new(a, 3); SDEV_Series c = new(a, 3);
Assert.Equal(6, c.Count); Assert.Equal(6, c.Count);
a.Add(5); a.Add(5);
Assert.Equal(a.Count, c.Count); Assert.Equal(a.Count, c.Count);
@@ -21,7 +21,7 @@ public class PSDEV_Test
public void Edge_Test() public void Edge_Test()
{ {
TSeries a = new() { double.NaN, double.Epsilon, double.PositiveInfinity, double.MaxValue }; TSeries a = new() { double.NaN, double.Epsilon, double.PositiveInfinity, double.MaxValue };
PSDEV_Series c = new(a, 3); SDEV_Series c = new(a, 3);
Assert.Equal(a.Count, c.Count); Assert.Equal(a.Count, c.Count);
a.Add(double.NaN); a.Add(double.NaN);
Assert.Equal(a.Count, c.Count); Assert.Equal(a.Count, c.Count);
+2 -2
View File
@@ -9,7 +9,7 @@ public class SDEV_Test
public void Add_Test() public void Add_Test()
{ {
TSeries a = new() { 0, 1, 2, 3, 4, 5 }; TSeries a = new() { 0, 1, 2, 3, 4, 5 };
SDEV_Series c = new(a, 3); SSDEV_Series c = new(a, 3);
Assert.Equal(6, c.Count); Assert.Equal(6, c.Count);
a.Add(5); a.Add(5);
Assert.Equal(a.Count, c.Count); Assert.Equal(a.Count, c.Count);
@@ -21,7 +21,7 @@ public class SDEV_Test
public void Edge_Test() public void Edge_Test()
{ {
TSeries a = new() { double.NaN, double.Epsilon, double.PositiveInfinity, double.MaxValue }; TSeries a = new() { double.NaN, double.Epsilon, double.PositiveInfinity, double.MaxValue };
SDEV_Series c = new(a, 3); SSDEV_Series c = new(a, 3);
Assert.Equal(a.Count, c.Count); Assert.Equal(a.Count, c.Count);
a.Add(double.NaN); a.Add(double.NaN);
Assert.Equal(a.Count, c.Count); Assert.Equal(a.Count, c.Count);
+10 -1
View File
@@ -28,7 +28,16 @@ public class TA_LIB
this.involume = this.bars.Volume.v.ToArray(); this.involume = this.bars.Volume.v.ToArray();
} }
///////////////////////////////////////// /////////////////////////////////////////
[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));
}
[Fact] [Fact]
public void SMA() public void SMA()