diff --git a/src/Numerics/Financial/AbsoluteReturnMeasures.cs b/src/Numerics/Financial/AbsoluteReturnMeasures.cs index abd38630..e41d7220 100644 --- a/src/Numerics/Financial/AbsoluteReturnMeasures.cs +++ b/src/Numerics/Financial/AbsoluteReturnMeasures.cs @@ -28,13 +28,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +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 { /// @@ -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; } /// @@ -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(); } /// @@ -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(); } } } \ No newline at end of file diff --git a/src/Numerics/Financial/AbsoluteRiskMeasures.cs b/src/Numerics/Financial/AbsoluteRiskMeasures.cs index 560aecdc..3e156068 100644 --- a/src/Numerics/Financial/AbsoluteRiskMeasures.cs +++ b/src/Numerics/Financial/AbsoluteRiskMeasures.cs @@ -28,13 +28,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +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(); } /// @@ -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(); } /// @@ -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(); } /// diff --git a/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs b/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs index 1cbc23dc..5343c525 100644 --- a/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs +++ b/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. // +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 diff --git a/src/UnitTests/FinancialTests/DownsideDeviationTests.cs b/src/UnitTests/FinancialTests/DownsideDeviationTests.cs index d57075bf..2d990e0a 100644 --- a/src/UnitTests/FinancialTests/DownsideDeviationTests.cs +++ b/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. // +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 diff --git a/src/UnitTests/FinancialTests/GainLossRatioTests.cs b/src/UnitTests/FinancialTests/GainLossRatioTests.cs index 571345df..26720daf 100644 --- a/src/UnitTests/FinancialTests/GainLossRatioTests.cs +++ b/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. // +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 diff --git a/src/UnitTests/FinancialTests/GainMeanTests.cs b/src/UnitTests/FinancialTests/GainMeanTests.cs index c91d9460..62b3620f 100644 --- a/src/UnitTests/FinancialTests/GainMeanTests.cs +++ b/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. // +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 diff --git a/src/UnitTests/FinancialTests/GainStandardDeviationTests.cs b/src/UnitTests/FinancialTests/GainStandardDeviationTests.cs index d9dbc79b..18135649 100644 --- a/src/UnitTests/FinancialTests/GainStandardDeviationTests.cs +++ b/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. // +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 diff --git a/src/UnitTests/FinancialTests/LossMeanTests.cs b/src/UnitTests/FinancialTests/LossMeanTests.cs index 6646cc87..72bfaf2c 100644 --- a/src/UnitTests/FinancialTests/LossMeanTests.cs +++ b/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. // +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 diff --git a/src/UnitTests/FinancialTests/LossStandardDeviationTests.cs b/src/UnitTests/FinancialTests/LossStandardDeviationTests.cs index 27728703..39bd1723 100644 --- a/src/UnitTests/FinancialTests/LossStandardDeviationTests.cs +++ b/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. // +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 diff --git a/src/UnitTests/FinancialTests/SemiDeviationTests.cs b/src/UnitTests/FinancialTests/SemiDeviationTests.cs index 8f631f93..0b6bdcb8 100644 --- a/src/UnitTests/FinancialTests/SemiDeviationTests.cs +++ b/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. // +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