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 submit_benchmark_returns(returns): benchmark_portfolio = Portfolio(date(2020, 1, 2)) benchmark_portfolio.add_holding(Holding("^GSPC", 1)) validation_benchmark_returns = portfolio_returns(benchmark_portfolio) if returns != validation_benchmark_returns: raise Exception("Returns don't match for S&P 500.") print( "{:.2f}% returns for your bencmark means your portfolio is performing well!" .format(returns))
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
""" import requests from portfolio import Portfolio, Holding, get_price, get_historical_price from lab1 import portfolio_value from lab3 import username from datetime import date filepath = 'portfolio.csv' validation_portfolio = Portfolio(date(2020, 1, 2)) validation_returns = 0.0 validation_benchmark_returns = 0.0 with open(filepath) as fp: lines = fp.readlines() for line in lines: validation_portfolio.add_holding(Holding(*line.split(','))) URL = "https://hmresj58ib.execute-api.us-east-1.amazonaws.com/production/trials" def submit_leaderboard(name, stage, completion): """Submits the results of a trial to the leaderboard api for recording. :param name: The name of the user submitting the trial. This will be used to display the user's results on the website. :param stage: an integer representing the stage of the challenge this submission pertains to. :param completion: a string summarizing the trial's results. It can be a a date, (if the goal of the stage is to complete it in the least amount of time) or it can be a string-encoded number (if the goal of the stage is to have the best-optimized result).