Beta calculation should check for zero variance before dividing
All checks were successful
Build .NET Project / build (push) Successful in 4m50s
All checks were successful
Build .NET Project / build (push) Successful in 4m50s
This commit is contained in:
@@ -1356,7 +1356,9 @@ namespace MarketData.Numerical
|
||||
/// The revised code (i.e.) Beta=Covariance(x,y)/Variance(x) was taken from Investopedia
|
||||
public static double Beta(ref double[] assetReturns, ref double[] benchmarkReturns)
|
||||
{
|
||||
return Covariance(ref assetReturns, ref benchmarkReturns) / Variance(ref benchmarkReturns);
|
||||
double variance = Variance(ref benchmarkReturns);
|
||||
if(0.00 == variance)return double.NaN;
|
||||
return Covariance(ref assetReturns, ref benchmarkReturns) / variance;
|
||||
}
|
||||
/// <summary>ApplyDecay - Apply exponential weighting.</summary>
|
||||
/// <param name="samples">the samples to weight.</param>
|
||||
|
||||
Reference in New Issue
Block a user