macos dev update

This commit is contained in:
Miha
2024-10-26 23:54:55 -07:00
parent e4f718a365
commit c21b96152c
28 changed files with 458 additions and 345 deletions
+11 -2
View File
@@ -20,6 +20,17 @@ public class Cmo : AbstractBase
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>
public Cmo(object source, int period) : this(period)
{
var pubEvent = source.GetType().GetEvent("Pub");
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
}
protected override void ManageState(bool isNew)
{
if (isNew)
@@ -54,7 +65,6 @@ public class Cmo : AbstractBase
{
_sumH.Add(0, Input.IsNew);
_sumL.Add(-diff, Input.IsNew);
}
// Calculate sums for the specified period only
@@ -67,4 +77,3 @@ public class Cmo : AbstractBase
0.0;
}
}
+70
View File
@@ -0,0 +1,70 @@
using System;
namespace QuanTAlib;
/// <summary>
/// Represents a Relative Strength Index (RSI) calculator following Wilder's algorithm.
/// </summary>
public class Rsi : AbstractBase
{
private readonly Rma _avgGain;
private readonly Rma _avgLoss;
private double _prevValue, _p_prevValue;
public Rsi(int period = 14)
{
if (period < 1)
throw new ArgumentOutOfRangeException(nameof(period));
_avgGain = new(period, useSma: true);
_avgLoss = new(period, useSma: true);
_index = 0;
WarmupPeriod = period + 1;
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>
public Rsi(object source, int period) : this(period)
{
var pubEvent = source.GetType().GetEvent("Pub");
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
}
protected override void ManageState(bool isNew)
{
if (isNew)
{
_index++;
_p_prevValue = _prevValue;
}
else
{
_prevValue = _p_prevValue;
}
}
protected override double Calculation()
{
ManageState(Input.IsNew);
if (_index == 1)
{
_prevValue = Input.Value;
}
double change = Input.Value - _prevValue;
double gain = Math.Max(change, 0);
double loss = Math.Max(-change, 0);
_prevValue = Input.Value;
_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;
return rsi;
}
}
+75
View File
@@ -0,0 +1,75 @@
using System;
namespace QuanTAlib;
/// <summary>
/// Jurik's superior replacement for RSI
/// </summary>
public class Rsx : AbstractBase
{
private readonly Rma _avgGain;
private readonly Rma _avgLoss;
private readonly Jma _rsx;
private double _prevValue, _p_prevValue;
public Rsx(int period = 14, int phase = 0, double factor = 0.55)
{
if (period < 1)
throw new ArgumentOutOfRangeException(nameof(period));
_avgGain = new(period);
_avgLoss = new(period);
_rsx = new(8, 100, 0.25, 3);
_index = 0;
WarmupPeriod = period + 1;
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>
public Rsx(object source, int period, int phase = 0, double factor = 0.55) : this(period, phase, factor)
{
var pubEvent = source.GetType().GetEvent("Pub");
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
}
protected override void ManageState(bool isNew)
{
if (isNew)
{
_index++;
_p_prevValue = _prevValue;
}
else
{
_prevValue = _p_prevValue;
}
}
protected override double Calculation()
{
ManageState(Input.IsNew);
if (_index == 1)
{
_prevValue = Input.Value;
}
double change = Input.Value - _prevValue;
double gain = Math.Max(change, 0);
double loss = Math.Max(-change, 0);
_prevValue = Input.Value;
_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;
double rsx = _rsx.Calc(rsi, Input.IsNew);
return rsx;
}
}
+29
View File
@@ -0,0 +1,29 @@
AC - Acceleration Oscillator
AO - Awesome Oscillator
AROON - Aroon oscillator
BOP - Balance of Power
CCI - Commodity Channel Index
CFO - Chande Forcast Oscillator
✔️ CMO - Chande Momentum Oscillator
CHOP - Choppiness Index
COG - Ehler's Center of Gravity
COPPOCK - Coppock Curve
CRSI - Connor RSI
CTI - Ehler's Correlation Trend Indicator
DOSC - Derivative Oscillator
EFI - Elder Ray's Force Index
FISHER - Fisher Transform
FOSC - Forecast Oscillator
GATOR - Williams Alliator Oscillator
KDJ - KDJ Indicator (trend reversal)
KRI - Kairi Relative Index
✔️ RSI - Relative Strength Index
✔️ RSX - Jurik Trend Strength Index
RVGI - Relative Vigor Index
SMI - Stochastic Momentum Index
SRSI - Stochastic RSI
STC - Schaff Trend Cycle
STOCH - Stochastic Oscillator
TSI - True Strength Index
UO - Ultimate Oscillator
WILLR - Larry Williams' %R