Last active
August 16, 2022 03:44
-
-
Save harunorimurata/084495d888c441190a1a6dcf5dae327e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sharpeRatio(array, interest = 0) { | |
| if (array.length < 3) return { mean: 0, sd: 0, sharpeRatio: 0 }; | |
| let mean = 0, sqsum = 0, l = array.length; | |
| for (let n = 1; n < l; n++) { | |
| const changeRate = (array[n] - array[n - 1]) / array[n - 1]; | |
| const x = changeRate - mean; | |
| mean += x / n; | |
| sqsum += (n - 1) * x * x / n; | |
| } | |
| const sd = Math.sqrt(sqsum / (l - 1)); | |
| const sharpeRatio = (mean - interest) / sd; | |
| return { mean, sd, sharpeRatio }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment