def setUp(self): self.cost_manager = CostManagerFactory() active_client = ActiveClientMainFactory( birthday=datetime.datetime(1967, 1, 1)) self.patrimony = PatrimonyMainFactory() self.patrimony.incomes.all().update(value_monthly=55000, thirteenth=False, vacation=False) ActiveFactory(value=30000.00, active_manager=self.patrimony.activemanager) ActiveFactory(value=321200.00, active_manager=self.patrimony.activemanager) ArrearageFactory(patrimony=self.patrimony, value=351200.00) self.goal_manager = GoalManagerFactory() GoalFactory.create_batch(4, goal_manager=self.goal_manager, year_init=2017, year_end=2027, value=2500, periodicity=1) self.financial_independece = FinancialIndependenceFactory( duration_of_usufruct=35, remain_patrimony=30000, ) self.financial_planning = FinancialPlanningFactory( active_client=active_client, cost_manager=self.cost_manager, patrimony=self.patrimony, financial_independence=self.financial_independece, goal_manager=self.goal_manager, target_profitability=110, )
class FinancialPlanningModelTest(TestCase): def setUp(self): active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) self.financial_planning = FinancialPlanningFactory( active_client=active_client, target_profitability=1.10, cdi=0.1213, ipca=0.075) def test_duration_financial_planning(self): self.assertEqual(self.financial_planning.duration(), 10) def test_real_gain_related_cdi(self): self.assertAlmostEqual(self.financial_planning.real_gain_related_cdi(), 0.054353488372093084) def test_real_gain(self): self.assertAlmostEqual(self.financial_planning.real_gain(), 0.04306976744186053) def test_save_financial_planning(self): financial_planning = FinancialPlanningFactory(init_year=None) self.assertEqual(financial_planning.init_year, datetime.datetime.now().year) def test_end_year(self): self.assertEqual(self.financial_planning.end_year(), 2027)
def setUp(self): self.cost_manager = CostManagerFactory() active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) self.patrimony = PatrimonyFactory() self.patrimony.incomes.all().update(value_monthly=55000, thirteenth=False, vacation=False) for active in self.patrimony.activemanager.actives.all(): active.delete() data = [{ 'value': 30000.00, 'rate': 1.1879 }, { 'value': 321200.00, 'rate': 0.7500 }, { 'value': 351200.00, 'rate': 0.7500 }] for active in data: ActiveFactory(**active, active_manager=self.patrimony.activemanager) ArrearageFactory(patrimony=self.patrimony, value=351200.00) self.goal_manager = GoalManagerFactory() GoalFactory.create_batch(4, goal_manager=self.goal_manager, init_year=2017, end_year=2027, value=2500, periodicity=1) self.financial_independence = FinancialIndependenceFactory( duration_of_usufruct=35, remain_patrimony=30000, ) self.financial_planning = FinancialPlanningFactory( active_client=active_client, cost_manager=self.cost_manager, patrimony=self.patrimony, financial_independence=self.financial_independence, goal_manager=self.goal_manager, cdi=0.1213, ) protection_manager = ProtectionManagerFactory( financial_planning=self.financial_planning) for private_pension in protection_manager.private_pensions.all(): private_pension.delete() for life_insurance in protection_manager.life_insurances.all(): life_insurance.delete() LifeInsuranceFactory(protection_manager=protection_manager, value_to_pay_annual=2000, has_year_end=False)
def setUp(self): active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) self.financial_planning = FinancialPlanningFactory( active_client=active_client, target_profitability=1.10, cdi=0.1213, ipca=0.075)
def emergency_reserve_case(self, model): financial_planning = FinancialPlanningFactory() patrimony = financial_planning.patrimony self.assertEqual(0, model.history.count()) EmergencyReserveFactory(patrimony=patrimony, cost_manager=financial_planning.cost_manager) self.assertEqual(1, model.history.count())
def setUp(self): active_client = ActiveClientMainFactory( birthday=datetime.datetime(1977, 1, 1)) financial_planning = FinancialPlanningFactory( active_client=active_client) self.goal_manager = financial_planning.goal_manager goal_type1 = GoalTypeFactory(name='Imóvel') goal_type2 = GoalTypeFactory(name='Vestuário') self.goal_has_end_date = GoalFactory(has_end_date=False, goal_type=goal_type1, year_init=2021, periodicity=3, value=50000, goal_manager=self.goal_manager) self.goal_hasnt_end_date = GoalFactory(has_end_date=True, goal_type=goal_type2, year_init=2021, periodicity=3, value=50000, year_end=2031, goal_manager=self.goal_manager) self.array_flow_withot_date = [ 0, 0, 0, 0, 50000, 0, 0, 50000, 0, 0, 50000, 0, 0, 50000, 0, 0, 50000, 0, 0, 50000 ] self.array_flow_with_date = [ 0, 0, 0, 0, 50000, 0, 0, 50000, 0, 0, 50000, 0, 0, 50000, 0, 0, 0, 0, 0, 0 ]
def setUp(self): active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) financial_planning = FinancialPlanningFactory( cdi=0.1213, ipca=0.075, active_client=active_client) self.protection_manager = ProtectionManagerFactory( financial_planning=financial_planning) self.protection_manager.private_pensions.all().update( value=20000, annual_investment=2000) for life_insurance in self.protection_manager.life_insurances.all(): life_insurance.delete() for private_pension in self.protection_manager.private_pensions.all(): private_pension.delete() life_insurances = [ {'value_to_pay_annual': 2000, 'has_year_end': False}, {'value_to_pay_annual': 2000, 'has_year_end': True, 'year_end': 2020, }, {'value_to_pay_annual': 1000, 'has_year_end': True, 'year_end': 2023, }] for life_insurance in life_insurances: LifeInsuranceFactory(**life_insurance, protection_manager=self.protection_manager) private_pensions = [ {'annual_investment': 5000}, {'annual_investment': 3000}, {'annual_investment': 2000}, {'annual_investment': 8000}, ] for private_pension in private_pensions: PrivatePensionFactory(protection_manager=self.protection_manager, **private_pension)
def setUp(self): financial_planning = FinancialPlanningFactory(cdi=0.1213, ipca=0.0750) self.reserve_in_lack = financial_planning.protection_manager.\ reserve_in_lack self.reserve_in_lack.value_0_to_24_mounth = 13000 self.reserve_in_lack.value_24_to_60_mounth = 10000 self.reserve_in_lack.value_60_to_120_mounth = 5000 self.reserve_in_lack.value_120_to_240_mounth = 5000
def setUp(self): self.cost_manager = CostManagerFactory() active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) self.financial_planning = FinancialPlanningFactory( active_client=active_client, cost_manager=self.cost_manager, )
def _create_reserve_in_lack(): financial_planning = FinancialPlanningFactory(cdi=0.1213, ipca=0.0750) protection_manager = ProtectionManagerFactory( financial_planning=financial_planning) reserve_in_lack = protection_manager.reserve_in_lack reserve_in_lack.value_0_to_24_mounth = 13000 reserve_in_lack.value_24_to_60_mounth = 10000 reserve_in_lack.value_60_to_120_mounth = 5000 reserve_in_lack.value_120_to_240_mounth = 5000 return reserve_in_lack
def setUp(self): self.financial_independence = FinancialIndependenceFactory( duration_of_usufruct=35, remain_patrimony=30000, ) active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) self.financial_planning = FinancialPlanningFactory( active_client=active_client, financial_independence=self.financial_independence, )
def setUp(self): active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) financial_planning = FinancialPlanningFactory( active_client=active_client) goal_manager = financial_planning.goal_manager self.financial_independence = financial_planning.financial_independence self.financial_independence.rate = 0.02 goals_type = [{ 'name': 'Casa Extra' }, { 'name': 'Compra De Cotas Societárias' }, { 'name': 'Moradia' }, { 'name': 'Reforma e Manutenção Da Casa' }, { 'name': 'Viagens' }] data_goal_type = [] for goal_type in goals_type: data_goal_type.append(GoalTypeFactory(**goal_type)) goals = [{ 'value': 200000, 'init_year': 2018, 'end_year': 2018 }, { 'value': 500000, 'init_year': 2022, 'end_year': 2022 }, { 'value': 1000000, 'init_year': 2021, 'end_year': 2021 }, { 'value': 140000, 'init_year': 2025, 'end_year': 2025 }, { 'value': 50000, 'init_year': 2023, 'end_year': 2023 }] self.data_goals = [] for goal_type, goal in zip(data_goal_type, goals): self.data_goals.append( GoalFactory(**goal, goal_type=goal_type, goal_manager=goal_manager))
def setUp(self): active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) financial_planning = FinancialPlanningFactory( active_client=active_client, ipca=0.075) protection_manager = ProtectionManagerFactory( financial_planning=financial_planning) reserve_in_lack = _create_reserve_in_lack() protection_manager = reserve_in_lack.protection_manager protection_manager.financial_planning = financial_planning for private_pension in protection_manager.private_pensions.all(): private_pension.delete() for life_insurance in protection_manager.life_insurances.all(): life_insurance.delete() private_pensions = [ {'value': 20000, 'annual_investment': 2000, 'rate': 0.1213}, {'value': 4000, 'annual_investment': 200, 'rate': 0.09}, {'value': 4000, 'annual_investment': 200, 'rate': 0.09}, ] self.private_pensions_array = [] for private_pension in private_pensions: element = PrivatePensionFactory( **private_pension, protection_manager=protection_manager) self.private_pensions_array.append(element) life_insurances = [ {'value_to_pay_annual': 2000, 'value_to_recive': 500000, 'actual': True}, {'value_to_pay_annual': 2000, 'value_to_recive': 200000, 'actual': False}, {'value_to_pay_annual': 1000, 'value_to_recive': 300000, 'actual': True}, {'value_to_pay_annual': 1000, 'value_to_recive': 300000, 'actual': True}, ] for life_insurance in life_insurances: LifeInsuranceFactory(**life_insurance, protection_manager=protection_manager) self.future_patrimony_succession =\ protection_manager.future_patrimony_succession self.future_patrimony_succession.itcmd_tax = 0.06 self.future_patrimony_succession.oab_tax = 0.05 self.future_patrimony_succession.other_taxes = 0.02 self.protection_manager = protection_manager
def setUp(self): active_client = ActiveClientMainFactory( birthday=datetime.datetime(1967, 1, 1)) self.patrimony = PatrimonyMainFactory() self.patrimony.incomes.all().update(value_monthly=1212.2) FinancialPlanningFactory( active_client=active_client, patrimony=self.patrimony) self.common_income = IncomeFactory(value_monthly=round(1200, 2), thirteenth=False, patrimony=self.patrimony, vacation=False) self.income_with_thirteenth = IncomeFactory(value_monthly=1200.00, thirteenth=True, patrimony=self.patrimony, vacation=False) self.income_with_vacation = IncomeFactory(value_monthly=round(1200, 2), thirteenth=False, patrimony=self.patrimony, vacation=True)
def setUp(self): active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) self.patrimony = PatrimonyFactory() self.patrimony.incomes.all().update(value_monthly=1212.2) FinancialPlanningFactory(active_client=active_client, patrimony=self.patrimony) self.common_income = IncomeFactory(value_monthly=1200, thirteenth=False, patrimony=self.patrimony, vacation=False) self.income_with_thirteenth = IncomeFactory(value_monthly=1200.00, thirteenth=True, patrimony=self.patrimony, vacation=False) self.income_with_vacation = IncomeFactory(value_monthly=1200, thirteenth=False, patrimony=self.patrimony, vacation=True) ArrearageFactory(patrimony=self.patrimony, value=351200.00, period=3) RealEstateFactory(patrimony=self.patrimony, salable=True)
def setUp(self): financial_planning = FinancialPlanningFactory() self.active_manager = financial_planning.patrimony.activemanager patrimony = financial_planning.patrimony self.emergency_reserve = financial_planning.protection_manager.\ emergency_reserve self.emergency_reserve.mounth_of_protection = 12 for active in self.active_manager.actives.all(): active.delete() cost_manager = financial_planning.cost_manager for regular_cost in cost_manager.regular_costs.all(): regular_cost.delete() for arrearage in patrimony.arrearages.all(): arrearage.delete() regular_costs = [{'value': 500}, {'value': 1500}, {'value': 2500}] for regular_cost in regular_costs: RegularCostFactory(**regular_cost, cost_manager=cost_manager)
def setUp(self): financial_planning = FinancialPlanningFactory(cdi=0.1) self.active_manager = financial_planning.patrimony.activemanager for active in self.active_manager.actives.all(): active.delete() data = [{ 'value': 27000.00, 'rate': 1.1879 }, { 'value': 125000.00, 'rate': 0.7500 }, { 'value': 95000.00, 'rate': 0.9000 }] for active in data: ActiveFactory(**active, active_manager=self.active_manager) # Update all equivalent_rates of that manager self.active_manager.real_profit_cdi()
class FinancialPlanningFlowTest(TestCase): def setUp(self): self.cost_manager = CostManagerFactory() active_client = ActiveClientFactory( birthday=datetime.datetime(1967, 1, 1)) self.patrimony = PatrimonyFactory() self.patrimony.incomes.all().update(value_monthly=55000, thirteenth=False, vacation=False) for active in self.patrimony.activemanager.actives.all(): active.delete() data = [{ 'value': 30000.00, 'rate': 1.1879 }, { 'value': 321200.00, 'rate': 0.7500 }, { 'value': 351200.00, 'rate': 0.7500 }] for active in data: ActiveFactory(**active, active_manager=self.patrimony.activemanager) ArrearageFactory(patrimony=self.patrimony, value=351200.00) self.goal_manager = GoalManagerFactory() GoalFactory.create_batch(4, goal_manager=self.goal_manager, init_year=2017, end_year=2027, value=2500, periodicity=1) self.financial_independence = FinancialIndependenceFactory( duration_of_usufruct=35, remain_patrimony=30000, ) self.financial_planning = FinancialPlanningFactory( active_client=active_client, cost_manager=self.cost_manager, patrimony=self.patrimony, financial_independence=self.financial_independence, goal_manager=self.goal_manager, cdi=0.1213, ) protection_manager = ProtectionManagerFactory( financial_planning=self.financial_planning) for private_pension in protection_manager.private_pensions.all(): private_pension.delete() for life_insurance in protection_manager.life_insurances.all(): life_insurance.delete() LifeInsuranceFactory(protection_manager=protection_manager, value_to_pay_annual=2000, has_year_end=False) def test_annual_leftovers_for_goal_without_change(self): array = [ 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257 ] self.assertEqual(self.financial_planning.annual_leftovers_for_goal(), array) def test_annual_leftovers_without_change(self): array = [ 647364.8, 647364.8, 647364.8, 647364.8, 647364.8, 647364.8, 647364.8, 647364.8, 647364.8, 647364.8 ] self.assertEqual(self.financial_planning.annual_leftovers(), array) def test_annual_leftovers_for_goal_with_change(self): FlowUnitChange.objects.create(annual_value=2000.00, year=2018, incomes=self.patrimony) FlowUnitChange.objects.create(annual_value=2000.00, year=2017, cost_manager=self.cost_manager) FlowUnitChange.objects.create(annual_value=9000.00, year=2026, cost_manager=self.cost_manager) array = [ 605045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 598045.13144555257 ] self.assertEqual(self.financial_planning.annual_leftovers_for_goal(), array) def test_total_resource_for_annual_goals(self): FlowUnitChange.objects.create(annual_value=2000.00, year=2018, incomes=self.patrimony) FlowUnitChange.objects.create(annual_value=2000.00, year=2017, cost_manager=self.cost_manager) FlowUnitChange.objects.create(annual_value=9000.00, year=2026, cost_manager=self.cost_manager) GoalFactory.create_batch(4, goal_manager=self.goal_manager, init_year=2017, end_year=2027, value=65865, periodicity=1) array = [ 341585.13144555251, 413413.10143097816, 491145.17214779771, 573102.25206646265, 659513.98517549736, 750622.49741528649, 846683.07511569967, 947964.88030916872, 1054751.7049235257, 1167342.7659678517 ] self.assertEqual( self.financial_planning.total_resource_for_annual_goals, array) def test_suggested_flow_patrimony(self): array = [ 647364.8, 1319372.6002455815, 2027906.368647767, 2774951.418992036, 3562600.973793622, 4393062.0295134, 5268661.54056872, 6191852.939466794, 7165223.011330091, 8191499.142076154 ] self.assertEqual( self.financial_planning.suggested_flow_patrimony['flow'], array) def test_actual_flow_patrimony(self): array = [ 647364.8, 1295546.2297445768, 1954727.8567590017, 2625096.3638675935, 3306841.6020630263, 4000156.644272876, 4705237.840038632, 5422284.871122657, 6151500.808058847, 6893092.167663001 ] self.assertEqual(self.financial_planning.actual_flow_patrimony['flow'], array)
def setUp(self): self.active_client = ActiveClientFactory() self.financial_planning = FinancialPlanningFactory() self.financial_adviser = FinancialAdviserFactory() self.patrimony = PatrimonyFactory()
class FinancialPlanningTest(TestCase): def setUp(self): self.cost_manager = CostManagerFactory() active_client = ActiveClientMainFactory( birthday=datetime.datetime(1967, 1, 1)) self.patrimony = PatrimonyMainFactory() self.patrimony.incomes.all().update(value_monthly=55000, thirteenth=False, vacation=False) ActiveFactory(value=30000.00, active_manager=self.patrimony.activemanager) ActiveFactory(value=321200.00, active_manager=self.patrimony.activemanager) ArrearageFactory(patrimony=self.patrimony, value=351200.00) self.goal_manager = GoalManagerFactory() GoalFactory.create_batch(4, goal_manager=self.goal_manager, year_init=2017, year_end=2027, value=2500, periodicity=1) self.financial_independece = FinancialIndependenceFactory( duration_of_usufruct=35, remain_patrimony=30000, ) self.financial_planning = FinancialPlanningFactory( active_client=active_client, cost_manager=self.cost_manager, patrimony=self.patrimony, financial_independence=self.financial_independece, goal_manager=self.goal_manager, target_profitability=110, ) def test_duration_financial_planning(self): self.assertEqual( self.financial_planning.duration(), 10) def test_cost_manager_total(self): total = 219.5999999999994 self.assertAlmostEqual(self.cost_manager.total(), total, 4) def test_regular_cost_flow_with_change(self): FlowUnitChange.objects.create(annual_value=123.40, year=2021, cost_manager=self.cost_manager) FlowUnitChange.objects.create(annual_value=-123.40, year=2022, cost_manager=self.cost_manager) flow_regular_cost_change = [2635.1999999999994, 2635.1999999999994, 2635.1999999999994, 2635.1999999999994, 2758.5999999999995, 2635.1999999999994, 2635.1999999999994, 2635.1999999999994, 2635.1999999999994, 2635.1999999999994] self.assertEqual(flow_regular_cost_change, self.cost_manager.flow()) def test_assets_required(self): self.assertAlmostEqual(self.financial_independece.assets_required(), 6447963.5463578859, 4) def test_remain_necessary_for_retirement_with_high_patrimony(self): active_manager = self.patrimony.activemanager active_manager.actives.update(value=30021200.00) self.assertEqual(self.financial_independece. remain_necessary_for_retirement(), 0) def test_remain_necessary_for_retirement(self): self.financial_planning.active_client.\ birthday = datetime.datetime(1978, 1, 1) self.assertAlmostEqual(self.financial_independece. remain_necessary_for_retirement(), 12156.118288258309, 4) def test_real_gain_related_cdi(self): data = {80: 0.02050232558139542, 85: 0.026144186046511697, 90: 0.031786046511627974, 95: 0.03742790697674425, 100: 0.04306976744186053, 105: 0.04871162790697681, 110: 0.054353488372093084, 115: 0.05999534883720936, 120: 0.06563720930232564, 125: 0.07127906976744192, 130: 0.0769209302325582, 135: 0.08256279069767447, 140: 0.08820465116279075, 145: 0.09384651162790703, 150: 0.0994883720930233, 155: 0.10513023255813958, 160: 0.11077209302325586, 165: 0.11641395348837213, 170: 0.12205581395348841, 175: 0.1276976744186047, 180: 0.13333953488372097, 185: 0.13898139534883724, 190: 0.14462325581395352, 195: 0.1502651162790698, 200: 0.15590697674418608} self.assertAlmostEqual(self.financial_planning. real_gain_related_cdi(), data) def test_annual_leftovers_for_goal_without_change(self): array = [607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257] self.assertEqual(self.financial_planning.annual_leftovers_for_goal(), array) def test_annual_leftovers_for_goal_with_change(self): FlowUnitChange.objects.create(annual_value=2000.00, year=2018, incomes=self.patrimony) FlowUnitChange.objects.create(annual_value=2000.00, year=2017, cost_manager=self.cost_manager) FlowUnitChange.objects.create(annual_value=9000.00, year=2026, cost_manager=self.cost_manager) array = [605045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 607045.13144555257, 598045.13144555257] self.assertEqual(self.financial_planning.annual_leftovers_for_goal(), array) def test_total_resource_for_annual_goals(self): FlowUnitChange.objects.create(annual_value=2000.00, year=2018, incomes=self.patrimony) FlowUnitChange.objects.create(annual_value=2000.00, year=2017, cost_manager=self.cost_manager) FlowUnitChange.objects.create(annual_value=9000.00, year=2026, cost_manager=self.cost_manager) GoalFactory.create_batch(4, goal_manager=self.goal_manager, year_init=2017, year_end=2027, value=65865, periodicity=1) array = [341585.13144555251, 413413.10143097816, 491145.17214779771, 573102.25206646265, 659513.98517549736, 750622.49741528649, 846683.07511569967, 947964.88030916872, 1054751.7049235257, 1167342.7659678517] self.assertEqual(self.financial_planning. total_resource_for_annual_goals, array) def test_save_financial_planning(self): financial_planning = FinancialPlanningFactory(init_year=None) self.assertEqual(financial_planning.init_year, datetime.datetime.now().year) def test_end_year(self): self.assertEqual(self.financial_planning.end_year(), 2027)
def test_save_financial_planning(self): financial_planning = FinancialPlanningFactory(init_year=None) self.assertEqual(financial_planning.init_year, datetime.datetime.now().year)