Browse Source

Financial: rename CompoundMonthlyReturn to CompoundReturn #331

The old method has been made obsolete and will be removed in the next
major version.
truncatednormal
Christoph Ruegg 11 years ago
parent
commit
f86c4426f3
  1. 14
      src/Numerics/Financial/AbsoluteReturnMeasures.cs
  2. 15
      src/UnitTests/FinancialTests/CompoundReturnTests.cs
  3. 8
      src/UnitTests/RootFindingTests/SecantTest.cs
  4. 2
      src/UnitTests/UnitTests.csproj

14
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)
{ {
@ -60,7 +66,7 @@ namespace MathNet.Numerics.Financial
/// <summary> /// <summary>
/// Average Gain or Gain Mean /// Average Gain or Gain Mean
/// This is a simple average (arithmetic mean) of the periods with a gain. It is calculated by summing the returns for gain periods (return 0) /// This is a simple average (arithmetic mean) of the periods with a gain. It is calculated by summing the returns for gain periods (return 0)
/// and then dividing the total by the number of gain periods. /// and then dividing the total by the number of gain periods.
/// </summary> /// </summary>
/// <remarks>http://www.offshore-library.com/kb/statistics.php</remarks> /// <remarks>http://www.offshore-library.com/kb/statistics.php</remarks>
@ -90,4 +96,4 @@ namespace MathNet.Numerics.Financial
return data.Where(x => x < 0).Mean(); return data.Where(x => x < 0).Mean();
} }
} }
} }

15
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.
} }
}
}

8
src/UnitTests/RootFindingTests/SecantTest.cs

@ -3,9 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// 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-2013 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
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -14,10 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
// //
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

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