Exemple #1
0
def calculate(working_age=22,
              retirement_age=51,
              monthly_salary=8000,
              bonus=2,
              deposit_ratio=0.4):
    total_income = 0
    total_deposit = 0
    purchasing_power = 0

    table = generate_table()

    i = working_age
    while i <= retirement_age:
        annual_income = monthly_salary * (12 + bonus)
        total_income += annual_income
        annual_deposit = annual_income * deposit_ratio
        total_deposit += annual_deposit
        purchasing_power = purchasing_power * (1 - 0.05) + annual_deposit

        agr = annual_growth_rate(i - working_age)

        table.add_row(str(i), str(agr), format_currency(monthly_salary),
                      format_currency(total_income),
                      format_currency(total_deposit),
                      format_currency(purchasing_power))

        monthly_salary *= agr
        i += 1

    console = Console()
    console.print(table)
def show_existing_inputs():
    """
    This shows the user's current saved inputs and allows them
    to either move on or edit it.
    """
    if g.logged_in is True:
        if g.inputs is True:
            user_assets = m_session.query(model.UserBanking).filter_by(
                user_id=g.user.id).first()
            total_assets = user_assets.inputted_assets + \
                user_assets.checking_amt + user_assets.savings_amt + \
                user_assets.IRA_amt + user_assets.comp401k_amt + \
                user_assets.investment_amt
            risk_prof = m_session.query(model.RiskProfile).filter_by(
                id=g.user.risk_profile_id).first()
            return render_template(
                "profile_inputs.html",
                assets=utils.format_currency(total_assets),
                income=utils.format_currency(g.user.income),
                company_401k=g.user.company_401k,
                company_match=g.user.company_match,
                match_percent=utils.format_percentage(g.user.match_percent),
                match_salary=utils.format_percentage(g.user.match_salary),
                risk_profile=risk_prof.name)
        else:
            flash("Our financial data on you is incomplete. \
                    Please input now.")
            return redirect("/input/banking")
    else:
        return redirect("/login")
Exemple #3
0
def evaluate_model(agent, data, window_size, debug):
    data_length = len(data) - 1
    state = get_state(data, 0, window_size + 1)
    total_profit = 0
    agent.inventory = []
    for t in range(data_length):
        action = agent.act(state, is_eval=True)
        # SIT
        next_state = get_state(data, t + 1, window_size + 1)
        reward = 0
        # BUY
        if action == 1:
            agent.inventory.append(data[t])
            if debug:
                logging.debug('Buy at: {}'.format(format_currency(data[t])))
        # SELL
        elif action == 2 and len(agent.inventory) > 0:
            bought_price = agent.inventory.pop(0)
            reward = max(data[t] - bought_price, 0)
            total_profit += data[t] - bought_price
            if debug:
                logging.debug('Sell at: {} | Position: {}'.format(
                    format_currency(data[t]),
                    format_position(data[t] - bought_price)))

        done = True if t == data_length - 1 else False
        agent.memory.append((state, action, reward, next_state, done))
        state = next_state

        if done:
            return total_profit
def calculate(total_deposit=6000000, years=20, inflation_ratio=0.05):
    deposit = total_deposit

    table = Table(show_header=True, header_style='bold')
    table.add_column('#')
    table.add_column('Real Deposit (RMB)')

    for i in range(1, years + 1):
        deposit -= deposit * inflation_ratio
        table.add_row(str(i), format_currency(deposit))

    console = Console()
    console.print(table)
Exemple #5
0
def get_file_stats(v, separator=None, as_statistic=True):
    stats = []
    agg = v.get("datagetter_aggregates")
    if agg is None:
        return stats

    count = agg.get("count", 0)
    stats.append(
        to_statistic(humanize.intcomma(count), pluralize("grant", count)))

    recip = agg.get("distinct_recipient_org_identifier_count", 0)
    if recip > 0:
        stats.append(
            to_statistic(
                humanize.intcomma(recip),
                pluralize("recipient", recip),
            ))

    funders = agg.get("distinct_funding_org_identifier_count", 0)
    if funders > 1:
        stats.append(
            to_statistic(
                humanize.intcomma(funders),
                pluralize("funder", funders),
            ))

    if len(agg.get("currencies", {})) == 1:
        for c in agg["currencies"]:
            cur = format_currency(agg["currencies"][c].get("total_amount", 0),
                                  c)
            stats.append(to_statistic(cur[0], cur[1]))

    if separator:
        result = [separator] * (len(stats) * 2 - 1)
        result[0::2] = stats
        return result

    return stats
def show_existing_results():
    """
    This route accesses saved data from the database and
    calculates the results.
    """
    if g.logged_in is True:
        if g.inputs is True:
            user_assets = m_session.query(model.UserBanking).filter_by(
                user_id=g.user.id).one()

            total_assets = user_assets.inputted_assets + \
                user_assets.checking_amt + user_assets.savings_amt + \
                user_assets.IRA_amt + user_assets.comp401k_amt + \
                user_assets.investment_amt
            income = g.user.income
            comp_401k = g.user.company_401k
            match_401k = g.user.company_match
            match_percent = g.user.match_percent
            match_salary = g.user.match_salary

            results = utils.calc_financial_results(
                total_assets, income, comp_401k, match_401k, match_percent,
                match_salary)
            max_results = utils.calc_max_financials(
                income, comp_401k, match_401k, match_percent, match_salary)

            return render_template(
                "results.html",
                checking=utils.format_currency(results["checking"]),
                savings=utils.format_currency(results["savings"]),
                match=utils.format_currency(results["match"]),
                ira=utils.format_currency(results["ira"]),
                ret401k=utils.format_currency(results["ret401k"]),
                investment=utils.format_currency(results["investment"]),
                results=json.dumps(results),
                max_results=json.dumps(max_results))
        else:
            flash("Our financial data on you is incomplete. \
                    Please input now.")
            return redirect("/input/banking")
    else:
        return redirect("/login")
Exemple #7
0
 def __str__(self):
     return self.en_description.ljust(20) + "\t" + \
            str(self.amount).ljust(15) + "\t" + \
            format_currency(self.current_value).ljust(15) + "\t" + \
            red_green_color(format_currency(self.profit).ljust(15)) + "\t" + \
            red_green_color(f"{self.profit_percentage:.2f}%")