Question: Part 2: Stock Bookkeeping Write the function transact() as defined below, along with the docstring. This function should operate as the docstring describes. Please note,
Part 2: Stock Bookkeeping
Write the function transact() as defined below, along with the docstring. This function should operate as the docstring describes. Please note, you need to lookup pricing of a current day and column. Please choose any column you wish inside this function (e.g. close). You must not use test_data() to lookup pricing for the current day. This means transact() and test_data() must use a common function that looks up your stock pricing data after it has been loaded, and processed into memory.
def transact(funds, stocks, qty, day, buy=False, sell=False): """A bookkeeping function to help make stock transactions. Args: funds: An account balance, a float; it is a value of how much money you have, currently. stocks: An int, representing the number of stock you currently own. qty: An int, representing how many stock you wish to buy or sell. day: An integer reflecting the absolute number of the day in the data to look up, e.g. day 1, 15, or 1200 is row 1, 15, or 1200 in the file. buy: This option parameter, if set to true, will initiate a buy. sell: This option parameter, if set to true, will initiate a sell. Returns: Two values *must* be returned. The first (a float) is the new account balance (funds) as the transaction is completed. The second is the number of stock now owned (an int) after the transaction is complete. Error condition #1: If the `buy` and `sell` keyword parameters are both set to true, or both false. You *must* print an error message, and then return the `funds` and `stocks` parameters unaltered. This is an ambiguous transaction request! Error condition #2: If you buy, or sell without enough funds or stocks to sell, respectively. You *must* print an error message, and then return the `funds` and `stocks` parameters unaltered. This is an ambiguous transaction request! """
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
