Beispiel #1
0
def on_stock_update(n_clicks,
                    symbol):
    stock = stock_cache.get(symbol, Stock(symbol))
    stock_projection_input_table_output = stock_projection_input_table_on_stock_update(stock)
    stock_ratios_table_output = update_stock_ratios_table(stock)
    stock_company_name_output = onsumbit_stock_company_name_label(stock)
    return stock_ratios_table_output, stock_company_name_output
Beispiel #2
0
def update_stock_ratios_table(n_clicks, symbol):
    print('update_stock_ratios_table')
    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]) + [
        html.Tr([html.Th("Error"), html.Td(e)]) for e in stock.error_log
    ]
Beispiel #3
0
def lambda_handler(event, context):
    watch_list = get_watch_list()
    for item in watch_list:
        print(item['user_name'] + '  ' + item['company'])
        stock = stock_cache.get(item['company'], Stock(item['company']))
        watch_list_item = {
            'projection_years':
            stock.n_projection_years,
            'excpected_eps':
            round(stock.estimated_growth * 100., 2),
            'target_yield':
            round(stock.target_yield * 100., 2),
            'target_p_e':
            round(stock.target_pe, 1),
            'expected_dividends':
            round(stock.expected_dividends, 2),
            'expected_dividends_growth':
            round(stock.projected_dividends_growth * 100., 2),
            #'projected_price': projected_price,
            #'projected_total_dividends': projected_total_dividends,
            #'target_price':  target_price,
            #'current_price':  current_target_price,
            'alert_price':
            round(stock.target_price, 2)
        }
        try:
            userInfo = UserInfo(item['user_name'])
            if 'alert_price' in item and not pd.isna(
                    stock.current_price) and stock.current_price < float(
                        item['alert_price']):
                if not 'last_mail_sent' in item or datetime.utcnow(
                ) - timedelta(days=14) > datetime.fromisoformat(
                        item['last_mail_sent']):
                    #datetime.datetime.now()-datetime.timedelta(seconds=20)
                    email = getUserEmail(userInfo, item['user_name'])
                    send_mail(email, item['company'], item['company_name'])
                    item['last_mail_sent'] = datetime.utcnow().isoformat()
            #item['target_price'] = Decimal(str(round(stock.target_price,2)))
            #item['projected_price'] = Decimal(str(round(stock.projected_price,2)))
            if not pd.isna(stock.current_price):
                item['current_price'] = Decimal(
                    str(round(stock.current_price, 2)))
            new_epsTTM = Decimal(
                str(
                    round(
                        stock.ratios["earnings-per-share-%s" %
                                     stock.currency].iloc[-1], 2)))
            if not pd.isna(new_epsTTM) and item['epsTTM'] != new_epsTTM:
                email = getUserEmail(userInfo, item['user_name'])
                send_change_eps_mail(email, item['company'],
                                     item['company_name'], item['epsTTM'],
                                     new_epsTTM)
                item['epsTTM'] = new_epsTTM

            userInfo.put_company_to_watch_list(item)
        except Exception as e:
            print(item)
            print(e)
    print("TaskScheduler")
    return 200
Beispiel #4
0
def stock_clear_cache_on_click(_nclicks, symbol):
    print(symbol + '- stock_clear_cache_on_click')
    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
Beispiel #5
0
def onsumbit_stock_company_name_label(n_clicks, symbol):
    print('onsumbit_stock_company_name_label')
    print(symbol)
    stock = stock_cache.get(symbol, Stock(symbol))
    #sprint(stock.company_name())
    if symbol not in stock_cache:
        stock_cache[symbol] = stock
    return u'{name}'.format(name=stock.company_name)
Beispiel #6
0
def onsumbit_stock_rule1_summary_table(n_clicks, symbol):
    print('onsumbit_stock_rule1_summary_table')
    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()
    ]
def get_layout(company):
    stock = stock_cache.get(company, Stock(company))

    stock_company_name_output = onsumbit_stock_company_name_label_raw(stock)

    ratios_df = stock.load_report_csv_to_original_df('ratios')
    ratios_table = dbc.Table.from_dataframe(ratios_df)

    balancesheet_df = stock.load_report_csv_to_original_df('balancesheet')
    balancesheet_table = dbc.Table.from_dataframe(balancesheet_df)

    cashflow_df = stock.load_report_csv_to_original_df('cashflow')
    cashflow_table = dbc.Table.from_dataframe(cashflow_df)

    income_df = stock.load_report_csv_to_original_df('income')
    income_table = dbc.Table.from_dataframe(income_df)

    layout = html.Div([
        html.Div([
            html.Div([
                dcc.Input(
                    id='stock-symbol-input-raw', type="text", value=company),
                html.Button(id='submit-button-raw',
                            children='Submit',
                            style={'backround': 'white'})
            ],
                     style={
                         'width': '49%',
                         'display': 'inline-block'
                     }),
            html.Div([
                html.Div(id='stock-company-name-label_raw',
                         children=stock_company_name_output,
                         style={'fontSize': 14})
            ],
                     style={
                         'width': '49%',
                         'display': 'inline-block',
                     }),
        ],
                 style={
                     'position': 'sticky',
                     'top': '90px',
                     'background': 'white'
                 }),
        html.Div(id='fundamental-redirect-raw'),
        html.H1("Income:"), income_table,
        html.H1("Balancesheet:"), balancesheet_table,
        html.H1("Cashflow:"), cashflow_table,
        html.H1("Ratios:"), ratios_table
    ],
                      style={
                          'padding': '10px',
                          'margin-right': '10px'
                      })
    return layout
Beispiel #8
0
def update_price_graph(n_clicks, symbol):
    print('update_price_graph')
    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)')),
    }
Beispiel #9
0
def stock_projection_output_table_on_stock_update(
    n_clicks,
    # n_years,
    # estimated_growth,
    # target_yield,
    # target_pe,
    # expected_dividends,
    #projected_dividends_growth,
    symbol):
    print('stock_projection_output_table_on_stock_update')
    stock = stock_cache.get(symbol, Stock(symbol))
    try:
        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))
            ]))
    except Exception as e:
        print("Error" + str(e))
        #raise
        return []
    return rows
Beispiel #10
0
def update_stock_ratios_summary_table(n_clicks, symbol):
    print('update_stock_ratios_summary_table')
    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',
        '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], n_years=8)
Beispiel #11
0
def 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))
    stock_projection_input_table_output = stock_projection_input_table_on_stock_update(
        n_clicks, symbol)
    stock_ratios_summary_table_output = update_stock_ratios_summary_table(
        n_clicks, symbol)
    stock_ratios_table_output = update_stock_ratios_table(n_clicks, symbol)
    stock_company_name_output = onsumbit_stock_company_name_label(
        n_clicks, symbol)
    stock_rule1_summary_table_output = onsumbit_stock_rule1_summary_table(
        n_clicks, symbol)
    growth_rate_graph = update_growth_rate_graph(n_clicks, symbol)
    price_graph_output = update_price_graph(n_clicks, symbol)
    return stock_projection_input_table_output, stock_ratios_summary_table_output, stock_ratios_table_output, stock_company_name_output, stock_rule1_summary_table_output, growth_rate_graph, price_graph_output
Beispiel #12
0
def update_growth_rate_graph(n_clicks, symbol):
    print('update_growth_rate_graph')
    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:
        try:
            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'
                        }
                    }))
        except:
            pass
    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)')),
    }
Beispiel #13
0
def stock_projection_input_table_on_stock_update(n_clicks, symbol):
    print('stock_projection_input_table_on_stock_update')
    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)]))

    try:
        value = round(stock.estimated_growth * 100., 2)
    except Exception as e:
        print("Error:" + str(e))
        raise
        value = 0
    eps_growth_input = dcc.Input(
        id='stock-projection-table-eps-growth-rate-input',
        value=value,
        **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)]))

    try:
        value = round(stock.target_pe, 1)
    except Exception as e:
        print("Error" + str(e))
        raise
        value = 0
    target_pe = dcc.Input(id='stock-projection-table-target-pe-input',
                          value=value,
                          **default_input_kwargs)
    rows.append(html.Tr([html.Th("Target p/e"), html.Td(target_pe)]))

    try:
        value = round(stock.expected_dividends, 2)
    except Exception as e:
        print("Error:" + str(e))
        raise
        value = 0
    expected_dividends = dcc.Input(
        id='stock-projection-table-expected-dividends-input',
        value=value,
        **default_input_kwargs)
    rows.append(
        html.Tr([
            html.Th("Expected dividends %s" % stock.currency),
            html.Td(expected_dividends)
        ]))

    try:
        value = round(stock.projected_dividends_growth * 100., 2)
    except Exception as e:
        print("Error:" + str(e))
        raise
        value = 0
    projected_dividends_growth = dcc.Input(
        id='stock-projection-table-projected-dividends-growth-input',
        value=value,
        **default_input_kwargs)
    rows.append(
        html.Tr([
            html.Th("Expected dividends growth %"),
            html.Td(projected_dividends_growth)
        ]))

    return rows