title: calculating sharpe ratio in java
body: <p>I am trying to calculate sharpe ratio in java, but I am struggling to find a "correct" dataset and result to test</p>
  
  <p>Refering to <a href="http://www.hedgeco.net/blogs/2008/07/30/explaining-the-sharpe-ratio-again/" rel="nofollow noreferrer">http://www.hedgeco.net/blogs/2008/07/30/explaining-the-sharpe-ratio-again/</a></p>
  
  <p>Investment Monthly Returns</p>
  
  <pre><code>Jan   Feb   Mar   Apr   May    June  Jul    Aug  Sep    Oct    Nov  Dec
  1.64  5.85  9.22  3.51  -0.88  1.07  13.03  9.4  10.49  -5.08  n/a  n/a
  </code></pre>
  
  <p>Risk Free Rate 5%</p>
  
  <p>However, I could not get what he got (2.56, instead I got 2.67 rounding error?)</p>
  
  <p>Is this the right way (or commonly accepted way) to compute sharpe ratio?</p>
  
  <p>My code (statistics computed using apache-commons-math)</p>
  
  <pre><code>    DescriptiveStatistics stats = new DescriptiveStatistics();
      for( double item : returns) {
          stats.addValue(item);
      }
  
      double mean = stats.getMean();
  
      double std = stats.getStandardDeviation();
  
      double sharpeRatio = (mean - (riskFreeReturn/12) ) / std * Math.sqrt(12);
  
      System.out.println("sharpeRatio="+ sharpeRatio);
  </code></pre>