Question: Language : Python Challenger Approaching You are working at a financial institution that is investing in a variety of stocks. It's the end of a
Language : Python
Challenger Approaching
You are working at a financial institution that is investing in a variety of stocks. It's the end of a trading year and your manager realizes that they have not been tracking the value of their stock portfolio and they are desperate to report this value as soon as possible. They decide to hand this task to you. You given several excel spreadsheets containing the price for each stock on each trading day throughout the year as well as a sheet containing all the trades that have been placed. These spreadsheets have been saved as CSV files. Your manager is very paranoid about leaking data so the full CSV files will not be shared with you, but your code will be executed on the full data set. NOTE: Each star in this prelab will only contain 1 question each and for the third star/question you will combine your previous two solutions to solve the entire problem. For the last start you will need to use your functions from the first two parts so save your code in Codenvy so you can easily paste them latter. Also, since there is only one question per star saving your code off-site will make it easy to paste your code and submit for credit after answering correct for the first time since you will always see the exact same question until you move to the next star. Part 1: 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. HINT: For each line read from the file you will either add a ticker symbol to the dictionary if it was the first time you've read that ticker, or update an existing key-value pair in your dictionary if you're reading a line for a ticker that has already been added to the dictionary. Be sure to not overwrite values that have already been added
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
