Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I NEED IT IN PYTHON ASAP PLEASEEEEE Many investment management companies are swi

ID: 3754074 • Letter: I

Question

I NEED IT IN PYTHON ASAP PLEASEEEEE

Many investment management companies are switching from manual stock trading (done by humans) to automatic stock trading (done by computers). You've been tasked to write a simple automatic stock trader function that determines whether to buy, sell, or do nothing (hold) shares of a stock for a particular account. It should follow the old saying "Buy low, sell high!"

This function must make the decision (to buy, sell, or hold) based on the following information.

1.Current number of shares of this stock in the account

2.Price (per share) paid for current stock in the account

3.Current market price (per share) of this stock

4.Maximum amount the client is willing to spend on a purchase

Additional information

Any transaction (buy or sell) costs $10. Be sure to account for this fee in your profitability calculations.

In order for a purchase (buy) to be considered profitable, the current market price (per share) must lower than the price (per share) paid for current stock in the account. Additionally, the amount the client is willing to spend on a purchase must allow us to buy enough shares so that the difference in value will cover the $10 transaction fee.

In order for a sale (sell) to be considered profitable, the current market price (per share) must be higher than the price (per share) paid for current stock in the account. Additionally, the value gained by selling the shares must also cover the $10 transaction fee.

If neither a buy nor a sell would be profitable, then we should simply hold the existing shares.

Part 2 - Implementation

Now that you have taken the time to analyze the problem and to sketch a design for a solution, it is time to begin implementing your design. Use the design that you created for Part 1 of this challenge and implement your design in the form of a function that also meets the following specifications.

1.This function will have 4 input parameters in the following order.

2. Current number of shares of this stock in the account (int)

3. Price (per share) paid for current stock in the account (float)

4. Current market price (per share) of this stock (float)

5. Maximum amount the client is willing to spend on a purchase (float)

The function will return a str with one of the following formats (where # is an integer representing the number of shares to buy or sell).

1.Buy # shares

2.Sell # shares

3. Hold shares

Things to think about

Look for opportunities to use variables as a way to name things, and to break larger more complex expressions down into simpler expressions.

Spend some time choosing your names carefully. Names should be descriptive.

Explanation / Answer

current_number_of_share=0

price_per_share_in_account=0.0

price_per_share_in_market=0.0

maximum_amount_allowed=0.0

number_of_shares=0.0

value=0.0

total_price_of_shares_in_account=0.0

def automatic_stock_trader(current_number_of_share,price_per_share_in_account,price_per_share_in_market,maximum_amount_allowed):

total_price_of_shares_in_account = current_number_of_share * price_per_share_in_account

if(price_per_share_in_account > price_per_share_in_market):

if(maximum_amount_allowed <= 10):

return "Hold shares"

else:

number_of_shares = maximum_amount_allowed/price_per_share_in_market

value = (price_per_share_in_account - price_per_share_in_market) * number_of_shares

if(value >= 10):

return "Buy " + str(number_of_shares) + " shares"

else:

return "Hold shares"

elif(price_per_share_in_account < price_per_share_in_market):

if(total_price_of_shares_in_account <= 10):

return "Hold shares"

else:

value = (price_per_share_in_market * price_per_share_in_account) * current_number_of_share

if(value >= 10):

return "Sell " + str(current_number_of_share) + " shares"

else:

return "Hold shares"

else:

return "Hold shares"

a = automatic_stock_trader(15,5,2,100) //Use this type to call the function with pre defined values

print(a)

You can also input values from the user and then pass these as parameters in the function.

Please give upvote if you get your answer and feel free to ask any question you have in comments.