Ejemplo n.º 1
0
def get_stock_symbol_with_highest_cap():
    """Return the stock symbol (e.g. PACD) with the highest cap, use
       the _cap_str_to_mln_float to parse the cap values"""
    sorted_cap = sorted(data,
                        key=lambda data: _cap_str_to_mln_float(data["cap"]),
                        reverse=True)
    return sorted_cap[0]["symbol"]
Ejemplo n.º 2
0
def get_industry_cap(industry):
    """Return the sum of all cap values for given industry, use
       the _cap_str_to_mln_float to parse the cap values,
       return a float with 2 digit precision"""
    sum_cap_industry = sum(
        _cap_str_to_mln_float(datum["cap"]) for datum in data
        if industry == datum["industry"])
    return round(sum_cap_industry, 2)
def get_industry_cap(industry):
    """Return the sum of all cap values for given industry, use
       the _cap_str_to_mln_float to parse the cap values,
       return a float with 2 digit precision"""
    industry_cap = sum([
        _cap_str_to_mln_float(item['cap']) for item in data
        if item['industry'] == industry
    ])
    return round(industry_cap, 2)
def get_sectors_with_max_and_min_stocks():
    """Return a tuple of the sectors with most and least stocks,
       discard n/a"""
    stocks = defaultdict(default_stock_cap)
    for stock in data:
        sector = stock['sector']
        cap = stock['cap']
        stocks[sector] += _cap_str_to_mln_float(cap)
    min_ = min(stocks, key=stocks.get)
    max_ = max(stocks, key=stocks.get)
    return (max_, min_)
Ejemplo n.º 5
0
def test_cap_str_to_mln_float():
    assert _cap_str_to_mln_float('n/a') == 0
    assert _cap_str_to_mln_float('$100.45M') == 100.45
    assert _cap_str_to_mln_float('$20.9B') == 20900
Ejemplo n.º 6
0
def test_cap_str_to_mln_float():
    assert _cap_str_to_mln_float("n/a") == 0
    assert _cap_str_to_mln_float("$100.45M") == 100.45
    assert _cap_str_to_mln_float("$20.9B") == 20900
def get_stock_symbol_with_highest_cap():
    """Return the stock symbol (e.g. PACD) with the highest cap, use
       the _cap_str_to_mln_float to parse the cap values"""
    filtered_stock = max(data, key=lambda i: _cap_str_to_mln_float(i['cap']))
    return filtered_stock['symbol']