SHARE
TWEET

Untitled

barrick09 Nov 12th, 2019 (edited) 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def trade_action(current_shares, purchase_price, market_price, available_funds):
  2.     decision_action = calculate_action(current_shares, purchase_price, market_price, available_funds)  
  3.     number_of_shares = calculate_stock_number(decision_action)  
  4.     shares = str(number_of_shares)
  5.     if decision_action == "buy":
  6.         return print("Buy " + shares + " shares")
  7.     elif decision_action == "sell":
  8.         return print("Sell " + shares + " shares" )
  9.     else:
  10.         return "Hold shares"
  11.    
  12. def calculate_action(current_shares, purchase_price, market_price, available_funds):
  13.     if purchase_price > market_price:
  14.         if (available_funds - 10) / market_price >= 1:
  15.             if ((available_funds - 10) / market_price) * (purchase_price - market_price) > 10:
  16.                 decision_action = "buy"
  17.                 return (decision_action)
  18.     elif purchase_price < market_price:
  19.         if (market_price - purchase_price) * (current_shares / market_price) > 10:
  20.             decision_action = "sell"
  21.         return (decision_action)
  22.            
  23. def calculate_stock_number(decision_action):
  24.     number_of_shares = 0
  25.     if decision_action == "buy":
  26.        number_of_shares = (available_funds - 10) / market_price
  27.     return number_of_shares
  28.     if decision_action == "sell":
  29.        number_of_shares = current_shares
  30.     return number_of_shares
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top