Browse Source

Financial: cosmetics

pull/163/head
Christoph Ruegg 13 years ago
parent
commit
65c44cf560
  1. 24
      src/Numerics/Financial/AbsoluteReturnMeasures.cs
  2. 19
      src/Numerics/Financial/AbsoluteRiskMeasures.cs
  3. 18
      src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs
  4. 20
      src/UnitTests/FinancialTests/DownsideDeviationTests.cs
  5. 20
      src/UnitTests/FinancialTests/GainLossRatioTests.cs
  6. 18
      src/UnitTests/FinancialTests/GainMeanTests.cs
  7. 20
      src/UnitTests/FinancialTests/GainStandardDeviationTests.cs
  8. 18
      src/UnitTests/FinancialTests/LossMeanTests.cs
  9. 20
      src/UnitTests/FinancialTests/LossStandardDeviationTests.cs
  10. 20
      src/UnitTests/FinancialTests/SemiDeviationTests.cs

24
src/Numerics/Financial/AbsoluteReturnMeasures.cs

@ -28,13 +28,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Statistics;
namespace MathNet.Numerics.Financial
{
using System;
using System.Collections.Generic;
using System.Linq;
using Statistics;
public static class AbsoluteReturnMeasures
{
/// <summary>
@ -47,16 +47,14 @@ namespace MathNet.Numerics.Financial
throw new ArgumentNullException("data");
}
var samples = data.Count();
if (samples == 0)
return double.NaN;
int count = 0;
double compoundReturn = 1.0;
foreach (var item in data)
{
count++;
compoundReturn *= (1 + item);
}
return Math.Pow(compoundReturn, 1.0 / samples) - 1.0;
return count == 0 ? double.NaN : Math.Pow(compoundReturn, 1.0/count) - 1.0;
}
/// <summary>
@ -72,8 +70,7 @@ namespace MathNet.Numerics.Financial
throw new ArgumentNullException("data");
}
var gains = data.Where(x => x >= 0);
return gains.Mean();
return data.Where(x => x >= 0).Mean();
}
/// <summary>
@ -89,8 +86,7 @@ namespace MathNet.Numerics.Financial
throw new ArgumentNullException("data");
}
var losses = data.Where(x => x < 0);
return losses.Mean();
return data.Where(x => x < 0).Mean();
}
}
}

19
src/Numerics/Financial/AbsoluteRiskMeasures.cs

@ -28,13 +28,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Statistics;
namespace MathNet.Numerics.Financial
{
using System;
using System.Collections.Generic;
using System.Linq;
using Statistics;
public static class AbsoluteRiskMeasures
{
//Note: The following statistics would be condidered an absolute risk statistic in the finance realm as well.
@ -56,8 +56,7 @@ namespace MathNet.Numerics.Financial
throw new ArgumentNullException("data");
}
var gains = data.Where(x => x >= 0);
return gains.StandardDeviation();
return data.Where(x => x >= 0).StandardDeviation();
}
/// <summary>
@ -72,8 +71,7 @@ namespace MathNet.Numerics.Financial
throw new ArgumentNullException("data");
}
var losses = data.Where(x => x < 0);
return losses.StandardDeviation();
return data.Where(x => x < 0).StandardDeviation();
}
/// <summary>
@ -90,8 +88,7 @@ namespace MathNet.Numerics.Financial
throw new ArgumentNullException("data");
}
var belowMARData = data.Where(x => x < minimalAcceptableReturn);
return belowMARData.StandardDeviation();
return data.Where(x => x < minimalAcceptableReturn).StandardDeviation();
}
/// <summary>

18
src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -24,15 +28,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.Financial;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathNet.Numerics.Financial;
using NUnit.Framework;
[TestFixture]
[Category("FinancialTests")]
public class CompoundMonthlyReturnTests

20
src/UnitTests/FinancialTests/DownsideDeviationTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -24,15 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
[TestFixture]
[Category("FinancialTests")]
public class DownsideDeviationTests

20
src/UnitTests/FinancialTests/GainLossRatioTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -24,15 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
[TestFixture]
[Category("FinancialTests")]
public class GainLossRatioTests

18
src/UnitTests/FinancialTests/GainMeanTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -24,14 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests
{
using System;
using System.Collections.Generic;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
[TestFixture]
[Category("FinancialTests")]
public class GainMeanTests

20
src/UnitTests/FinancialTests/GainStandardDeviationTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -24,15 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
[TestFixture]
[Category("FinancialTests")]
public class GainStandardDeviationTests

18
src/UnitTests/FinancialTests/LossMeanTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -24,14 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests
{
using System;
using System.Collections.Generic;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
[TestFixture]
[Category("FinancialTests")]
public class LossMeanTests

20
src/UnitTests/FinancialTests/LossStandardDeviationTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -24,15 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
[TestFixture]
[Category("FinancialTests")]
public class LossStandardDeviationTests

20
src/UnitTests/FinancialTests/SemiDeviationTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -24,15 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.FinancialTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
[TestFixture]
[Category("FinancialTests")]
public class SemiDeviationTests

Loading…
Cancel
Save