Browse Source

Financial: rename CompoundMonthlyReturn to CompoundReturn #331

The old method has been made obsolete and will be removed in the next
major version.
pull/336/merge
Christoph Ruegg 11 years ago
parent
commit
f86c4426f3
  1. 10
      src/Numerics/Financial/AbsoluteReturnMeasures.cs
  2. 13
      src/UnitTests/FinancialTests/CompoundReturnTests.cs
  3. 2
      src/UnitTests/UnitTests.csproj

10
src/Numerics/Financial/AbsoluteReturnMeasures.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2013 Math.NET // Copyright (c) 2009-2015 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -37,10 +37,16 @@ namespace MathNet.Numerics.Financial
{ {
public static class AbsoluteReturnMeasures public static class AbsoluteReturnMeasures
{ {
[Obsolete("Use CompoundReturn instead, will be removed in v4.0")]
public static double CompoundMonthlyReturn(this IEnumerable<double> data)
{
return CompoundReturn(data);
}
/// <summary> /// <summary>
/// Compound Monthly Return or Geometric Return or Annualized Return /// Compound Monthly Return or Geometric Return or Annualized Return
/// </summary> /// </summary>
public static double CompoundMonthlyReturn(this IEnumerable<double> data) public static double CompoundReturn(this IEnumerable<double> data)
{ {
if (data == null) if (data == null)
{ {

13
src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs → src/UnitTests/FinancialTests/CompoundReturnTests.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// //
// Copyright (c) 2009-2013 Math.NET // Copyright (c) 2009-2015 Math.NET
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
@ -36,7 +36,7 @@ using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests namespace MathNet.Numerics.UnitTests.FinancialTests
{ {
[TestFixture, Category("Financial")] [TestFixture, Category("Financial")]
public class CompoundMonthlyReturnTests public class CompoundReturnTests
{ {
[Test] [Test]
[ExpectedException(typeof(ArgumentNullException))] //assert [ExpectedException(typeof(ArgumentNullException))] //assert
@ -46,7 +46,7 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
List<double> inputData = null; List<double> inputData = null;
//act //act
// ReSharper disable ExpressionIsAlwaysNull // ReSharper disable ExpressionIsAlwaysNull
inputData.CompoundMonthlyReturn(); inputData.CompoundReturn();
// ReSharper restore ExpressionIsAlwaysNull // ReSharper restore ExpressionIsAlwaysNull
} }
@ -56,23 +56,22 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
//arrange //arrange
var inputData = new List<double>(); var inputData = new List<double>();
//act //act
var cmpdReturn = inputData.CompoundMonthlyReturn(); var cmpdReturn = inputData.CompoundReturn();
//assert //assert
Assert.AreEqual(double.NaN, cmpdReturn); Assert.AreEqual(double.NaN, cmpdReturn);
} }
[Test] [Test]
public void calculates_the_compound_monthly_return() public void calculates_the_compound_return()
{ {
//arrange //arrange
var inputData = new[] { 0.2, 0.06, 0.01 }; var inputData = new[] { 0.2, 0.06, 0.01 };
//act //act
var cmpdReturn = inputData.CompoundMonthlyReturn(); var cmpdReturn = inputData.CompoundReturn();
//assert //assert
AssertHelpers.AlmostEqualRelative(0.0870999982199265, cmpdReturn, 14); AssertHelpers.AlmostEqualRelative(0.0870999982199265, cmpdReturn, 14);
} }
//Definitely need more tests here. Would love to find test data for these stats similar to the .dat files used for other tests. //Definitely need more tests here. Would love to find test data for these stats similar to the .dat files used for other tests.
} }
} }

2
src/UnitTests/UnitTests.csproj

@ -118,7 +118,7 @@
<Compile Include="DistributionTests\Multivariate\MultinomialTests.cs" /> <Compile Include="DistributionTests\Multivariate\MultinomialTests.cs" />
<Compile Include="DistributionTests\Multivariate\NormalGammaTests.cs" /> <Compile Include="DistributionTests\Multivariate\NormalGammaTests.cs" />
<Compile Include="DistributionTests\Multivariate\WishartTests.cs" /> <Compile Include="DistributionTests\Multivariate\WishartTests.cs" />
<Compile Include="FinancialTests\CompoundMonthlyReturnTests.cs" /> <Compile Include="FinancialTests\CompoundReturnTests.cs" />
<Compile Include="FinancialTests\DownsideDeviationTests.cs" /> <Compile Include="FinancialTests\DownsideDeviationTests.cs" />
<Compile Include="FinancialTests\GainLossRatioTests.cs" /> <Compile Include="FinancialTests\GainLossRatioTests.cs" />
<Compile Include="FinancialTests\GainStandardDeviationTests.cs" /> <Compile Include="FinancialTests\GainStandardDeviationTests.cs" />

Loading…
Cancel
Save