xml doc rewrite

This commit is contained in:
Miha
2024-10-27 09:38:53 -07:00
parent c21b96152c
commit b2fcdda785
71 changed files with 2607 additions and 1102 deletions
+41 -8
View File
@@ -1,14 +1,47 @@
using System;
namespace QuanTAlib;
/// <summary>
/// Represents a Chande Momentum Oscillator (CMO) calculator.
/// CMO: Chande Momentum Oscillator
/// A technical momentum indicator that measures the difference between upward and
/// downward momentum. CMO helps identify overbought and oversold conditions, as
/// well as trend strength and potential reversals.
/// </summary>
/// <remarks>
/// The CMO calculation process:
/// 1. Calculates price differences from previous period
/// 2. Separates positive (upward) and negative (downward) movements
/// 3. Sums upward and downward movements over period
/// 4. Calculates: 100 * ((sumUp - sumDown) / (sumUp + sumDown))
///
/// Key characteristics:
/// - Oscillates between -100 and +100
/// - Values above +50 indicate overbought
/// - Values below -50 indicate oversold
/// - Zero line crossovers signal trend changes
/// - High absolute values suggest strong trends
///
/// Formula:
/// CMO = 100 * ((ΣUp - ΣDown) / (ΣUp + ΣDown))
/// where:
/// Up = positive price changes
/// Down = absolute negative price changes
///
/// Sources:
/// Tushar Chande - "The New Technical Trader" (1994)
/// https://www.investopedia.com/terms/c/chandemomentumoscillator.asp
///
/// Note: Similar to RSI but with different scaling and calculation method
/// </remarks>
public class Cmo : AbstractBase
{
private readonly CircularBuffer _sumH;
private readonly CircularBuffer _sumL;
private double _prevValue, _p_prevValue;
/// <param name="period">The number of periods used in the CMO calculation.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
public Cmo(int period)
{
if (period < 1)
@@ -16,15 +49,12 @@ public class Cmo : AbstractBase
_sumH = new(period);
_sumL = new(period);
WarmupPeriod = period+1;
WarmupPeriod = period + 1;
Name = $"CMO({period})";
}
/// <summary>
/// Initializes a new instance of the CMO 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>
/// <param name="source">The data source object that publishes updates.</param>
/// <param name="period">The number of periods used in the CMO calculation.</param>
public Cmo(object source, int period) : this(period)
{
var pubEvent = source.GetType().GetEvent("Pub");
@@ -53,9 +83,11 @@ public class Cmo : AbstractBase
_prevValue = Input.Value;
}
// Calculate price difference
double diff = Input.Value - _prevValue;
_prevValue = Input.Value;
// Separate upward and downward movements
if (diff > 0)
{
_sumH.Add(diff, Input.IsNew);
@@ -67,11 +99,12 @@ public class Cmo : AbstractBase
_sumL.Add(-diff, Input.IsNew);
}
// Calculate sums for the specified period only
// Calculate sums for the specified period
double sumH = _sumH.Sum();
double sumL = _sumL.Sum();
double divisor = sumH + sumL;
// Calculate CMO value
return (Math.Abs(divisor) > double.Epsilon) ?
100.0 * ((sumH - sumL) / divisor) :
0.0;
+39 -7
View File
@@ -1,16 +1,48 @@
using System;
namespace QuanTAlib;
/// <summary>
/// Represents a Relative Strength Index (RSI) calculator following Wilder's algorithm.
/// RSI: Relative Strength Index
/// A momentum oscillator that measures the speed and magnitude of recent price
/// changes to evaluate overbought or oversold conditions. RSI compares the
/// magnitude of recent gains to recent losses.
/// </summary>
/// <remarks>
/// The RSI calculation process:
/// 1. Calculates price changes from previous period
/// 2. Separates gains and losses
/// 3. Calculates average gain and loss using Wilder's smoothing
/// 4. Computes relative strength (avg gain / avg loss)
/// 5. Normalizes to 0-100 scale: 100 - (100 / (1 + RS))
///
/// Key characteristics:
/// - Oscillates between 0 and 100
/// - Traditional overbought level at 70
/// - Traditional oversold level at 30
/// - Centerline (50) crossovers signal trend changes
/// - Divergences suggest potential reversals
///
/// Formula:
/// RSI = 100 - (100 / (1 + RS))
/// where:
/// RS = Average Gain / Average Loss
/// Average Gain/Loss = Wilder's smoothed average over period
///
/// Sources:
/// J. Welles Wilder Jr. - "New Concepts in Technical Trading Systems" (1978)
/// https://www.investopedia.com/terms/r/rsi.asp
///
/// Note: Default period of 14 was recommended by Wilder
/// </remarks>
public class Rsi : AbstractBase
{
private readonly Rma _avgGain;
private readonly Rma _avgLoss;
private double _prevValue, _p_prevValue;
/// <param name="period">The number of periods used in the RSI calculation (default 14).</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
public Rsi(int period = 14)
{
if (period < 1)
@@ -22,11 +54,8 @@ public class Rsi : AbstractBase
Name = $"RSI({period})";
}
/// <summary>
/// Initializes a new instance of the RSI 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>
/// <param name="source">The data source object that publishes updates.</param>
/// <param name="period">The number of periods used in the RSI calculation.</param>
public Rsi(object source, int period) : this(period)
{
var pubEvent = source.GetType().GetEvent("Pub");
@@ -55,14 +84,17 @@ public class Rsi : AbstractBase
_prevValue = Input.Value;
}
// Calculate price change and separate gains/losses
double change = Input.Value - _prevValue;
double gain = Math.Max(change, 0);
double loss = Math.Max(-change, 0);
_prevValue = Input.Value;
// Calculate smoothed averages using Wilder's method
_avgGain.Calc(gain, IsNew: Input.IsNew);
_avgLoss.Calc(loss, IsNew: Input.IsNew);
// Calculate RSI
double rsi = (_avgLoss.Value > 0) ? 100 - (100 / (1 + (_avgGain.Value / _avgLoss.Value))) : 100;
return rsi;
+43 -10
View File
@@ -1,10 +1,39 @@
using System;
namespace QuanTAlib;
/// <summary>
/// Jurik's superior replacement for RSI
/// RSX: Relative Strength eXtended
/// An enhanced version of RSI developed by Mark Jurik that applies JMA (Jurik Moving
/// Average) smoothing to the RSI calculation. RSX provides smoother signals with
/// less noise while maintaining responsiveness to significant price movements.
/// </summary>
/// <remarks>
/// The RSX calculation process:
/// 1. Calculates traditional RSI values
/// 2. Applies JMA smoothing to RSI output
/// 3. Uses optimized parameters for noise reduction
/// 4. Maintains RSI's 0-100 scale
///
/// Key characteristics:
/// - Smoother than traditional RSI
/// - Better noise reduction
/// - Maintains responsiveness to significant moves
/// - Same interpretation as RSI (0-100 scale)
/// - Fewer false signals than RSI
///
/// Formula:
/// RSX = JMA(RSI(price))
/// where:
/// RSI = standard Relative Strength Index
/// JMA = Jurik Moving Average with optimized parameters
///
/// Sources:
/// Mark Jurik - "The Jurik RSX"
/// https://www.jurikresearch.com/
///
/// Note: Proprietary enhancement of RSI using JMA technology
/// </remarks>
public class Rsx : AbstractBase
{
private readonly Rma _avgGain;
@@ -12,6 +41,10 @@ public class Rsx : AbstractBase
private readonly Jma _rsx;
private double _prevValue, _p_prevValue;
/// <param name="period">The number of periods for RSI calculation (default 14).</param>
/// <param name="phase">The phase parameter for JMA smoothing (default 0).</param>
/// <param name="factor">The factor parameter for smoothing control (default 0.55).</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
public Rsx(int period = 14, int phase = 0, double factor = 0.55)
{
if (period < 1)
@@ -24,13 +57,10 @@ public class Rsx : AbstractBase
Name = $"RSX({period})";
}
/// <summary>
/// Initializes a new instance of the RSX 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>
/// <param name="phase">The phase parameter.</param>
/// <param name="factor">The factor parameter.</param>
/// <param name="source">The data source object that publishes updates.</param>
/// <param name="period">The number of periods for RSI calculation.</param>
/// <param name="phase">The phase parameter for JMA smoothing.</param>
/// <param name="factor">The factor parameter for smoothing control.</param>
public Rsx(object source, int period, int phase = 0, double factor = 0.55) : this(period, phase, factor)
{
var pubEvent = source.GetType().GetEvent("Pub");
@@ -59,15 +89,18 @@ public class Rsx : AbstractBase
_prevValue = Input.Value;
}
// Calculate RSI components
double change = Input.Value - _prevValue;
double gain = Math.Max(change, 0);
double loss = Math.Max(-change, 0);
_prevValue = Input.Value;
// Calculate RSI
_avgGain.Calc(gain, IsNew: Input.IsNew);
_avgLoss.Calc(loss, IsNew: Input.IsNew);
double rsi = (_avgLoss.Value > 0) ? 100 - (100 / (1 + (_avgGain.Value / _avgLoss.Value))) : 100;
// Apply JMA smoothing
double rsx = _rsx.Calc(rsi, Input.IsNew);
return rsx;