Question: Write a function named quantities_owned that takes one parameter that is a string representing a filename that contains all the trades made by your company
Write a function named "quantities_owned" that takes one parameter that is a string representing a filename that contains all the trades made by your company throughout the year and returns a dictionary containing the quantity of each stock owned by the company by ticker symbol. Each row of CSV file will contain a single trade in the format "buy_or_sell,quantity,ticker,date" where buy_or_sell is either the string "buy" or "sell", quantity is an integer representing the number of shares traded, ticker is a string representing the ticker symbol being traded, and date is the date of the trade in the format YYYY-MM-DD. This function will return a dictionary with ticker symbols as keys, and the number of shares of each ticker symbol owned as values as integers. In part 3 this dictionary will be used to lookup the number of shares owned for each stock/ticker symbol For example if the input file contains: buy,1700,XOM,2015-01-26 buy,1900,AAPL,2015-02-13 sell,700,XOM,2015-02-17 buy,700,AAPL,2015-02-17 Then the output would be {'AAPL': 2600, 'XOM':1000}. You should use this example, and some of your own, as test cases in Codenvy to verify that your code is working and help you debug if it is not.
(It is python)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
