def compute_applications(data, base_date): previous_month_data = rs.records_for_month(data, dth.months_ago(base_date, 1)) current_month_data = rs.records_for_month(data, base_date) difference = rs.total_amount_by( APPLICATIONS_GROUPBY, current_month_data) - rs.total_amount_by( APPLICATIONS_GROUPBY, previous_month_data) return difference.amount
def food_expenses(expenses, base_date): data = rs.total_amount_by('category', rs.records_for_month(expenses, base_date)) if 'mercado' in data.index and 'restaurante' in data.index: return pd.Series(data.loc['mercado'].amount + data.loc['restaurante'].amount) * -1 else: return pd.Series(0)
def absolute_return_for_month(invest, base_date): """Total return on current month given base_date""" past_month = rs.records_for_previous_month(invest, base_date) current_month = rs.records_for_month(invest, base_date) invested_previous_month = total_invested_by('title', past_month) invested_for_month = total_invested_by('title', current_month) applications_month = total_applications_by('title', current_month) discounts_month = total_discounts_by('title', current_month) return invested_for_month \ .sub(invested_previous_month, fill_value=0) \ .sub(applications_month, fill_value=0) \ .add(discounts_month, fill_value=0)
def total_monthly_return(invest, base_date): past_month = rs.records_for_previous_month(invest, base_date) current_month = rs.records_for_month(invest, base_date) invested_past_month = ft.invested(past_month).amount.sum() invested_current_month = ft.invested(current_month).amount.sum() applications_current_month = ft.applications(current_month).amount.sum() discounts_current_month = ft.discounts(current_month).amount.sum() if invested_current_month == 0: return 0.0 return monthly_return_percentage( invested_past_month, invested_current_month, applications_current_month + discounts_current_month)
def monthly_return_by_title(invest, base_date): """Monthly return percentage given investments. Even though it has a different calculation, it returns the same results as absolute_return_for_month_percentage""" past_month = rs.records_for_previous_month(invest, base_date) current_month = rs.records_for_month(invest, base_date) invested_previous_month = total_invested_by('title', past_month) invested_for_month = total_invested_by('title', current_month) applications_month = total_applications_by('title', current_month) discounts_month = total_discounts_by('title', current_month) return invested_for_month\ .sub(applications_month, fill_value=0)\ .add(discounts_month, fill_value=0)\ .div(invested_previous_month, fill_value=0) - 1
def summary(invest, base_date): past_month = rs.records_for_previous_month(invest, base_date) current_month = rs.records_for_month(invest, base_date) invest_return_for_month = tt.absolute_return_for_month(invest, base_date) invested_previous_month = tt.total_invested_by('title', past_month) invest_return_for_month_perc = invest_return_for_month / invested_previous_month summary = {'Total': tt.total_invested_by('title', current_month).amount, 'Total last month': invested_previous_month.amount, 'Return for month': invest_return_for_month.amount, 'Return for month (%)': invest_return_for_month_perc.amount, 'Return with inflation (%)': tt.return_with_inflation( invest_return_for_month_perc, base_date).amount} summary_invest = pd.DataFrame(summary, columns=list(summary.keys())) return summary_invest[summary_invest['Total'] > 0]
def earned_for_month(incomes, base_date): return rs.records_for_month(incomes[incomes.category == 'renda'], base_date).amount.sum()
def applications_for_month(incomes, base_date): """Total applications on current month given base_date""" applications = rs.records_for_month(ft.applications(incomes), base_date) return rs.total_amount_by('title', applications)
def invested_for_month_by(column, invest, base_date): """Total invested on current month given base_date""" invested = rs.records_for_month(invest, base_date) return total_invested_by(column, invested)
def describe_over_time(expenses, incomes, post_describe_fn): """Computes expenses distribution over time, for all months available in expenses""" return rs.describe_over_time( expenses, lambda exps, date: post_describe_fn( distribution(rs.records_for_month(expenses, date), rs.records_for_month(incomes, date))))
def describe(invest, column, base_date): """Returns relevant data about types""" current_month = rs.records_for_month(invest, base_date) return tt.total_invested_by(column, current_month).amount