Browse Source

Financial: tweaks, add to portable build

v2
Christoph Ruegg 14 years ago
parent
commit
043de9838e
  1. 5
      src/Numerics/Financial/AbsoluteReturnMeasures.cs
  2. 32
      src/Numerics/Financial/AbsoluteRiskMeasures.cs
  3. 6
      src/Portable/Portable.csproj

5
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-2010 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
@ -33,8 +33,7 @@ namespace MathNet.Numerics.Financial
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using Statistics;
using MathNet.Numerics.Statistics;
public static class AbsoluteReturnMeasures public static class AbsoluteReturnMeasures
{ {

32
src/Numerics/Financial/AbsoluteRiskMeasures.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-2010 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
@ -33,8 +33,7 @@ namespace MathNet.Numerics.Financial
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using Statistics;
using MathNet.Numerics.Statistics;
public static class AbsoluteRiskMeasures public static class AbsoluteRiskMeasures
{ {
@ -60,10 +59,6 @@ namespace MathNet.Numerics.Financial
} }
var gains = data.Where(x => x >= 0); var gains = data.Where(x => x >= 0);
var count = gains.Count();
if (count == 0 || count == 1)
return double.NaN;
return gains.StandardDeviation(); return gains.StandardDeviation();
} }
@ -82,10 +77,6 @@ namespace MathNet.Numerics.Financial
} }
var losses = data.Where(x => x < 0); var losses = data.Where(x => x < 0);
var count = losses.Count();
if (count == 0 || count == 1)
return double.NaN;
return losses.StandardDeviation(); return losses.StandardDeviation();
} }
@ -106,12 +97,8 @@ namespace MathNet.Numerics.Financial
throw new ArgumentNullException("data"); throw new ArgumentNullException("data");
} }
var belowMARdata = data.Where(x => x < minimalAcceptableReturn); var belowMARData = data.Where(x => x < minimalAcceptableReturn);
var count = belowMARdata.Count(); return belowMARData.StandardDeviation();
if (count == 0 || count == 1)
return double.NaN;
return belowMARdata.StandardDeviation();
} }
/// <summary> /// <summary>
@ -127,11 +114,8 @@ namespace MathNet.Numerics.Financial
throw new ArgumentNullException("data"); throw new ArgumentNullException("data");
} }
var belowMeanData = data.Where(x => x < data.Mean()); var mean = data.Mean();
var count = belowMeanData.Count(); var belowMeanData = data.Where(x => x < mean);
if (count == 0 || count == 1)
return double.NaN;
return belowMeanData.StandardDeviation(); return belowMeanData.StandardDeviation();
} }
@ -150,11 +134,7 @@ namespace MathNet.Numerics.Financial
var gains = data.Where(x => x >= 0); var gains = data.Where(x => x >= 0);
var losses = data.Where(x => x < 0); var losses = data.Where(x => x < 0);
var lossMean = losses.Mean();
return Math.Abs(gains.Mean() / losses.Mean()); return Math.Abs(gains.Mean() / losses.Mean());
} }
} }
} }

6
src/Portable/Portable.csproj

@ -192,6 +192,12 @@
<Compile Include="..\Numerics\Distributions\Multivariate\Wishart.cs"> <Compile Include="..\Numerics\Distributions\Multivariate\Wishart.cs">
<Link>Distributions\Multivariate\Wishart.cs</Link> <Link>Distributions\Multivariate\Wishart.cs</Link>
</Compile> </Compile>
<Compile Include="..\Numerics\Financial\AbsoluteReturnMeasures.cs">
<Link>Financial\AbsoluteReturnMeasures.cs</Link>
</Compile>
<Compile Include="..\Numerics\Financial\AbsoluteRiskMeasures.cs">
<Link>Financial\AbsoluteRiskMeasures.cs</Link>
</Compile>
<Compile Include="..\Numerics\GlobalizationHelper.cs"> <Compile Include="..\Numerics\GlobalizationHelper.cs">
<Link>GlobalizationHelper.cs</Link> <Link>GlobalizationHelper.cs</Link>
</Compile> </Compile>

Loading…
Cancel
Save