def submit_portfolio_value(value): total = 0 for holding in validation_portfolio.holdings: total += int(holding.shares) * get_price(holding.symbol) if (round(value, 2) != 29525.85): raise Exception("The value of " + "{:2f}".format(value) + " doesn't add up") print("${:,.2f} is a good start! How does it compare?".format(value))
def submit_portfolio_value(value): filepath = 'portfolio.csv' total = 0 portfolio = Portfolio(date(2020, 1, 2)) with open(filepath) as fp: lines = fp.readlines() for line in lines: portfolio.add_holding(Holding(*line.split(','))) for holding in portfolio.holdings: total += int(holding.shares) * get_price(holding.symbol) if (round(value, 2) != 29525.85): raise Exception("The value of " + "{:2f}".format(value) + " doesn't add up") print("${:,.2f} is a good start! How does it compare?".format(value)) return True
def portfolio_value(portfolio: Portfolio): total = 0 for holding in portfolio.holdings: total += int(holding.shares) * get_price(holding.symbol) return total
""" At FactSet the first step of the portfolio lifecycle involves parsing clients' holdings into our portfolio databases. In this lab you are given an input file as comma separated values and calculating the portfolio's value. Each line has a symbol and number of shares. portfolio.py contains documentation for the portfolio object get_price(symbol) will return the latest closing price given a symbol portfolio.csv is the input file that's being parsed https://www.w3schools.com/python/ref_string_split.asp """ from portfolio import Portfolio, Holding, get_price from datetime import date filepath = 'portfolio.csv' def parse_portfolio(): portfolio = Portfolio(date(2020, 1, 2)) with open(filepath) as fp: lines = fp.readlines() for line in lines: portfolio.add_holding(Holding(*line.split(','))) return portfolio def portfolio_value(portfolio: Portfolio): total = 0