Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Indicators/Beta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Beta(string name, Symbol targetSymbol, Symbol referenceSymbol, int period
: base(name, targetSymbol, referenceSymbol, 2)
{
// Assert the period is greater than two, otherwise the beta can not be computed
if (period < 2)
if (period < 3)
{
throw new ArgumentException($"Period parameter for Beta indicator must be greater than 2 but was {period}.");
}
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Correlation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Correlation(string name, Symbol targetSymbol, Symbol referenceSymbol, int
: base(name, targetSymbol, referenceSymbol, period)
{
// Assert the period is greater than two, otherwise the correlation can not be computed
if (period < 2)
if (period < 3)
{
throw new ArgumentException($"Period parameter for Correlation indicator must be greater than 2 but was {period}");
}
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Covariance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Covariance(string name, Symbol targetSymbol, Symbol referenceSymbol, int
: base(name, targetSymbol, referenceSymbol, 2)
{
// Assert the period is greater than two, otherwise the covariance can not be computed
if (period < 2)
if (period < 3)
{
throw new ArgumentException($"Period parameter for Covariance indicator must be greater than 2 but was {period}.");
}
Expand Down
12 changes: 12 additions & 0 deletions Tests/Indicators/BetaIndicatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,17 @@ public override void IndicatorShouldHaveSymbolAfterUpdates()
Assert.AreEqual(Symbols.AAPL, indicator.Current.Symbol);
}
}

[Test]
public void PeriodBelowMinimumThrows()
{
// A two point window leaves no spread to measure: the correlation of two
// points is 1 or -1 whatever the data says, so three is the smallest period
// that carries information
var period = 2;

var exception = Assert.Throws<ArgumentException>(() => new Beta(Symbols.SPY, Symbols.AAPL, period));
Assert.That(exception.Message, Is.EqualTo($"Period parameter for Beta indicator must be greater than 2 but was {period}."));
}
}
}
12 changes: 12 additions & 0 deletions Tests/Indicators/CorrelationPearsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,17 @@ public void CorrelationWithDifferentTimeZones()
}
Assert.AreEqual(1, (double)indicator.Current.Value);
}

[Test]
public void PeriodBelowMinimumThrows()
{
// A two point window leaves no spread to measure: the correlation of two
// points is 1 or -1 whatever the data says, so three is the smallest period
// that carries information
var period = 2;

var exception = Assert.Throws<ArgumentException>(() => new Correlation(Symbols.SPY, Symbols.AAPL, period));
Assert.That(exception.Message, Is.EqualTo($"Period parameter for Correlation indicator must be greater than 2 but was {period}"));
}
}
}
12 changes: 12 additions & 0 deletions Tests/Indicators/CovarianceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,17 @@ public override void IndicatorShouldHaveSymbolAfterUpdates()
Assert.AreEqual(Symbols.AAPL, indicator.Current.Symbol);
}
}

[Test]
public void PeriodBelowMinimumThrows()
{
// A two point window leaves no spread to measure: the correlation of two
// points is 1 or -1 whatever the data says, so three is the smallest period
// that carries information
var period = 2;

var exception = Assert.Throws<ArgumentException>(() => new Covariance(Symbols.SPY, Symbols.AAPL, period));
Assert.That(exception.Message, Is.EqualTo($"Period parameter for Covariance indicator must be greater than 2 but was {period}."));
}
}
}