Skip to content

Instantly share code, notes, and snippets.

@jmhobbs
Created December 18, 2013 19:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmhobbs/8028367 to your computer and use it in GitHub Desktop.
Save jmhobbs/8028367 to your computer and use it in GitHub Desktop.
I wanted to know when I would break even (including fees) on some bitcoins I bought on coinbase. So I built a brute force calculator.
# -*- coding: utf-8 -*-
BANK_FEE = 0.15
COINBASE_PCT = 0.01
def calculate_sale_profit(coins, price, purchase_cost):
value = round(coins * price, 2)
fee = BANK_FEE + round(value * COINBASE_PCT)
return (value - fee) - purchase_cost
def find_break_even(coins, purchase_cost):
# Start at approx. purchase value
current_value = round(purchase_cost / coins, 2)
while True:
profit = calculate_sale_profit(coins, current_value, purchase_cost)
if profit >= 0:
return current_value
current_value += 0.01
if __name__ == '__main__':
coins = float(raw_input('How many coins did you buy? '))
cost = float(raw_input('How much was the (total) cost? '))
print "Break even when 1 BTC == %0.02f" % find_break_even(coins, cost)
@blankpagestl
Copy link

I love the idea of this. And I'm sorry to ask this... but where would you use this? Is this a potential script for a google sheet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment