Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you tell me why this said No such file or directory:y.csv? Here is my code: def quantities_owned(filename): tran = {'buy': 1, 'sell': -1}

image text in transcribed

Can you tell me why this said " No such file or directory:"y.csv"?

Here is my code:

def quantities_owned(filename): tran = {'buy': 1, 'sell': -1} with open(filename) as f: reader = csv.reader(f) dicti = {} for row in reader: if row[2] in dicti: dicti[row[2]] += tran[row[0]] * int(row[1]) else: dicti[row[2]] = tran[row[0]] * int(row[1]) return dicti def read_prices(tickers): d = {} for ticker in tickers: with open(ticker + '.csv') as g: for date, price, _ in csv.reader(g): d.setdefault(ticker, {})[date] = float(price) return d def portfolio_value(filename): sum = 0 templist =[] with open(filename) as h: for line in h: templist = line[2] info = read_prices(templist) quantities = quantities_owned(filename) for i in info: price = int(info['2015-12-31']) sum = sum + price for j in quantities: quan = int(quantities['2015-12-31']) value = sumsum * quan return value
Reminder nf the data tcrmats: The input file wi b a CSV file with each row in the format 'buy or sellquantity ticker date"whre buy or sel is either the string buy" orlquantity is an integer reprrsenting the numbrr of shares traded, tirker is a string represcnting the ticker symbol bcing traded, and date is the date of the trade in the format WYY MMDO. You may assume there arc files named ctickers.csv for cach ticker symbol that the company trades. Each row of thesc CSV filcs will bc in the format date,price,volume" where date is in the format YYMM-DD, the price is a float, and volume is an integer representing the number of shares that were traded on that day by all traders oill not need the trading volume for this prelab) Part 3: Write a functicn named portfelio value 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 the total value of the portfolio on the date "2015-12-31 The total value is the sum of all the quantites of stock owned times the price for that stock at the end of the year reader csvresderf 0. 24. 1s4: rwurn dicti 1 der re pricec(tickers .dth pen(ticker-, ,esv.} 55 cl 22-def portfolie vel eifiienare bmit for errer on nput[rades: [2] No such file or directory:'y

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

What tools might be helpful?

Answered: 1 week ago