Example #1
0
def stock_clear_cache_on_click(_nclicks, symbol):
    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock
    stock.clear_cached_files()
    del stock_cache[symbol]
    return 1
Example #2
0
def stock_projection_input_table_on_stock_update(
        n_clicks, n_years, estimated_growth, target_yield, target_pe,
        expected_dividends, projected_dividends_growth, symbol):

    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock
    stock.n_projection_years = int(n_years)
    stock.estimated_growth = float(estimated_growth) / 100.
    stock.target_yield = float(target_yield) / 100.
    stock.target_pe = float(target_pe)
    stock.expected_dividends = float(expected_dividends)
    stock.projected_dividends_growth = float(projected_dividends_growth) / 100.
    rows = []

    rows.append(
        html.Tr([
            html.Th("Projected price"),
            html.Td(round(stock.price_projection, 2))
        ]))
    rows.append(
        html.Tr([
            html.Th("Projected Total Dividends"),
            html.Td(round(stock.projected_dividend_earnings, 2))
        ]))
    rows.append(
        html.Tr(
            [html.Th("Target Price"),
             html.Td(round(stock.target_price, 2))]))
    rows.append(
        html.Tr(
            [html.Th("Current Price"),
             html.Td(round(stock.current_price, 2))]))
    # rows.append(html.Tr([html.Th("dividend"), html.Td(stock.projected_dividends_growth)]))
    return rows
Example #3
0
def update_stock_ratios_table(n_clicks, symbol):
    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock

    desired_keys = [
        'earnings-per-share-%s' % stock.currency,
        'dividends-%s' % stock.currency,
        'book-value-per-share-%s' % stock.currency,
        'free-cash-flow-per-share-%s' % stock.currency,
        'operating-cash-flow-growth-yoy',
        'free-cash-flow-growth-yoy',
        'shares',
        'operating-cash-flow-%s' % stock.currency,
        'free-cash-flow-%s' % stock.currency,
        'working-capital-%s' % stock.currency,
        'net-income-%s' % stock.currency,
        'revenue-%s' % stock.currency,
        'return-on-invested-capital',
        'return-on-equity',
        'debt-equity',
        'long-term-debt',
        'short-term-debt',
        'total-debt-%s' % stock.currency,
        'debt-per-earnings',
        'debt-per-bookvalue',
    ]
    existing_keys = set(list(stock.ratios))
    keys = [k for k in desired_keys if k in existing_keys]
    return fundamentals_to_table(stock.ratios[keys])
Example #4
0
def onsumbit_stock_rule1_summary_table(n_clicks, symbol):
    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock
    return [
        html.Tr([html.Th(s[0]), html.Td(s[1])])
        for s in stock.get_summary_info()
    ]
Example #5
0
def stock_projection_input_table_on_stock_update(n_clicks, symbol):

    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock

    rows = []
    default_input_kwargs = {
        "type": "number",
        "inputmode": "numeric",
    }

    n_years_input = dcc.Input(id='stock-projection-table-nyear-input',
                              value=stock.n_projection_years,
                              **default_input_kwargs)
    rows.append(html.Tr([html.Th("Projection years"), html.Td(n_years_input)]))

    eps_growth_input = dcc.Input(
        id='stock-projection-table-eps-growth-rate-input',
        value=round(stock.estimated_growth * 100., 2),
        **default_input_kwargs)
    rows.append(
        html.Tr([html.Th("Expected EPS growth %"),
                 html.Td(eps_growth_input)]))

    target_yield = dcc.Input(id='stock-projection-table-target-yield-input',
                             value=round(stock.target_yield * 100., 2),
                             **default_input_kwargs)
    rows.append(html.Tr([html.Th("Target yield %"), html.Td(target_yield)]))

    target_pe = dcc.Input(id='stock-projection-table-target-pe-input',
                          value=round(stock.target_pe, 1),
                          **default_input_kwargs)
    rows.append(html.Tr([html.Th("Target p/e"), html.Td(target_pe)]))

    expected_dividends = dcc.Input(
        id='stock-projection-table-expected-dividends-input',
        value=round(stock.expected_dividends, 2),
        **default_input_kwargs)
    rows.append(
        html.Tr([
            html.Th("Expected dividends %s" % stock.currency),
            html.Td(expected_dividends)
        ]))

    projected_dividends_growth = dcc.Input(
        id='stock-projection-table-projected-dividends-growth-input',
        value=round(stock.projected_dividends_growth * 100., 2),
        **default_input_kwargs)
    rows.append(
        html.Tr([
            html.Th("Expected dividends growth %"),
            html.Td(projected_dividends_growth)
        ]))

    return rows
Example #6
0
def update_price_graph(n_clicks, symbol):
    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock
    data = []
    try:
        data.append(
            go.Scatter(
                x=list(stock.historic_prices.index),
                y=stock.historic_prices['Close'],
                # text=dff[dff['Indicator Name'] == yaxis_column_name]['Country Name'],
                mode='lines',
                name="closing",
                marker={
                    'size': 5,
                    'opacity': 0.5,
                    'line': {
                        'width': 0.5,
                        'color': 'white'
                    }
                }))
    except:
        pass
    return {
        'data':
        data,
        'layout':
        go.Layout(xaxis={
            'title': "Date",
            'type': 'date'
        },
                  yaxis={
                      'title': "closing price (%s)" % stock.currency,
                      'type': 'linear'
                  },
                  margin={
                      'l': 40,
                      'b': 40,
                      't': 10,
                      'r': 40
                  },
                  hovermode='closest',
                  legend=dict(x=0.1,
                              y=1,
                              traceorder='normal',
                              font=dict(family='sans-serif',
                                        size=12,
                                        color='#000'),
                              bgcolor='rgba(0,0,0,0)')),
    }
Example #7
0
def main():
    parser = argparse.ArgumentParser(
        description='Create xls reports based on stock symbol')
    parser.add_argument('stock_symbols', nargs="+")

    args = parser.parse_args()
    out = []
    wb = xls.Workbook(write_only=True)
    ws = wb.create_sheet("summary")
    ws.append(Stock.get_summary_header_row())
    for symbol in args.stock_symbols:
        stock = Stock(symbol)
        stock.write_xls_report()
        stock.plot_growth_ratios()
        ws.append(stock.get_summary_row())
        print(list(stock.ratios.keys()))
        print(stock.ratios['short-term-debt'])
Example #8
0
def onadd_stock_company_name_label(n_clicks, symbol, selected_stocks):
    symbols = []
    if len(symbol.split(" ")) > 1:
        symbols = symbol.split(" ")
    if len(symbol.split(";")) > 1:
        symbols = symbol.split(";")
    if not symbols:
        symbols = [symbol]
    symbols = [s for s in symbols if symbol]
    for symbol in symbols:
        stock = stock_cache.get(symbol, Stock(symbol))
        if symbol not in stock_cache:
            stock_cache[symbol] = stock
    return dcc.Dropdown(id='screener-stock-selection',
                        options=get_available_stock_options(),
                        multi=True,
                        value=list(set(list(selected_stocks) + symbols)))
Example #9
0
def update_stock_ratios_summary_table(n_clicks, symbol):
    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock
    desired_keys = [
        'book-value-per-share-%s' % stock.currency,
        'earnings-per-share-%s' % stock.currency,
        'revenue-per-share-%s' % stock.currency,
        'operating-cashflow-per-share-%s' % stock.currency,
        'shares',
        'return-on-invested-capital',
        'return-on-equity',
        'long-term-debt',
        'debt-equity',
    ]

    existing_keys = set(list(stock.ratios))
    keys = [k for k in desired_keys if k in existing_keys]
    return fundamentals_to_table(stock.ratios[keys], n_years=8)
Example #10
0
def update_2d_graph(symbols, xkey, ykey, sizekey):

    data = []
    stocks = [stock_cache.get(symbol, Stock(symbol)) for symbol in symbols]
    if not stocks:
        max_area = 1
    elif len(stocks) > 1:
        max_area = max(*[stock.ratios[sizekey].iloc[-1] for stock in stocks])
    else:
        max_area = stocks[0].ratios[sizekey].iloc[-1]

    # max_area = 20000000
    for stock in stocks:
        if not xkey:
            x = []
        else:
            x = [stock.ratios[xkey].iloc[-1]]
        if not ykey:
            y = []
        else:
            y = [stock.ratios[ykey].iloc[-1]]
        data.append(
            go.Scatter(
                x=x,
                y=y,
                text=[stock.company_name],
                mode='line',
                name=stock.symbol,
                marker={
                    'sizemode': 'area',  #stock.ratios[sizekey].iloc[-1],
                    'sizeref': 2. * max_area / (40.**2),
                    'size': [stock.ratios[sizekey].iloc[-1]],
                    'sizemin': 4,
                    'opacity': 0.5,
                    'line': {
                        'width': 0.5,
                        'color': 'blue'
                    }
                }))
    return {
        'data':
        data,
        'layout':
        go.Layout(
            xaxis={
                'title': xkey,
                'type': 'linear'
            },
            yaxis={
                'title': ykey,
                'type': 'linear'
            },
            margin={
                'l': 40,
                'b': 40,
                't': 10,
                'r': 40
            },
            hovermode='closest',
            showlegend=False,
        ),
    }
Example #11
0
def onadd_stock_yaxis_options(symbols):
    stocks = [stock_cache.get(symbol, Stock(symbol)) for symbol in symbols]
    return get_ratio_axis_options()
Example #12
0
def onadd_stock_xaxis_options(symbols):
    print("updating x axis")
    stocks = [stock_cache.get(symbol, Stock(symbol)) for symbol in symbols]
    return get_ratio_axis_options()
Example #13
0
def update_growth_rate_graph(n_clicks, symbol):
    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock
    label_map = {
        'earnings-ps-growth': "Earnings per share",
        'book-value-ps-growth': "Book value per share",
        'revenue-ps-growth': "Revenue per share",
        'operating-cashflow-ps-growth': "Operating Cashflow per share"
    }

    growth_keys = [
        'earnings-ps-growth', 'book-value-ps-growth', 'revenue-ps-growth',
        'operating-cashflow-ps-growth'
    ]

    data = []
    for key in growth_keys:
        data.append(
            go.Scatter(
                x=list(stock.ratios[key].index),
                y=stock.ratios[key] * 100,
                # text=dff[dff['Indicator Name'] == yaxis_column_name]['Country Name'],
                mode='lines',
                name=label_map[key],
                marker={
                    'size': 15,
                    'opacity': 0.5,
                    'line': {
                        'width': 0.5,
                        'color': 'white'
                    }
                }))

    return {
        'data':
        data,
        'layout':
        go.Layout(xaxis={
            'title': "Date",
            'type': 'date'
        },
                  yaxis={
                      'title': "relative change (%)",
                      'type': 'linear'
                  },
                  margin={
                      'l': 40,
                      'b': 40,
                      't': 10,
                      'r': 40
                  },
                  hovermode='closest',
                  legend=dict(x=0.1,
                              y=1,
                              traceorder='normal',
                              font=dict(family='sans-serif',
                                        size=12,
                                        color='#000'),
                              bgcolor='rgba(0,0,0,0)')),
    }
Example #14
0
def onsumbit_stock_company_name_label(n_clicks, symbol):
    stock = stock_cache.get(symbol, Stock(symbol))
    if symbol not in stock_cache:
        stock_cache[symbol] = stock
    return u'{name}'.format(name=stock.company_name)