mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-13 16:18:05 +00:00
xml doc rewrite
This commit is contained in:
+32
-4
@@ -1,11 +1,38 @@
|
||||
using System;
|
||||
namespace QuanTAlib;
|
||||
|
||||
/// <summary>
|
||||
/// SMA: Simple Moving Average
|
||||
/// The most basic form of moving average, calculating the arithmetic mean over a
|
||||
/// specified period. Each data point in the period has equal weight in the
|
||||
/// calculation.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SMA calculation process:
|
||||
/// 1. Maintains a buffer of the last 'period' values
|
||||
/// 2. Calculates arithmetic mean of all values in the buffer
|
||||
/// 3. Updates buffer with new values in FIFO manner
|
||||
///
|
||||
/// Key characteristics:
|
||||
/// - Equal weight for all values in the period
|
||||
/// - Simple and straightforward calculation
|
||||
/// - Significant lag due to equal weighting
|
||||
/// - Smooth output with good noise reduction
|
||||
/// - Most basic form of trend following
|
||||
///
|
||||
/// Sources:
|
||||
/// https://www.investopedia.com/terms/s/sma.asp
|
||||
/// https://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages
|
||||
/// </remarks>
|
||||
|
||||
public class Sma : AbstractBase
|
||||
{
|
||||
// inherited _index
|
||||
// inherited _value
|
||||
private readonly CircularBuffer _buffer;
|
||||
|
||||
/// <param name="period">The number of data points used in the SMA calculation.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
|
||||
public Sma(int period)
|
||||
{
|
||||
if (period < 1)
|
||||
@@ -19,12 +46,13 @@ public class Sma : AbstractBase
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <param name="source">The data source object that publishes updates.</param>
|
||||
/// <param name="period">The number of data points used in the SMA calculation.</param>
|
||||
public Sma(object source, int period) : this(period: period)
|
||||
{
|
||||
var pubEvent = source.GetType().GetEvent("Pub");
|
||||
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
|
||||
}
|
||||
//inhereted public void Sub(object source, in ValueEventArgs args)
|
||||
|
||||
protected override void ManageState(bool isNew)
|
||||
{
|
||||
@@ -36,9 +64,9 @@ public class Sma : AbstractBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Core SMA calculation - using _buffer.Average
|
||||
/// Performs the core SMA calculation using the circular buffer's average.
|
||||
/// </summary>
|
||||
|
||||
/// <returns>The calculated SMA value.</returns>
|
||||
protected override double Calculation()
|
||||
{
|
||||
double result;
|
||||
@@ -49,4 +77,4 @@ public class Sma : AbstractBase
|
||||
IsHot = _index >= WarmupPeriod;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user