This commit is contained in:
Miha Kralj
2024-09-30 08:55:50 -07:00
23 changed files with 32 additions and 387 deletions
+1 -8
View File
@@ -6,11 +6,6 @@ namespace QuanTAlib;
/// The weights are decreasing over the period with p^2 decay, and the most recent data has the heaviest weight.
/// </summary>
/// <remarks>
/// Smoothness: ★★★★★ (5/5)
/// Sensitivity: ★★★☆☆ (3/5)
/// Overshooting: ★★★★☆ (4/5)
/// Lag: ★★☆☆☆ (2/5)
///
/// The DWMA is calculated by applying two WMAs in sequence:
/// 1. An inner WMA is applied to the input data.
/// 2. An outer WMA is then applied to the result of the inner WMA.
@@ -28,7 +23,6 @@ namespace QuanTAlib;
public class Dwma : AbstractBase
{
private readonly int _period;
private readonly Wma _innerWma;
private readonly Wma _outerWma;
@@ -38,11 +32,10 @@ public class Dwma : AbstractBase
{
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_period = period;
_innerWma = new Wma(period);
_outerWma = new Wma(period);
Name = "Wma";
WarmupPeriod = 2 * _period - 1;
WarmupPeriod = 2 * period - 1;
Init();
}
+1 -3
View File
@@ -2,7 +2,6 @@ namespace QuanTAlib;
public class Fwma : AbstractBase
{
private readonly int _period;
private readonly Convolution _convolution;
public Fwma(int period)
@@ -11,8 +10,7 @@ public class Fwma : AbstractBase
{
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_period = period;
_convolution = new Convolution(GenerateKernel(_period));
_convolution = new Convolution(GenerateKernel(period));
Name = "Fwma";
WarmupPeriod = period;
Init();
+1 -3
View File
@@ -2,7 +2,6 @@ namespace QuanTAlib;
public class Gma : AbstractBase
{
private readonly int _period;
private readonly Convolution _convolution;
public Gma(int period)
@@ -11,8 +10,7 @@ public class Gma : AbstractBase
{
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_period = period;
_convolution = new Convolution(GenerateKernel(_period));
_convolution = new Convolution(GenerateKernel(period));
Name = "Gma";
WarmupPeriod = period;
Init();
+2 -4
View File
@@ -2,7 +2,6 @@ namespace QuanTAlib;
public class Hma : AbstractBase
{
private readonly int _period, _sqrtPeriod;
private readonly Convolution _wmaHalf, _wmaFull, _wmaFinal;
public Hma(int period)
@@ -11,13 +10,12 @@ public class Hma : AbstractBase
{
throw new ArgumentException("Period must be greater than or equal to 2.", nameof(period));
}
_period = period;
_sqrtPeriod = (int)Math.Sqrt(period);
int _sqrtPeriod = (int)Math.Sqrt(period);
_wmaHalf = new Convolution(GenerateWmaKernel(period / 2));
_wmaFull = new Convolution(GenerateWmaKernel(period));
_wmaFinal = new Convolution(GenerateWmaKernel(_sqrtPeriod));
Name = "Hma";
WarmupPeriod = _period + _sqrtPeriod - 1;
WarmupPeriod = period + _sqrtPeriod - 1;
Init();
}
+1 -3
View File
@@ -2,7 +2,6 @@ namespace QuanTAlib;
public class Sinema : AbstractBase
{
private readonly int _period;
private readonly Convolution _convolution;
public Sinema(int period)
@@ -11,8 +10,7 @@ public class Sinema : AbstractBase
{
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_period = period;
_convolution = new Convolution(GenerateKernel(_period));
_convolution = new Convolution(GenerateKernel(period));
Name = "Sinema";
WarmupPeriod = period;
Init();
-7
View File
@@ -4,7 +4,6 @@ public class Sma : AbstractBase
{
// inherited _index
// inherited _value
private readonly int Period;
private readonly CircularBuffer _buffer;
public Sma(int period)
@@ -13,7 +12,6 @@ public class Sma : AbstractBase
{
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
}
Period = period;
WarmupPeriod = period;
_buffer = new CircularBuffer(period);
Name = "Sma";
@@ -28,11 +26,6 @@ public class Sma : AbstractBase
}
//inhereted public void Sub(object source, in ValueEventArgs args)
public override void Init()
{
base.Init();
}
protected override void ManageState(bool isNew)
{
if (isNew)
+1 -3
View File
@@ -2,7 +2,6 @@ namespace QuanTAlib;
public class Trima : AbstractBase
{
private readonly int _period;
private readonly Convolution _convolution;
public Trima(int period)
@@ -11,8 +10,7 @@ public class Trima : AbstractBase
{
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
}
_period = period;
_convolution = new Convolution(GenerateKernel(_period));
_convolution = new Convolution(GenerateKernel(period));
Name = "Trima";
WarmupPeriod = period;
Init();
+2 -4
View File
@@ -6,7 +6,6 @@ namespace QuanTAlib;
public class Vidya : AbstractBase
{
private readonly int _shortPeriod;
private readonly int _longPeriod;
private readonly double _alpha;
private double _lastVIDYA, _p_lastVIDYA;
@@ -19,12 +18,11 @@ public class Vidya : AbstractBase
{
throw new ArgumentException("Short period must be greater than or equal to 1.", nameof(shortPeriod));
}
_shortPeriod = shortPeriod;
_longPeriod = (longPeriod == 0) ? shortPeriod * 4 : longPeriod;
_alpha = alpha;
WarmupPeriod = _longPeriod;
Name = $"Vidya({_shortPeriod},{_longPeriod})";
_shortBuffer = new CircularBuffer(_shortPeriod);
Name = $"Vidya({shortPeriod},{_longPeriod})";
_shortBuffer = new CircularBuffer(shortPeriod);
_longBuffer = new CircularBuffer(_longPeriod);
Init();
}
+4 -11
View File
@@ -30,15 +30,11 @@ public readonly record struct TBar(DateTime Time, double Open, double High, doub
public TBar() : this(DateTime.UtcNow, 0, 0, 0, 0, 0) { }
public TBar(double Open, double High, double Low, double Close, double Volume, bool IsNew = true) : this(DateTime.UtcNow, Open, High, Low, Close, Volume, IsNew) { }
// when TBar casts to double, it returns its Close
public static implicit operator double(TBar bar) => bar.Close;
public static implicit operator DateTime(TBar tv) => tv.Time;
// castings for sloppy people - a single double injected into a TBar, and a single TValue injected into a TBar
public TBar(double value) : this(Time: DateTime.UtcNow, Open: value, High: value, Low: value, Close: value, Volume: value, IsNew: true) { }
public TBar(TValue value) : this(Time: value.Time, Open: value.Value, High: value.Value, Low: value.Value, Close: value.Value, Volume: value.Value, IsNew: value.IsNew) { }
public static implicit operator double(TBar bar) => bar.Close;
public static implicit operator DateTime(TBar tv) => tv.Time;
public override string ToString() => $"[{Time:yyyy-MM-dd HH:mm:ss}: O={Open:F2}, H={High:F2}, L={Low:F2}, C={Close:F2}, V={Volume:F2}]";
}
@@ -70,11 +66,8 @@ public class TBarSeries : List<TBar>
public TBarSeries()
{
this.Name = "Bar";
Open = new();
High = new();
Low = new();
Close = new();
Volume = new();
(Open, High, Low, Close, Volume) = ([], [], [], [], []);
}
public TBarSeries(object source) : this()
{
-5
View File
@@ -27,11 +27,6 @@ namespace QuanTAlib
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
}
public override void Init()
{
base.Init();
}
protected override void ManageState(bool isNew)
{
if (isNew)
-5
View File
@@ -24,11 +24,6 @@ public class Mode : AbstractBase
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
}
public override void Init()
{
base.Init();
}
protected override void ManageState(bool isNew)
{
if (isNew)
+1 -3
View File
@@ -2,7 +2,6 @@ namespace QuanTAlib;
public class Atr : AbstractBarBase
{
private readonly int _period;
private readonly Ema _ma;
private double _prevClose, _p_prevClose;
@@ -12,10 +11,9 @@ public class Atr : AbstractBarBase
{
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
}
_period = period;
_ma = new(1.0/period);
WarmupPeriod = _ma.WarmupPeriod;
Name = $"ATR({_period})";
Name = $"ATR({period})";
}
public Atr(object source, int period) : this(period)