Skip to content

Instantly share code, notes, and snippets.

@julesjans
Last active August 17, 2017 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesjans/c8d9b5fd37ca9a4dd1ea3d5ba901abe9 to your computer and use it in GitHub Desktop.
Save julesjans/c8d9b5fd37ca9a4dd1ea3d5ba901abe9 to your computer and use it in GitHub Desktop.
Calculating hammer price to limit on auction with variable commission rates
BEFORE = 0.25 # Percent commission before the limit
LIMIT = 50000 # The commission boundary
AFTER = 0.20 # Percent after the boundary
# The only number to change is this one! No spaces, dots or commas...!
total_price_including_commssion = 10000000
# Warning - Do not use for bids over a £1,000,000 Hammer
def finds_the_total_price_including_commission(hammer)
if hammer < LIMIT
commission = BEFORE * hammer
else
commission = BEFORE * LIMIT
passed_limit = hammer - LIMIT
commission = commission + (AFTER * passed_limit)
end
return hammer + commission
end
def finds_the_hammer_price(total_price_including_commssion)
total_price_including_commssion.to_i.times do |count|
total = finds_the_total_price_including_commission(count)
if (total > (total_price_including_commssion - 1.0)) && (total < (total_price_including_commssion + 1.0))
return count
end
end
end
hammer_price = finds_the_hammer_price(total_price_including_commssion)
total_price = finds_the_total_price_including_commission(hammer_price)
puts "Hammer Price:\t\t#{hammer_price}"
puts "Commission:\t\t#{total_price - hammer_price}"
puts "Total Price:\t\t#{total_price}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment