mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
Pwma
This commit is contained in:
@@ -28,6 +28,7 @@ public class EventingTests
|
|||||||
("Dwma", new Dwma(p), new Dwma(input, p)),
|
("Dwma", new Dwma(p), new Dwma(input, p)),
|
||||||
("Ema", new Ema(p), new Ema(input, p)),
|
("Ema", new Ema(p), new Ema(input, p)),
|
||||||
("Epma", new Epma(p), new Epma(input, p)),
|
("Epma", new Epma(p), new Epma(input, p)),
|
||||||
|
("Pwma", new Pwma(p), new Pwma(input, p)),
|
||||||
("Frama", new Frama(p), new Frama(input, p)),
|
("Frama", new Frama(p), new Frama(input, p)),
|
||||||
("Fwma", new Fwma(p), new Fwma(input, p)),
|
("Fwma", new Fwma(p), new Fwma(input, p)),
|
||||||
("Gma", new Gma(p), new Gma(input, p)),
|
("Gma", new Gma(p), new Gma(input, p)),
|
||||||
@@ -81,4 +82,4 @@ public class EventingTests
|
|||||||
rng.GetBytes(bytes);
|
rng.GetBytes(bytes);
|
||||||
return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue;
|
return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class IndicatorTests
|
|||||||
new Dsma(period: 14),
|
new Dsma(period: 14),
|
||||||
new Dwma(period: 14),
|
new Dwma(period: 14),
|
||||||
new Epma(period: 14),
|
new Epma(period: 14),
|
||||||
|
new Pwma(period: 14),
|
||||||
new Frama(period: 14),
|
new Frama(period: 14),
|
||||||
new Fwma(period: 14),
|
new Fwma(period: 14),
|
||||||
new Gma(period: 14),
|
new Gma(period: 14),
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
|MGDI - McGinley Dynamic Indicator|`Mgdi`|`✔️`|||
|
|MGDI - McGinley Dynamic Indicator|`Mgdi`|`✔️`|||
|
||||||
|MMA - Modified Moving Average|`Mma`||||
|
|MMA - Modified Moving Average|`Mma`||||
|
||||||
|PPMA - Pivot Point Moving Average|||||
|
|PPMA - Pivot Point Moving Average|||||
|
||||||
|PWMA - Pascal's Weighted Moving Average|||||
|
|PWMA - Pascal's Weighted Moving Average|`Pwma`||||
|
||||||
|QEMA - Quad Exponential Moving Average|`Qema`||||
|
|QEMA - Quad Exponential Moving Average|`Qema`||||
|
||||||
|RMA - WildeR's Moving Average|`Rma`||||
|
|RMA - WildeR's Moving Average|`Rma`||||
|
||||||
|SINEMA - Sine Weighted Moving Average|`Sinema`||||
|
|SINEMA - Sine Weighted Moving Average|`Sinema`||||
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
public class Pwma : AbstractBase
|
||||||
|
{
|
||||||
|
private readonly int _period;
|
||||||
|
private readonly Convolution _convolution;
|
||||||
|
|
||||||
|
public Pwma(int period)
|
||||||
|
{
|
||||||
|
if (period < 1)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Period must be greater than or equal to 1.", nameof(period));
|
||||||
|
}
|
||||||
|
_period = period;
|
||||||
|
_convolution = new Convolution(GenerateKernel(_period));
|
||||||
|
Name = "Pwma";
|
||||||
|
WarmupPeriod = period;
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pwma(object source, int period) : this(period)
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
private new void Init()
|
||||||
|
{
|
||||||
|
base.Init();
|
||||||
|
_convolution.Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_lastValidValue = Input.Value;
|
||||||
|
_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(Input.IsNew);
|
||||||
|
|
||||||
|
// Use Convolution for calculation
|
||||||
|
TValue convolutionResult = _convolution.Calc(Input);
|
||||||
|
|
||||||
|
double result = convolutionResult.Value;
|
||||||
|
|
||||||
|
// Adjust for partial periods during warmup
|
||||||
|
if (_index < _period)
|
||||||
|
{
|
||||||
|
double[] partialKernel = GenerateKernel(_index);
|
||||||
|
result /= partialKernel.Sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
IsHot = _index >= WarmupPeriod;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double[] GenerateKernel(int period)
|
||||||
|
{
|
||||||
|
double[] kernel = new double[period];
|
||||||
|
kernel[0] = 1;
|
||||||
|
|
||||||
|
for (int i = 1; i < period; i++)
|
||||||
|
{
|
||||||
|
for (int j = i; j > 0; j--)
|
||||||
|
{
|
||||||
|
kernel[j] += kernel[j - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize the kernel
|
||||||
|
double weightSum = kernel.Sum();
|
||||||
|
for (int i = 0; i < period; i++)
|
||||||
|
{
|
||||||
|
kernel[i] /= weightSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
return kernel;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class AlmaIndicator : IndicatorBase
|
public class AlmaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
@@ -7,10 +7,10 @@ public class AlmaIndicator : IndicatorBase
|
|||||||
public int Period { get; set; } = 10;
|
public int Period { get; set; } = 10;
|
||||||
|
|
||||||
[InputParameter("Offset", sortIndex: 5)]
|
[InputParameter("Offset", sortIndex: 5)]
|
||||||
public double Offset = 0.85;
|
public double Offset { get; set; } = 0.85;
|
||||||
|
|
||||||
[InputParameter("Sigma", sortIndex: 6)]
|
[InputParameter("Sigma", sortIndex: 6)]
|
||||||
public double Sigma = 6.0;
|
public double Sigma { get; set; } = 6.0;
|
||||||
private Alma? ma;
|
private Alma? ma;
|
||||||
protected override AbstractBase QuanTAlib => ma!;
|
protected override AbstractBase QuanTAlib => ma!;
|
||||||
public override string ShortName => $"ALMA {Period} : {Offset:F2} : {Sigma:F0} : {SourceName}";
|
public override string ShortName => $"ALMA {Period} : {Offset:F2} : {Sigma:F0} : {SourceName}";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class DemaIndicator : IndicatorBase
|
public class DemaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class DsmaIndicator : IndicatorBase
|
public class DsmaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class DwmaIndicator : IndicatorBase
|
public class DwmaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class EmaIndicator : IndicatorBase
|
public class EmaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class EpmaIndicator : IndicatorBase
|
public class EpmaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class FramaIndicator : IndicatorBase
|
public class FramaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class FwmaIndicator : IndicatorBase
|
public class FwmaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using TradingPlatform.BusinessLayer;
|
using TradingPlatform.BusinessLayer;
|
||||||
using QuanTAlib;
|
namespace QuanTAlib;
|
||||||
|
|
||||||
public class GmaIndicator : IndicatorBase
|
public class GmaIndicator : IndicatorBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using TradingPlatform.BusinessLayer;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
public class PwmaIndicator : IndicatorBase
|
||||||
|
{
|
||||||
|
[InputParameter("Period", sortIndex: 1, 1, 2000, 1, 0)]
|
||||||
|
public int Period { get; set; } = 10;
|
||||||
|
|
||||||
|
private Pwma? ma;
|
||||||
|
protected override AbstractBase QuanTAlib => ma!;
|
||||||
|
public override string ShortName => $"PWMA {Period} : {SourceName}";
|
||||||
|
|
||||||
|
public PwmaIndicator() : base()
|
||||||
|
{
|
||||||
|
Name = "PWMA - Pascal's Weighted Moving Average";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void InitIndicator()
|
||||||
|
{
|
||||||
|
base.InitIndicator();
|
||||||
|
ma = new Pwma(period: Period);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user