Last active
December 26, 2015 09:29
-
-
Save mattfitzgerald/7129700 to your computer and use it in GitHub Desktop.
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
# looking at a simple set of back prices ('payouts') | |
class Book | |
def initialize (payouts) | |
@payouts = payouts | |
end | |
def probabilities | |
@payouts.map{|p| 1.0/p} | |
end | |
def percentage | |
probabilities.inject(:+) | |
end | |
def is_green? | |
percentage < 1.0 | |
end | |
def breakeven_payout_on_nth_runner n | |
1.0/(1.0 - @payouts.inject(0){|sum,x| sum + 1.0/x} + 1.0/@payouts[n]) | |
end | |
def required_payouts | |
@payouts.each_with_index{|p,n| puts "#{p} => #{breakeven_payout_on_nth_runner(n)}"} | |
end | |
end | |
book = Book.new [5.0,5.0,5.0,5.0,4.0] | |
#book = Book.new [2.0,1.5] | |
puts book.probabilities.inspect | |
puts book.percentage | |
puts book.is_green? | |
puts book.required_payouts | |
# [0.2, 0.2, 0.2, 0.2, 0.25] | |
# 1.05 | |
# false | |
# 5.0 => 6.6666666666666705 | |
# 5.0 => 6.6666666666666705 | |
# 5.0 => 6.6666666666666705 | |
# 5.0 => 6.6666666666666705 | |
# 4.0 => 5.000000000000001 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment