Skip to content

Instantly share code, notes, and snippets.

@nsa-yoda
Last active September 17, 2015 14:43
Show Gist options
  • Save nsa-yoda/343f8716fe79fa22284a to your computer and use it in GitHub Desktop.
Save nsa-yoda/343f8716fe79fa22284a to your computer and use it in GitHub Desktop.
# Buy price is the float value of the market price of the stock in question
buy_price = 0.623
# Budget is your budget for this purchase
budget = 400
# Per trade fee is any fee that you pay your brokerage house per transaction
per_trade_fee = 9.99
# This is your minimum desired return
min_desired_return = 90.00
################################
## Do not edit below this line #
################################
def possible_purchase(buy_price, budget, per_trade_fee):
return int(((budget - per_trade_fee) / buy_price) )
def min_return(num_held, buy_price, min_desired_return, per_trade_fee):
actual_return = 0.0
sell_price = buy_price
while actual_return <= min_desired_return:
actual_return = (sell_price * num_held) - (buy_price * num_held) - per_trade_fee
sell_price += 0.01
return actual_return, sell_price, ((sell_price - buy_price)/(buy_price))
num_held = possible_purchase(buy_price, budget, per_trade_fee)
actual_return, sell_price, gain = min_return(num_held, buy_price, min_desired_return, per_trade_fee)
print "With budget of $%s, possible to own %i shares" % (format(budget, '.2f'), num_held)
print "Return of $%s from %i shares possible at $%s, representing gain of %f%%" \
% (format(actual_return, '.2f'), num_held, format(sell_price, '.4f'), gain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment