예제 #1
0
def portfolio_cost(filename):
    """
    Computes the total cost (shares*price) of a portfolio file
    """
    portfolio = report.read_portfolio(filename)
    total_cost = sum(stock.cost for stock in portfolio)
    return portfolio.total_cost
예제 #2
0
def portfolio_cost(filename):
    '''
    Computes the total cost (shares*price) of a portfolio file
    '''

    portfolio = report.read_portfolio(filename)
    return sum([s['shares'] * s['price'] for s in portfolio])
예제 #3
0
def portfolio_cost(file):
    """     
    f = open(filename)
    rows = csv.reader(f)
    headers=next(rows)

    cost = 0

    for i, row in enumerate(rows):
        record = dict(zip(headers, row))
        # row = line.split(',')
        try:
            shares = int(record['shares'])
            price = float(record['price'])
            cost += shares*price
        except ValueError:
            print(f'Row {i}: Bad row {row}')
    """
    # Quote it out after building a portfolio class in Exercise 6.2
    """     
    portdicts = fileparse.parse_csv(file, select=['name','shares','price'],types=[str, int, float])
    # print(portfolio)
    cost = 0
    portfolio = [stock.Stock(d['name'],d['shares'],d['price']) for d in portdicts]
    for s in portfolio:
        cost += s.shares*s.price 
    """
    
    portfolio = report.read_portfolio(file)

    return portfolio.total_cost
예제 #4
0
def portfolio_cost(filename):
    '''gets a csv file of the shares, their qunatity and value
    returns the total cost for buying them all
    has a header which should be nexted
    '''
    portfolio = report.read_portfolio(filename)
    return portfolio.total_cost
예제 #5
0
def portfolio_cost(filename):
    portfolio = read_portfolio(filename)

    cost = 0;
    for item in portfolio:
        cost += item['shares'] * item['price']
    return cost
예제 #6
0
def portfolio_cost(filename):
    'Use csv module to print total cost of portfolio.'
    total_cost = 0
    portfolio = read_portfolio(filename)
    for s in portfolio:
        total_cost += s.cost
    print('Total cost:', round(total_cost, 2))
예제 #7
0
def protfolio_cost(name) -> float:
    '''
    Calculate the cost of portfolio
    '''
    stocks = read_portfolio(name)
    portfolio = Portfolio(stocks)
    return portfolio.cost_shares
예제 #8
0
def portfolio_cost(filename):
    '''
    Computes the total cost (shares*price) of a portfolio file
    '''
    portfolio = report.read_portfolio(filename)
    # return sum([s.shares * s.price for s in portfolio])
    return portfolio.total_cost
예제 #9
0
def portfolio_cost(filename: str) -> float:
    """Returns the total cost of the portfolio"""

    portfolio = read_portfolio(filename)
    total_cost = 0
    for asset in portfolio:
        total_cost += asset['shares'] * asset['price']
    return total_cost
예제 #10
0
def ticker(portfile, logfile, fmt):
    portfolio = read_portfolio(portfile)
    rows = parse_stock_data(follow(logfile))
    rows = (row for row in rows if row['name'] in portfolio)
    formatter = tableformat.create_formatter(fmt)
    formatter.headings(['Name', 'Price', 'Change'])
    for row in rows:
        formatter.row([row['name'], f"{row['price']:0.2f}", f"{row['change']:0.2f}"])
예제 #11
0
def portfolio_cost(filename):
    import csv
    import report
    Total_Cost = 0.0
    record = report.read_portfolio(filename)
    for row in record:
        Total_Cost = Total_Cost + (int(row['shares']) * float(row['price']))
    return Total_Cost
예제 #12
0
def portfolio_cost(filename):
    total_cost = 0
    records = report.read_portfolio(filename)
    for record in records:
        nshares = int(record['shares'])
        price = float(record['price'])
        total_cost += nshares * price
    return total_cost
예제 #13
0
def portfolio_cost(filename):
    total_cost = 0
    portfolio = report.read_portfolio(filename)
    for rows in portfolio:
        nshares = int(rows['shares'])
        price = float(rows['price'])
        total_cost += nshares * price
    return total_cost
예제 #14
0
def main(argv):
    # Parse command line args, environment, etc.
    print(argv)
    if len(argv) != 2:
        raise SystemExit(f'Usage: {argv[0]} ' 'portfile')
    portfile = argv[1]
    portfolio = report.read_portfolio(portfile)
    # Calculate total cost of the portfolio
    portfolio_total_cost = portfolio_cost(portfolio)
예제 #15
0
def main(args: list):
    if args:
        filename = args[0]
    else:
        filename = '../Data/portfolio.csv'

    portfolio = report.read_portfolio(filename)
    total_cost = portfolio.total_cost
    print('total_cost=', total_cost)
예제 #16
0
def ticker(portfile,logfile,fmt):
    portfolio = report.read_portfolio(portfile)
    lines = follow(logfile)
    rows = parse_stock_data(lines)
    rows = filter_symbols(rows, portfolio)
    formatter = tableformat.create_formatter(fmt)
    formatter.headings(['Name','Price','Change'])
    for row in rows:
        formatter.row([ row['name'], f"{row['price']:0.2f}",f"{row['change']:0.2f}" ])
예제 #17
0
def ticker(port, stream, fmt):
    port = read_portfolio(port)
    rows = parse_stock_data(follow(stream))
    fmt = create_formatter(fmt)
    rows = filter_symbols(rows, port)

    fmt.headings(['Name', 'Price', 'Change'])
    for row in rows:
        fmt.row(tuple(row.values()))
예제 #18
0
def portfolio_cost(filename):
    """
    Return the total cost of a stock portfolio CSV file.

    """

    portfolio = read_portfolio(filename)

    return portfolio.total_cost
예제 #19
0
def ticker(portfile, logfile, fmt):
    headers = ['name', 'price', 'change']
    portfolio = report.read_portfolio(portfile)
    rows = parse_stock_data(follow(logfile), portfolio, headers)
    formatter = tableformat.create_formatter(fmt)
    formatter.headings(headers)
    for row in rows:
        formatter.row(
            [row['name'], f"{row['price']:0.2f}", f"{row['change']:0.2f}"])
예제 #20
0
def ticker(portfile, logfile, fmt):
    lines = follow(logfile)
    portfolio = read_portfolio(portfile)
    rows = parse_stock_data(lines)
    rows = filter_names(rows, portfolio)
    formatter = tableformat.create_formatter(fmt)
    formatter.headings(['Name', 'Price', 'Change'])
    for row in rows:
        formatter.row((row['Name'], str(row['Price']), str(row['Change'])))
예제 #21
0
def ticker(portfolio_path, logfile, fmt):
    portfolio = report.read_portfolio(portfolio_path)
    lines = follow(logfile)
    rows = parse_stock_data(lines)

    formatter = create_formatter(fmt)

    formatter.headings(['Name', 'Price', 'Change'])
    for row in rows:
        formatter.row(row)
예제 #22
0
def portfolio_value(filename):
    """
    Function to calculate the total portfolio value.
    Input of type string defining a file location.
    File at file location of the form nx3 (stock name,
    stock price, total shares owned),
    """

    port = report.read_portfolio(filename)
    return sum([s['shares'] * s['price'] for s in port])
예제 #23
0
def portfolio_cost(filename):
    cost = 0
    portfolio = report.read_portfolio(filename)
    return portfolio.total_cost
    for record in records:
        try:
            cost += record.cost
        except ValueError:
            print(f"Row {i}: Bad row: {row}")
    return cost
예제 #24
0
def ticker(portfile, logfile, fmt):
    portfolio = report.read_portfolio(portfile)
    lines = follow(logfile)
    rows = parse_stock_data(lines)
    rows = (row for row in rows
            if row['name'] in portfolio)  # substitute filter_symbols()
    formatter = tableformat.create_formatter(fmt)
    formatter.headings('Name Price Change'.split())
    for row in rows:
        formatter.row(
            [row['name'], f"{row['price']:0.2f}", f"{row['change']:0.2f}"])
예제 #25
0
def ticker(portfile, logfile, fmt):
    import report
    import tableformat

    portfolio = report.read_portfolio(portfile)
    rows = parse_stock_data(follow(logfile))
    rows = filter_symbols(rows, portfolio)
    fmt = tableformat.create_formatter(fmt)
    fmt.headings(["Name", "Price", "Change"])
    for row in rows:
        fmt.row([row["name"], str(row["price"]), str(row["change"])])
예제 #26
0
def ticker(portfile, logfile, fmt):
    import report
    portfolio = report.read_portfolio(portfile)
    rows = parse_stock_data(follow(logfile))
    rows = (row for row in rows if row["name"] in portfolio)
    import tableformat
    formatter = tableformat.create_formatter(fmt)
    formatter.headings(["Name", "Price", "Change"])
    for row in rows:
        formatter.row(
            [row['name'], f"{row['price']:0.2f}", f"{row['change']:0.2f}"])
예제 #27
0
def ticker(portfile, logfile, fmt):
    names = ['name', 'price', 'change']
    portfolio = report.read_portfolio(portfile)
    rows = parse_stock_data(follow(logfile))
    rows = select_columns(rows, [0, 1, 4])
    rows = make_dicts(rows, names)
    rows = filter_symbols(rows, portfolio)
    formatter = create_formatter(fmt)
    formatter.headings([name.title() for name in names])
    for row in rows:
        formatter.row([row['name'], row['price'], row['change']])
예제 #28
0
def main():
    import report
    portfolio = report.read_portfolio('Data/portfolio.csv')

    for line in follow('Data/stocklog.csv'):
        fields = line.split(',')
        name = fields[0].strip('"')
        price = float(fields[1])
        change = float(fields[4])
        if name in portfolio:
            print(f'{name:>10s} {price:>10.2f} {change:>10.2f}')
예제 #29
0
def portfolio_cost(filename):
    try:
        tot_cost = 0

        portfolio = report.read_portfolio(filename)

        return sum([s['shares'] * s['price'] for s in portfolio])

    except ValueError:
        print("Missing Data, clean the file")
        print(f'Row {rowno}: Bad row: {line}')
예제 #30
0
def ticker(portfile, logfile, fmt):
    formatter = tableformat.create_formatter(fmt)
    formatter.headings(['Name', 'Price', 'Change'])

    portfolio = report.read_portfolio('Data/portfolio.csv')
    rows = parse_stock_data(follow('Data/stocklog.csv'))

    holdings = (row for row in rows if row['name'] in portfolio)

    for stock in holdings:
        formatter.row(
            [stock['name'], f"{stock['price']:0.2f}", f"{stock['change']:0.2f}"])