mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-19 19:18:05 +00:00
macos dev update
This commit is contained in:
@@ -9,7 +9,7 @@ namespace QuanTAlib;
|
||||
/// both annualized and non-annualized volatility measures. The calculation uses a sample
|
||||
/// standard deviation formula and assumes 252 trading days in a year for annualization.
|
||||
/// </remarks>
|
||||
public class Historical : AbstractBase
|
||||
public class Hv : AbstractBase
|
||||
{
|
||||
private readonly int Period;
|
||||
private readonly bool IsAnnualized;
|
||||
@@ -25,7 +25,7 @@ public class Historical : AbstractBase
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// Thrown when period is less than 2.
|
||||
/// </exception>
|
||||
public Historical(int period, bool isAnnualized = true)
|
||||
public Hv(int period, bool isAnnualized = true)
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
@@ -46,7 +46,7 @@ public class Historical : AbstractBase
|
||||
/// <param name="source">The source object to subscribe to for value updates.</param>
|
||||
/// <param name="period">The period over which to calculate historical volatility.</param>
|
||||
/// <param name="isAnnualized">Whether to annualize the volatility (default is true).</param>
|
||||
public Historical(object source, int period, bool isAnnualized = true) : this(period, isAnnualized)
|
||||
public Hv(object source, int period, bool isAnnualized = true) : this(period, isAnnualized)
|
||||
{
|
||||
var pubEvent = source.GetType().GetEvent("Pub");
|
||||
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
|
||||
@@ -1,62 +0,0 @@
|
||||
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})";
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
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})";
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace QuanTAlib;
|
||||
/// both annualized and non-annualized volatility measures. The calculation uses a rolling
|
||||
/// sum of squared returns for efficiency and assumes 252 trading days in a year for annualization.
|
||||
/// </remarks>
|
||||
public class Realized : AbstractBase
|
||||
public class Rv : AbstractBase
|
||||
{
|
||||
private readonly int Period;
|
||||
private readonly bool IsAnnualized;
|
||||
@@ -25,7 +25,7 @@ public class Realized : AbstractBase
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// Thrown when period is less than 2.
|
||||
/// </exception>
|
||||
public Realized(int period, bool isAnnualized = true)
|
||||
public Rv(int period, bool isAnnualized = true)
|
||||
{
|
||||
if (period < 2)
|
||||
{
|
||||
@@ -39,6 +39,18 @@ public class Realized : AbstractBase
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Realized class with a data source.
|
||||
/// </summary>
|
||||
/// <param name="source">The source object that publishes data.</param>
|
||||
/// <param name="period">The period over which to calculate realized volatility.</param>
|
||||
/// <param name="isAnnualized">Whether to annualize the volatility (default is true).</param>
|
||||
public Rv(object source, int period, bool isAnnualized = true) : this(period, isAnnualized)
|
||||
{
|
||||
var pubEvent = source.GetType().GetEvent("Pub");
|
||||
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the Realized instance by clearing buffers and resetting calculation variables.
|
||||
/// </summary>
|
||||
@@ -113,4 +125,4 @@ public class Realized : AbstractBase
|
||||
IsHot = _index >= WarmupPeriod;
|
||||
return volatility;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
ADR - Average Daily Range
|
||||
AP - Andrew's Pitchfork
|
||||
✔️ ATR - Average True Range
|
||||
ATRP - Average True Range Percent
|
||||
ATRS - ATR Trailing Stop
|
||||
BB - Bollinger Bands®
|
||||
CCV - Close-to-Close Volatility
|
||||
CE - Chandelier Exit
|
||||
CV - Conditional Volatility (ARCH/GARCH)
|
||||
CVI - Chaikin's Volatility
|
||||
DC - Donchian Channels
|
||||
FCB - Fractal Chaos Bands
|
||||
GKV - Garman-Klass Volatility
|
||||
HLV - High-Low Volatility
|
||||
✔️ HV - Historical Volatility
|
||||
ICH - Ichimoku Cloud
|
||||
✔️ JVOLTY - Jurik Volatility
|
||||
KC - Keltner Channels
|
||||
NATR - Normalized Average True Range
|
||||
PCH - Price Channel Indicator
|
||||
PSAR - Parabolic Stop and Reverse
|
||||
PV - Parkinson Volatility
|
||||
RSV - Rogers-Satchell Volatility
|
||||
✔️ RV - Realized Volatility
|
||||
RVI - Relative Volatility Index
|
||||
STARC - Starc Bands
|
||||
SV - Stochastic Volatility
|
||||
TR - True Range
|
||||
UI - Ulcer Index
|
||||
VC - Volatility Cone
|
||||
VOV - Volatility of Volatility
|
||||
VR - Volatility Ratio
|
||||
VS - Volatility Stop
|
||||
YZV - Yang-Zhang Volatility
|
||||
Reference in New Issue
Block a user