XML Documentation

This commit is contained in:
Miha Kralj
2024-10-05 15:20:13 -07:00
parent 30d93e724d
commit 3458b14ebb
23 changed files with 1596 additions and 986 deletions
+37 -3
View File
@@ -1,16 +1,27 @@
namespace QuanTAlib;
// Excess kurtosis calculated with Sheskin Algorithm
/// <summary>
/// Calculates excess kurtosis using the Sheskin Algorithm.
/// Measures the "tailedness" of the probability distribution of a real-valued random variable.
/// </summary>
public class Kurtosis : AbstractBase
{
private readonly int Period;
private readonly CircularBuffer _buffer;
/// <summary>
/// Initializes a new instance of the Kurtosis class.
/// </summary>
/// <param name="period">The number of data points to consider for calculation.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the period is less than 4.
/// </exception>
public Kurtosis(int period) : base()
{
if (period < 4)
{
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 4 for kurtosis calculation.");
throw new ArgumentOutOfRangeException(nameof(period),
"Period must be greater than or equal to 4 for kurtosis calculation.");
}
Period = period;
WarmupPeriod = Period - 1;
@@ -19,18 +30,30 @@ public class Kurtosis : AbstractBase
Init();
}
/// <summary>
/// Initializes a new instance of the Kurtosis class with a data source.
/// </summary>
/// <param name="source">The source object that publishes data.</param>
/// <param name="period">The number of data points to consider.</param>
public Kurtosis(object source, int period) : this(period)
{
var pubEvent = source.GetType().GetEvent("Pub");
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
}
/// <summary>
/// Resets the Kurtosis indicator to its initial state.
/// </summary>
public override void Init()
{
base.Init();
_buffer.Clear();
}
/// <summary>
/// Manages the state of the indicator.
/// </summary>
/// <param name="isNew">Indicates if the current data point is new.</param>
protected override void ManageState(bool isNew)
{
if (isNew)
@@ -40,6 +63,17 @@ public class Kurtosis : AbstractBase
}
}
/// <summary>
/// Performs the kurtosis calculation.
/// </summary>
/// <returns>
/// The calculated excess kurtosis. Positive for heavy-tailed distributions,
/// negative for light-tailed distributions.
/// </returns>
/// <remarks>
/// Uses the Sheskin Algorithm for kurtosis calculation.
/// Requires at least 4 data points for a valid calculation.
/// </remarks>
protected override double Calculation()
{
ManageState(Input.IsNew);
@@ -65,7 +99,7 @@ public class Kurtosis : AbstractBase
double variance = s2 / (n - 1);
// Using the Sheskin Algorithm for kurtosis
// Sheskin Algorithm
kurtosis = (n * (n + 1) * s4) / (variance * variance * (n - 3) * (n - 1) * (n - 2))
- (3 * (n - 1) * (n - 1) / ((n - 2) * (n - 3)));
}