Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def trade_action(current_shares, purchase_price, market_price, available_funds):
- decision_action = calculate_action(current_shares, purchase_price, market_price, available_funds)
- number_of_shares = calculate_stock_number(decision_action)
- shares = str(number_of_shares)
- if decision_action == "buy":
- return print("Buy " + shares + " shares")
- elif decision_action == "sell":
- return print("Sell " + shares + " shares" )
- else:
- return "Hold shares"
- def calculate_action(current_shares, purchase_price, market_price, available_funds):
- if purchase_price > market_price:
- if (available_funds - 10) / market_price >= 1:
- if ((available_funds - 10) / market_price) * (purchase_price - market_price) > 10:
- decision_action = "buy"
- return (decision_action)
- elif purchase_price < market_price:
- if (market_price - purchase_price) * (current_shares / market_price) > 10:
- decision_action = "sell"
- return (decision_action)
- def calculate_stock_number(decision_action):
- number_of_shares = 0
- if decision_action == "buy":
- number_of_shares = (available_funds - 10) / market_price
- return number_of_shares
- if decision_action == "sell":
- number_of_shares = current_shares
- return number_of_shares
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement