mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-16 01:28:05 +00:00
Apply fixes from CodeFactor (#46)
This commit is contained in:
@@ -22,7 +22,7 @@ public class StatisticsUpdateTests
|
|||||||
double open = GetRandomDouble();
|
double open = GetRandomDouble();
|
||||||
double high = open + Math.Abs(GetRandomDouble());
|
double high = open + Math.Abs(GetRandomDouble());
|
||||||
double low = open - Math.Abs(GetRandomDouble());
|
double low = open - Math.Abs(GetRandomDouble());
|
||||||
double close = low + (high - low) * GetRandomDouble();
|
double close = low + ((high - low) * GetRandomDouble());
|
||||||
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
|
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public class StatisticsUpdateTests
|
|||||||
double open = GetRandomDouble();
|
double open = GetRandomDouble();
|
||||||
double high = open + Math.Abs(GetRandomDouble());
|
double high = open + Math.Abs(GetRandomDouble());
|
||||||
double low = open - Math.Abs(GetRandomDouble());
|
double low = open - Math.Abs(GetRandomDouble());
|
||||||
double close = low + (high - low) * GetRandomDouble();
|
double close = low + ((high - low) * GetRandomDouble());
|
||||||
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
|
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns a value between 0 and 1
|
/// Note: Returns a value between 0 and 1
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Hurst : AbstractBase
|
public sealed class Hurst : AbstractBase
|
||||||
{
|
{
|
||||||
@@ -184,7 +183,7 @@ public sealed class Hurst : AbstractBase
|
|||||||
double hurst = 0.5; // Default to random walk
|
double hurst = 0.5; // Default to random walk
|
||||||
if (numPoints > 1)
|
if (numPoints > 1)
|
||||||
{
|
{
|
||||||
double slope = (numPoints * sumXY - sumX * sumY) / (numPoints * sumX2 - sumX * sumX);
|
double slope = ((numPoints * sumXY) - (sumX * sumY)) / ((numPoints * sumX2) - (sumX * sumX));
|
||||||
hurst = Math.Max(0, Math.Min(1, slope)); // Clamp between 0 and 1
|
hurst = Math.Max(0, Math.Min(1, slope)); // Clamp between 0 and 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns three values: upper, middle, and lower bands
|
/// Note: Returns three values: upper, middle, and lower bands
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Bband : AbstractBase
|
public sealed class Bband : AbstractBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns annualized volatility as a percentage
|
/// Note: Returns annualized volatility as a percentage
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Ccv : AbstractBase
|
public sealed class Ccv : AbstractBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns two values: long exit and short exit levels
|
/// Note: Returns two values: long exit and short exit levels
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Ce : AbstractBase
|
public sealed class Ce : AbstractBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns annualized volatility as a percentage
|
/// Note: Returns annualized volatility as a percentage
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Cv : AbstractBase
|
public sealed class Cv : AbstractBase
|
||||||
{
|
{
|
||||||
@@ -126,7 +125,7 @@ public sealed class Cv : AbstractBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update variance estimate using GARCH(1,1)
|
// Update variance estimate using GARCH(1,1)
|
||||||
double variance = _omega + _alpha * squaredReturn + _beta * _prevVariance;
|
double variance = _omega + (_alpha * squaredReturn) + (_beta * _prevVariance);
|
||||||
_prevVariance = variance;
|
_prevVariance = variance;
|
||||||
|
|
||||||
// Calculate annualized volatility as percentage
|
// Calculate annualized volatility as percentage
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns annualized volatility as a percentage
|
/// Note: Returns annualized volatility as a percentage
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Ewma : AbstractBase
|
public sealed class Ewma : AbstractBase
|
||||||
{
|
{
|
||||||
@@ -121,7 +120,7 @@ public sealed class Ewma : AbstractBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update EWMA
|
// Update EWMA
|
||||||
_ewma = _lambda * _ewma + (1 - _lambda) * squaredReturn;
|
_ewma = (_lambda * _ewma) + ((1 - _lambda) * squaredReturn);
|
||||||
|
|
||||||
// Calculate volatility
|
// Calculate volatility
|
||||||
double volatility = Math.Sqrt(_ewma);
|
double volatility = Math.Sqrt(_ewma);
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns three values: upper, middle, and lower bands
|
/// Note: Returns three values: upper, middle, and lower bands
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Fcb : AbstractBase
|
public sealed class Fcb : AbstractBase
|
||||||
{
|
{
|
||||||
@@ -134,8 +133,8 @@ public sealed class Fcb : AbstractBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply smoothing to bands
|
// Apply smoothing to bands
|
||||||
_upperBand = _smoothing * _upperEma + (1 - _smoothing) * BarInput.High;
|
_upperBand = (_smoothing * _upperEma) + ((1 - _smoothing) * BarInput.High);
|
||||||
_lowerBand = _smoothing * _lowerEma + (1 - _smoothing) * BarInput.Low;
|
_lowerBand = (_smoothing * _lowerEma) + ((1 - _smoothing) * BarInput.Low);
|
||||||
_middleBand = (_upperBand + _lowerBand) / 2;
|
_middleBand = (_upperBand + _lowerBand) / 2;
|
||||||
|
|
||||||
IsHot = _index >= WarmupPeriod;
|
IsHot = _index >= WarmupPeriod;
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns annualized volatility as a percentage
|
/// Note: Returns annualized volatility as a percentage
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Gkv : AbstractBase
|
public sealed class Gkv : AbstractBase
|
||||||
{
|
{
|
||||||
@@ -97,7 +96,7 @@ public sealed class Gkv : AbstractBase
|
|||||||
c = c * c;
|
c = c * c;
|
||||||
|
|
||||||
// Combine components with optimal weights
|
// Combine components with optimal weights
|
||||||
double component = 0.5 * u - (2 * _ln2 - 1) * c;
|
double component = (0.5 * u) - (((2 * _ln2) - 1) * c);
|
||||||
_components.Add(component);
|
_components.Add(component);
|
||||||
|
|
||||||
// Need enough values for calculation
|
// Need enough values for calculation
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ namespace QuanTAlib;
|
|||||||
///
|
///
|
||||||
/// Note: Returns annualized volatility as a percentage
|
/// Note: Returns annualized volatility as a percentage
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Hlv : AbstractBase
|
public sealed class Hlv : AbstractBase
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user