Created
December 18, 2013 19:34
-
-
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.
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
# -*- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?