Created
October 1, 2019 18:54
-
-
Save dragthor/c40202cdfba2dd112d30d617417f843e to your computer and use it in GitHub Desktop.
option spread calculation
This file contains 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
var calc = function (itm_percent, credit_received, spread_with, multiplier) { | |
var win = 0; | |
var lose = 0; | |
for (var m = 0; m < multiplier; m++) { | |
for (var i = 0; i < 100; i++) { | |
// 0 -> 99 | |
var r = Math.floor(Math.random() * 100); | |
if (r < itm_percent) win++; | |
if (r >= itm_percent) lose++; | |
} | |
} | |
var gain = win * credit_received; | |
var loss = lose * (spread_with - credit_received); | |
return { | |
"winners": win, | |
"winrate" : win / (multiplier * 100), | |
"gain": gain, | |
"losers": lose, | |
"lossrate" : lose / (multiplier * 100), | |
"loss": loss, | |
"profit" : gain - loss | |
}; | |
} | |
calc(80, 20, 100, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment