Exemple #1
0
def main():
    log.info("Started...")
    db = database2()
    rpt = report()
    
    formats = [ rpt.CONST_FORMAT_NONE, rpt.CONST_FORMAT_CCY, rpt.CONST_FORMAT_CCY, rpt.CONST_FORMAT_CCY, rpt.CONST_FORMAT_CCY_COLOR]
    table = [
        [ "Category", "Spent", "Projected", "Budget", "Tracking" ],
        ]
    append_budget_row( db, table, "Base", [0,2,3,4,5,8,12,96], 65000 )
    append_budget_row( db, table, "Rent", [1], 48000 )
    append_budget_row( db, table, "Travel", [7], 10000 )
    append_budget_row( db, table, "Helper", [9], 12000 )
    append_budget_row( db, table, "Monchichi", [94], 12000 )
    append_budget_row( db, table, "Deux", [93], 1000 )
    append_budget_row( db, table, "Fumi", [11], 5000 )
    append_budget_row( db, table, "Mike", [6,10], 5000 )
    append_budget_row( db, table, "Special", [95,97,98,99], 0 )
    append_budget_row( db, table, "Total", [0,1,2,3,4,5,6,7,8,9,10,11,12,93,94,95,96,97,98,99], 158000 )
    recon_projected = calculate_recon_projected( table, [2,3,4,5,7,8], 1, 6, 2, 4 )
    table.append( [ "Recon", db.get_ytd_spending_sum(), recon_projected, 158000, 158000 - recon_projected ] )
    fumi_projected = calculate_fumi_projected( table, 1, 6, 4 )
    table.append( [ "Payout", 0, fumi_projected, 0, 0 ] )
    rpt.add_table(table, formats)

    subject = 'Spending Report - ' + strftime("%Y-%m-%d", localtime())
     
    send_mail_html_self(subject, rpt.get_html())
    log.info("Completed")
Exemple #2
0
def main():
    log.info("Started...")
    db = database2()
    d = date(2019, 11, 27)

    pos_hsbc = db.get_balance_history(db.CONST_BALANCES_TYPE_HSBC, d)
    pos_vb = db.get_balance_history(db.CONST_BALANCES_TYPE_VIRTUAL_BANK, d)
    pos_jpy = db.get_balance_history(db.CONST_BALANCES_TYPE_JPY, d)
    neg_owe_portfolio = db.get_balance_history(
        db.CONST_BALANCES_TYPE_OWE_PORTFOLIO, d)
    neg_amex_cx = db.get_balance_history(db.CONST_BALANCES_TYPE_AMEX_CX, d)
    neg_capital_one = db.get_balance_history(
        db.CONST_BALANCES_TYPE_CAPITAL_ONE, d)
    neg_hsbc_visa = db.get_balance_history(db.CONST_BALANCES_TYPE_HSBC_VISA, d)
    budget_recon = (pos_hsbc + pos_vb + pos_jpy) - (
        neg_owe_portfolio + neg_amex_cx + neg_capital_one + neg_hsbc_visa)

    paid = db.get_balance_history(db.CONST_BALANCES_TYPE_PAID, d)
    tax = db.get_balance_history(db.CONST_BALANCES_TYPE_TAX, d)
    savings = db.get_balance_history(db.CONST_BALANCES_TYPE_SAVINGS, d)
    spending = paid - tax - savings - (budget_recon - CONST_BUDGET_UNIT)

    recon = spending - db.get_ytd_spending_sum_by_date(d)

    log.info(recon)
    log.info("Completed")
Exemple #3
0
def main():
    log.info("Started...")
    symbol = "KMX"
    from_date = date(2017, 1, 1)
    db = database2()
    rows = db.get_fundamentals(symbol, from_date)
    h = historicals(get_market_data_symbol(symbol))
    for row in rows:
        close = h.close(row.date)
        high = h.year_high(row.date)
        low = h.year_low(row.date)
        pe = round(close / row.eps)
        pe_high = round(high / row.eps)
        pe_low = round(low / row.eps)
        mkt_cap = round(row.shrs_out * close)
        print(
            "%s %s PE: %d %f / %f PE High: %d %f / %f PE Low: %d %f / %f Mkt Cap: %d %f * %f"
            % (row.date, row.symbol, pe, close, row.eps, pe_high, high,
               row.eps, pe_low, low, row.eps, mkt_cap, row.shrs_out, close))
        action = input("Please input y to commit, n to skip, a to abort:")
        if action == "y":
            row.pe = pe
            row.pe_high = pe_high
            row.pe_low = pe_low
            row.mkt_cap = mkt_cap
            db.commit()
        elif action == "n":
            continue
        elif action == "a":
            break

    log.info("Completed")
Exemple #4
0
def main():
    log.info("Started...")
    db = database2()
    date = datetime.now().date()
    recon = 1
    log.info("%s %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" %
             (date, "recon", "pos_gs", "pos_gs_ira", "pos_gs_hkd", "pos_ed",
              "pos_owe_portfolio", "neg_cash_total", "neg_cash_self",
              "neg_cash_managed"))
    while recon != 0:
        pos_gs = db.get_balance_history(db.CONST_BALANCES_TYPE_GS, date)
        pos_gs_ira = db.get_balance_history(db.CONST_BALANCES_TYPE_GS_IRA,
                                            date)
        pos_gs_hkd = db.get_balance_history(db.CONST_BALANCES_TYPE_GS_HKD,
                                            date)
        pos_owe_portfolio = db.get_balance_history(
            db.CONST_BALANCES_TYPE_OWE_PORTFOLIO, date)
        pos_ed = db.get_balance_history(db.CONST_BALANCES_TYPE_ED, date)
        neg_cash_total = db.get_portfolio_history(db.CONST_PORTFOLIO_CASH,
                                                  db.CONST_SYMBOL_CASH, date)
        neg_cash_self = db.get_portfolio_history(db.CONST_PORTFOLIO_SELF,
                                                 db.CONST_SYMBOL_CASH, date)
        neg_cash_managed = db.get_portfolio_history(db.CONST_PORTFOLIO_MANAGED,
                                                    db.CONST_SYMBOL_CASH, date)
        recon = (pos_gs + pos_gs_ira + pos_gs_hkd + pos_owe_portfolio +
                 pos_ed) - (neg_cash_total + neg_cash_self + neg_cash_managed)
        log.info(
            "%s %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" %
            (date, recon, pos_gs, pos_gs_ira, pos_gs_hkd, pos_owe_portfolio,
             pos_ed, neg_cash_total, neg_cash_self, neg_cash_managed))
        date -= timedelta(1)
    log.info("Completed")
def main():
    log.info("Started...")
    symbol = "KMX"
    from_date = date(2000,1,1)
    db = database2()
    rows = db.get_fundamentals(symbol, from_date)
    h = historicals( get_market_data_symbol( symbol ) )
    for row in rows:
        close = h.close(row.date)
        high = h.year_high(row.date)
        low = h.year_low(row.date)
        pe = round( close / row.eps )
        pe_high = round( high / row.eps )
        pe_low = round( low / row.eps )
        mkt_cap = round( row.shrs_out * close )
        print( "%s %s PE: %d %f / %f PE High: %d %f / %f PE Low: %d %f / %f Mkt Cap: %d %f * %f" % (row.date, row.symbol, pe, close, row.eps, pe_high, high, row.eps, pe_low, low, row.eps, mkt_cap, row.shrs_out, close))
        action = input( "Please input y to commit, n to skip, a to abort:" )
        if action == "y":
            row.pe = pe
            row.pe_high = pe_high
            row.pe_low = pe_low
            row.mkt_cap = mkt_cap
            db.commit()
        elif action == "n":
            continue
        elif action == "a":
            break
    
    log.info("Completed")
Exemple #6
0
def main():
    log.info("Started...")

    db = database2()
    rpt = report()
    total_roe = db.get_balance(db.CONST_BALANCES_TYPE_TOTAL_ROE)
    total_finish = CONST_ONE_UNIT / CONST_FINISH_PCT
    index_roe = db.get_index_history(db.CONST_INDEX_ROE,
                                     datetime.today().date())
    ytd_base_index_roe = db.get_index_history(db.CONST_INDEX_ROE,
                                              db.get_ytd_base_date())
    definite_retirement_years = CONST_DEFINITE_RETIREMENT_DATE - datetime.today(
    ).date()
    hoped_retirement_years = CONST_HOPED_RETIREMENT_DATE - datetime.today(
    ).date()

    # Determine cash made this year
    profit = total_roe - db.get_balance_history(
        db.CONST_BALANCES_TYPE_TOTAL_ROE,
        db.get_ytd_base_date()) - db.get_balance(
            db.CONST_BALANCES_TYPE_SAVINGS)

    populate_summary(db, rpt, index_roe, total_roe, total_finish,
                     hoped_retirement_years, profit)
    populate_summary_super_inflection(db, rpt, index_roe, total_roe,
                                      definite_retirement_years)
    populate_stress_test_twenty_percent_drop(db, rpt, index_roe, total_roe,
                                             total_finish)

    # Send a summary mail
    subject = "Blue Lion - " + rpt.format_ccy(profit) + " / " + rpt.format_pct(
        index_roe / ytd_base_index_roe - 1)
    send_mail_html_self(subject, rpt.get_html())
    log.info("Completed")
Exemple #7
0
def main():
    log.info("Started...")
    
    db = database2()
    
    total_self = calculate_total(db, db.CONST_PORTFOLIO_SELF)
    index_self = calculate_index(db, total_self, db.CONST_INDEX_SELF)
    total_play = calculate_total(db, db.CONST_PORTFOLIO_PLAY)
    index_play = calculate_index(db, total_play, db.CONST_INDEX_PLAY)
    total_managed = calculate_total(db, db.CONST_PORTFOLIO_MANAGED)
    index_managed = calculate_index(db, total_managed, db.CONST_INDEX_MANAGED)
    cash = db.get_constituents_by_portfolio_symbol(db.CONST_PORTFOLIO_CASH, db.CONST_SYMBOL_CASH)
    total_roe = total_self + total_managed + cash
    total_rotc = total_roe
    debt = db.get_constituents_by_portfolio_symbol(db.CONST_PORTFOLIO_CASH, db.CONST_SYMBOL_DEBT)
    total_roe -= debt
    index_roe = calculate_index(db, total_roe, db.CONST_INDEX_ROE)
    index_rotc = calculate_index(db, total_rotc, db.CONST_INDEX_ROTC)
    
    conn = connect( config_database_connect )
    cur = conn.cursor(cursor_factory=DictCursor)

    # Update index_history with today's values
    cur.execute("delete from index_history where date=current_date")
    cur.execute("insert into index_history values (current_date, 1, " + format_ccy_sql(index_self) + ")")
    cur.execute("insert into index_history values (current_date, 2, " + format_ccy_sql(index_roe) + ")")
    cur.execute("insert into index_history values (current_date, 3, " + format_ccy_sql(index_rotc) + ")")
    cur.execute("insert into index_history values (current_date, 4, " + format_ccy_sql(index_managed) + ")")
    cur.execute("insert into index_history values (current_date, 5, " + format_ccy_sql(index_play) + ")")
    conn.commit()
    
    # Update balances with today's values
    cur.execute("update balances set value=" + format_ccy_sql(total_roe) + " where type=12")
    cur.execute("update balances set value=" + format_ccy_sql(total_self) + " where type=13")
    cur.execute("update balances set value=" + format_ccy_sql(total_managed) + " where type=14")
    cur.execute("update balances set value=" + format_ccy_sql(total_rotc) + " where type=18")
    cur.execute("update balances set value=" + format_ccy_sql(total_play) + " where type=19")
    conn.commit()
    
    # Update balances_history with today's values
    cur.execute("delete from balances_history where date=current_date")
    cur.execute("insert into balances_history (select current_date, type, value from balances)")
    conn.commit()
    
    # Update portfolio_history with today's values
    cur.execute("delete from portfolio_history where date=current_date")
    cur.execute("insert into portfolio_history (select current_date, symbol, value, portfolio_id, pricing_type, quantity, price from constituents)")
    conn.commit()
    
    # Update divisors_history with today's values
    cur.execute("delete from divisors_history where date=current_date")
    cur.execute("insert into divisors_history (select current_date, type, value from divisors)")
    conn.commit()
    
    # Close the db
    cur.close()
    conn.close()
    
    log.info("Completed")
def main():
    log.info("Started...")
    db = database2()
    rpt = report()

    CONST_PORTFOLIO = 1
    CONST_START = date(2020, 1, 21)
    CONST_END = date(2017, 1, 1)

    contributors = {}
    start = db.get_portfolio_history_by_date(CONST_PORTFOLIO, CONST_START)
    for row in start:
        contributors[row.symbol] = [row.symbol, row.value, 0, 0, 0, 0, 0, 0]
    end = db.get_portfolio_history_by_date(CONST_PORTFOLIO, CONST_END)
    for row in end:
        if row.symbol in contributors:
            contributors[row.symbol][5] = row.value
        else:
            contributors[row.symbol] = [
                row.symbol, 0, 0, 0, 0, row.value, 0, 0
            ]
    divs = db.get_actions_by_date_range_type(
        CONST_START, CONST_END, db.CONST_ACTION_TYPE_DIVIDEND_PORTFOLIO)
    for row in divs:
        if row.symbol in contributors:
            contributors[row.symbol][4] += row.value1
    buys = db.get_actions_by_date_range_type(
        CONST_START, CONST_END, db.CONST_ACTION_TYPE_BOUGHT_PORTFOLIO)
    for row in buys:
        if row.symbol in contributors:
            contributors[row.symbol][2] += row.value1
    sells = db.get_actions_by_date_range_type(
        CONST_START, CONST_END, db.CONST_ACTION_TYPE_SOLD_PORTFOLIO)
    for row in sells:
        if row.symbol in contributors:
            contributors[row.symbol][3] += row.value1
    for key, value in contributors.items():
        value[6] = value[3] + value[4] + value[5] - value[1] - value[2]
        value[7] = (value[1] + value[2] + value[6]) / (value[1] + value[2]) - 1

    formats = [
        rpt.CONST_FORMAT_NONE, rpt.CONST_FORMAT_CCY, rpt.CONST_FORMAT_CCY,
        rpt.CONST_FORMAT_CCY, rpt.CONST_FORMAT_CCY, rpt.CONST_FORMAT_CCY,
        rpt.CONST_FORMAT_CCY_COLOR, rpt.CONST_FORMAT_PCT_COLOR
    ]
    table = []
    for key, value in contributors.items():
        table.append(value)
    table.sort(key=lambda a: a[7] * -1)
    table.insert(0,
                 ["Symbol", "Start", "Buy", "Sell", "Div", "End", "Diff", "%"])
    rpt.add_table(table, formats)

    subject = 'Blue Lion - Contributors'
    send_mail_html_self(subject, rpt.get_html())
    log.info("Completed")
def main():
    log.info("Started...")
    db = database2()
    rpt = report()
    
    populate_max_movers( db, rpt )
    subject = 'Health Check - ' + strftime("%Y-%m-%d", localtime())
     
    send_mail_html_self(subject, rpt.get_html())
    log.info("Completed")
def main():
    log.info("Started loading prices for constituents...")
    db = database2()    
    rows = db.get_constituents(db.CONST_PRICING_TYPE_BY_PRICE)   
    populate_price_and_value(db, rows, True)
    log.info("Completed")

    log.info("Started loading prices for stocks...")
    rows = db.get_stocks()   
    populate_price_and_value(db, rows, False)
    log.info("Completed")
Exemple #11
0
def main():
    log.info("Started...")
    db = database2()
    rpt = report()

    populate_five_cagr(db, rpt)
    populate_magic(rpt)

    subject = 'Blue Lion - Search'
    send_mail_html_self(subject, rpt.get_html())
    log.info("Completed")
Exemple #12
0
def main():
    log.info("Started loading prices for constituents...")
    db = database2()
    rows = db.get_constituents(db.CONST_PRICING_TYPE_BY_PRICE)
    populate_price_and_value(db, rows, True)
    log.info("Completed")

    log.info("Started loading prices for stocks...")
    rows = db.get_stocks()
    populate_price_and_value(db, rows, False)
    log.info("Completed")
Exemple #13
0
def main():
    log.info("Started...")
    db = database2()
    rpt = report()

    formats = [
        rpt.CONST_FORMAT_NONE, rpt.CONST_FORMAT_CCY, rpt.CONST_FORMAT_CCY,
        rpt.CONST_FORMAT_CCY, rpt.CONST_FORMAT_CCY_COLOR
    ]
    table = [
        ["Category", "Spent", "Projected", "Budget", "Tracking"],
    ]
    append_budget_row(db, table, "Base", [0, 2, 3, 4, 5, 8, 12, 96], 75000)
    append_budget_row(db, table, "Rent", [1], 73000)
    append_budget_row(db, table, "Travel", [7], 10000)
    append_budget_row(db, table, "Helper", [9], 12000)
    append_budget_row(db, table, "Monchichi", [94], 12000)
    append_budget_row(db, table, "Deux", [93], 12000)
    append_budget_row(db, table, "Fumi", [11], 5000)
    append_budget_row(db, table, "Mike", [6, 10], 5000)
    append_budget_row(db, table, "Special", [95, 97, 98, 99], 0)
    append_budget_row(
        db, table, "Total",
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 93, 94, 95, 96, 97, 98, 99],
        CONST_BUDGET)
    recon_projected = calculate_recon_projected(table, [2, 3, 4, 5, 6, 8, 9],
                                                1, 7, 2, 4)
    table.append([
        "Recon",
        db.get_ytd_spending_sum(), recon_projected, CONST_BUDGET,
        CONST_BUDGET - recon_projected
    ])
    fumi_projected = calculate_fumi_projected(table, 1, 7, 4)
    table.append(["Payout", 0, fumi_projected, 0, 0])
    rpt.add_table(table, formats)

    plan_projected = (recon_projected + CONST_FIXED) / (1 - CONST_TAX_RATE)
    rpt.add_string("BLRP " + rpt.format_ccy(plan_projected) + "=(" +
                   rpt.format_ccy(recon_projected) + "+" +
                   rpt.format_ccy(CONST_FIXED) + ")/(1-" +
                   rpt.format_ccy(CONST_TAX_RATE) + ")")
    rpt.add_string("BLRB " + rpt.format_ccy(CONST_ONE_UNIT) + "=(" +
                   rpt.format_ccy(CONST_BUDGET) + "+" +
                   rpt.format_ccy(CONST_FIXED) + ")/(1-" +
                   rpt.format_ccy(CONST_TAX_RATE) + ")")
    subject = 'Blue Tree - ' + rpt.format_ccy(
        plan_projected) + ' / ' + rpt.format_ccy(CONST_ONE_UNIT)

    send_mail_html_self(subject, rpt.get_html())
    log.info("Completed")
Exemple #14
0
def main():
    log.info("Started...")
    db = database2()
    date = datetime.now().date()
    recon = 1
    while recon != 0:
        pos_gs = db.get_balance_history(db.CONST_BALANCES_TYPE_GS, date)
        pos_gs_ira = db.get_balance_history(db.CONST_BALANCES_TYPE_GS_IRA, date)
        pos_gs_hkd = db.get_balance_history(db.CONST_BALANCES_TYPE_GS_HKD, date)
        pos_owe_portfolio = db.get_balance_history(db.CONST_BALANCES_TYPE_OWE_PORTFOLIO, date)
        neg_cash_total = db.get_portfolio_history(db.CONST_PORTFOLIO_CASH, db.CONST_SYMBOL_CASH, date)
        neg_cash_self = db.get_portfolio_history(db.CONST_PORTFOLIO_SELF, db.CONST_SYMBOL_CASH, date)
        recon = (pos_gs + pos_gs_ira + pos_gs_hkd + pos_owe_portfolio) - (neg_cash_total + neg_cash_self)
        log.info("%s %s\t%s\t%s\t%s\t%s\t%s\t%s" % (date, recon, pos_gs, pos_gs_ira, pos_gs_hkd, pos_owe_portfolio, 
                                                    neg_cash_total, neg_cash_self))
        date -= timedelta(1)    
    log.info("Completed")
Exemple #15
0
def main():
    log.info("Started...")
    db = database2()
    rpt = report()

    rpt.add_heading("Trade")
    populate_cash(db, rpt)
    rpt.add_string("")        
    populate_allocations(db, rpt)
    rpt.add_heading("Upgrade")
    populate_thirty_pe( db, rpt )
    rpt.add_string("")        
    populate_five_cagr(db, rpt)
    rpt.add_heading("Research")
    populate_reds(db, rpt)
    rpt.add_string("")        
    populate_max_movers( db, rpt )
    
    subject = 'Blue Lion - Health Check'
    send_mail_html_self(subject, rpt.get_html())
    log.info("Completed")
Exemple #16
0
def main():
    log.info("Started...")
    db = database2()
    rows = db.get_stocks()
    for row in rows:
        log.info("Downloading %s..." % (row.symbol))
        try:
            h = historicals(get_market_data_symbol(row.symbol))
            update_stock_historical_change(row, h, h.CONST_BUSINESS_DAYS_ONE,
                                           "day_change", "day_change_date")
            update_stock_historical_change(row, h, h.CONST_BUSINESS_DAYS_WEEK,
                                           "week_change", "week_change_date")
            update_stock_historical_change(row, h, h.CONST_BUSINESS_DAYS_MONTH,
                                           "month_change", "month_change_date")
            update_stock_historical_change(row, h,
                                           h.CONST_BUSINESS_DAYS_THREE_MONTHS,
                                           "three_month_change",
                                           "three_month_change_date")
            update_stock_historical_change(row, h, h.CONST_BUSINESS_DAYS_YEAR,
                                           "year_change", "year_change_date")
            update_stock_historical_change(row, h,
                                           h.CONST_BUSINESS_DAYS_FIVE_YEARS,
                                           "five_year_change",
                                           "five_year_change_date")
            update_stock_historical_change(row, h,
                                           h.CONST_BUSINESS_DAYS_TEN_YEARS,
                                           "ten_year_change",
                                           "ten_year_change_date")
        except Exception as err:
            # Log exceptions as warnings, there often won't be historical data for international names
            log.warning("Could not get data for %s" % (row.symbol))
            # log.exception(err)
            continue

    log.info("Committing transaction...")
    db.commit()

    log.info("Completed")
Exemple #17
0
def main():
    log.info("Started...")

    db = database2()

    total_self = calculate_total(db, db.CONST_PORTFOLIO_SELF)
    index_self = calculate_index(db, total_self, db.CONST_INDEX_SELF)
    total_play = calculate_total(db, db.CONST_PORTFOLIO_PLAY)
    index_play = calculate_index(db, total_play, db.CONST_INDEX_PLAY)
    total_managed = calculate_total(db, db.CONST_PORTFOLIO_MANAGED)
    index_managed = calculate_index(db, total_managed, db.CONST_INDEX_MANAGED)
    cash = db.get_constituents_by_portfolio_symbol(db.CONST_PORTFOLIO_CASH,
                                                   db.CONST_SYMBOL_CASH)
    total_roe = total_self + total_managed + cash
    total_rotc = total_roe
    debt = db.get_constituents_by_portfolio_symbol(db.CONST_PORTFOLIO_CASH,
                                                   db.CONST_SYMBOL_DEBT)
    total_roe -= debt
    index_roe = calculate_index(db, total_roe, db.CONST_INDEX_ROE)
    index_rotc = calculate_index(db, total_rotc, db.CONST_INDEX_ROTC)

    conn = connect(config_database_connect)
    cur = conn.cursor(cursor_factory=DictCursor)

    # Update index_history with today's values
    cur.execute("delete from index_history where date=current_date")
    cur.execute("insert into index_history values (current_date, 1, " +
                format_ccy_sql(index_self) + ")")
    cur.execute("insert into index_history values (current_date, 2, " +
                format_ccy_sql(index_roe) + ")")
    cur.execute("insert into index_history values (current_date, 3, " +
                format_ccy_sql(index_rotc) + ")")
    cur.execute("insert into index_history values (current_date, 4, " +
                format_ccy_sql(index_managed) + ")")
    cur.execute("insert into index_history values (current_date, 5, " +
                format_ccy_sql(index_play) + ")")
    conn.commit()

    # Update balances with today's values
    cur.execute("update balances set value=" + format_ccy_sql(total_roe) +
                " where type=12")
    cur.execute("update balances set value=" + format_ccy_sql(total_self) +
                " where type=13")
    cur.execute("update balances set value=" + format_ccy_sql(total_managed) +
                " where type=14")
    cur.execute("update balances set value=" + format_ccy_sql(total_rotc) +
                " where type=18")
    cur.execute("update balances set value=" + format_ccy_sql(total_play) +
                " where type=19")
    conn.commit()

    # Update balances_history with today's values
    cur.execute("delete from balances_history where date=current_date")
    cur.execute(
        "insert into balances_history (select current_date, type, value from balances)"
    )
    conn.commit()

    # Update portfolio_history with today's values
    cur.execute("delete from portfolio_history where date=current_date")
    cur.execute(
        "insert into portfolio_history (select current_date, symbol, value, portfolio_id, pricing_type, quantity, price from constituents)"
    )
    conn.commit()

    # Update divisors_history with today's values
    cur.execute("delete from divisors_history where date=current_date")
    cur.execute(
        "insert into divisors_history (select current_date, type, value from divisors)"
    )
    conn.commit()

    # Close the db
    cur.close()
    conn.close()

    log.info("Completed")