예제 #1
0
    def setUp(self):
        """ Create setup for making sure that meta-data are
        transfered to the status of payments """
        account = a.BankAccount(amount = 1000, interest = 0.001, name = 'Main account', date=datetime(2016,9, 1))
        savings = a.BankAccount(amount = 5000, interest = 0.013, name = 'Savings', date=datetime(2016,9, 1))
        loan = a.Loan(amount = 100000, interest = 0.01, name = 'House Credit', date=datetime(2016,9, 1))

        simulation = a.Simulation(account, savings, loan, name = 'Testsimulation', date=datetime(2016,9, 1))
        simulation.add_regular(from_acc = 'Income',
                               to_acc = account,
                               payment = 2000,
                               interval = 'monthly',
                               date_start = datetime(2016,9,15),
                               day = 15,
                               name = 'Income')

        simulation.add_regular(from_acc = account,
                               to_acc = savings,
                               payment = 500,
                               interval = 'monthly',
                               date_start = datetime(2016,9,30),
                               day = 30,
                               name = 'Savings',
                               meta = {'tax': 100})

        simulation.simulate(delta=timedelta(days=2000))
        self.simulation = simulation
예제 #2
0
def example_meta_controller(print_it=True):
    """ This example shows, how meta-information for payments and account data could
    be used to calculate annual tax-return """
    account = a.BankAccount(amount=1000,
                            interest=0.001,
                            name='Main account',
                            date="01.09.2016")

    # define meta-data for accounts. here: some fields that are relevant for
    # tax calculations
    loan = a.Loan(amount=100000,
                  interest=0.01,
                  name='House Credit',
                  date="01.09.2016",
                  meta={'tax': {
                      'outcome': 'yearly_interests'
                  }})

    # add these accounts to the simulation
    simulation = a.Simulation(account, loan, date='01.09.2016')

    # our employee receives monthly 2000 netto, coming from 2500 brutto,
    # 310 are subtracted directly from the loan, which is less than she
    # needs to pay. 190 are paid for insurance
    simulation.add_regular('Income',
                           account,
                           2000,
                           interval='monthly',
                           date_start="01.09.2016",
                           meta={
                               'type': 'income',
                               'tax': {
                                   'brutto': 2500,
                                   'paid': 310,
                                   'insurance': 190
                               }
                           })

    simulation.add_regular(account,
                           loan,
                           lambda: min(1500, -loan.account),
                           interval='monthly',
                           date_start="01.09.2016")
    simulation.add_controller(controller_tax)

    # simulate for ten years
    simulation.simulate(delta=timedelta(days=365 * 10))

    # this function is also part of a unittest. Therefore, we want to be able to
    # control, whether we print some information or not
    if print_it:
        # print reports summarized in years
        print(account.report.with_meta())
        #print(loan.report.with_meta())
    return simulation
예제 #3
0
def example3():
    account = a.BankAccount(amount=1000, interest=0.001, name='Main account')
    savings = a.BankAccount(amount=5000, interest=0.013, name='Savings')
    loan = a.Loan(amount=100000, interest=0.01, name='House Credit')

    simulation = a.Simulation(account, savings, loan, name='Testsimulation')
    simulation.add_regular(from_acc='Income',
                           to_acc=account,
                           payment=2000,
                           interval='monthly',
                           date_start=datetime(2016, 9, 15),
                           day=15,
                           name='Income')

    simulation.add_regular(from_acc=account,
                           to_acc=savings,
                           payment=500,
                           interval='monthly',
                           date_start=datetime(2016, 9, 30),
                           day=30,
                           name='Savings')

    simulation.add_regular(from_acc=account,
                           to_acc=loan,
                           payment=1000,
                           interval='monthly',
                           date_start=datetime(2016, 9, 15),
                           day=15,
                           name='Debts',
                           fixed=False,
                           date_stop=lambda cdate: loan.is_finished())

    simulation.add_regular(
        from_acc=account,
        to_acc=loan,
        payment=lambda: min(8000, max(0,
                                      account.get_account() - 4000)),
        interval='yearly',
        date_start=datetime(2016, 11, 20),
        day=20,
        name='Debts',
        fixed=False,
        date_stop=lambda cdate: loan.is_finished())

    simulation.simulate(delta=timedelta(days=2000))

    simulation.plt_summary()
    show()

    print(account.report)
    print(loan.report)
예제 #4
0
def dependencies():
    loan = a.Loan(200000, 0.0185, name='Credit')

    # the class property defines a dependency on loan. When loan
    # decreases, the house-property increases
    house = a.Property(200000, 0, loan, name='House')

    simulation = a.Simulation(loan, house)

    simulation.add_regular('Income', loan, 1000, interval='monthly')

    simulation.simulate(delta=timedelta(days=365 * 20))
    simulation.plt_summary()
    show(block=True)
예제 #5
0
def example2():
    # create a private bank account and a loan
    account = a.BankAccount(amount=1000, interest=0.001, name='Main account')
    savings = a.BankAccount(amount=5000, interest=0.007, name='Savings')
    loan = a.Loan(amount=100000, interest=0.01, name='House Credit')

    # add these accounts to the simulation
    simulation = a.Simulation(account, savings, loan)

    # describe single or regular payments between accounts. note, that
    # a string can be used for external accounts that you don't want to model.
    # also note the lambda function for the payments to the loan.
    simulation.add_regular('Income', account, 2000, interval='monthly')
    simulation.add_regular(account, savings, 500, interval='monthly')
    simulation.add_regular(account,
                           loan,
                           lambda: min(1500, -loan.account),
                           interval='monthly')
    simulation.add_unique(savings, 'Vendor for car', 10000, '17.03.2019')

    # simulate for ten years
    simulation.simulate(delta=timedelta(days=365 * 10))
    # plot the data
    simulation.plt_summary()

    # print reports summarized in years
    print(account.report.yearly().as_df())
    print(loan.report.yearly().as_df())

    # analyze data
    print("Bank account: %.2f" % (account.account + savings.account))

    cwd = os.path.dirname(os.path.realpath(__file__))
    result_folder = cwd + '/example2'

    html.report(simulation, style="standard", output_dir=result_folder)
    show()
예제 #6
0
def example1():
    # create a private bank account and a loan
    account = a.BankAccount(amount=1000, interest=0.001, name='Main account')
    loan = a.Loan(amount=100000, interest=0.01, name='House Credit')

    # add these accounts to the simulation
    simulation = a.Simulation(account, loan)

    # describe single or regular payments between accounts. note, that
    # a string can be used for external accounts that you don't want to model.
    # also note the lambda function for the payments to the loan.
    simulation.add_regular('Income', account, 2000, interval='monthly')
    # you can also use lambda function to dynamically decide how much money
    # you would like to transfer
    simulation.add_regular(account,
                           loan,
                           lambda: min(1500, -loan.account),
                           interval='monthly')

    # simulate for ten years
    simulation.simulate(delta=timedelta(days=365 * 10))
    # plot the data
    simulation.plt_summary()
    show()

    # print reports summarized in years
    print(account.report.yearly().as_df())
    print(loan.report.yearly().as_df())

    # analyze data
    print("Interests on bank account: %.2f" %
          sum(account.report.yearly().interest))
    print("Interests on loan account: %.2f" %
          sum(loan.report.yearly().interest))

    return simulation
예제 #7
0
    def setUp(self):
        """ Mostly taken from examples/simple_example.py """
        account = a.BankAccount(amount=1000,
                                interest=0.001,
                                name='Main account',
                                date=datetime(2016, 9, 1))
        savings = a.BankAccount(amount=5000,
                                interest=0.013,
                                name='Savings',
                                date=datetime(2016, 9, 1))
        loan = a.Loan(amount=100000,
                      interest=0.01,
                      name='House Credit',
                      date=datetime(2016, 9, 1))

        simulation = a.Simulation(account,
                                  savings,
                                  loan,
                                  name='Testsimulation',
                                  date=datetime(2016, 9, 1))
        simulation.add_regular(from_acc='Income',
                               to_acc=account,
                               payment=2000,
                               interval='monthly',
                               date_start=datetime(2016, 9, 15),
                               day=15,
                               name='Income')

        simulation.add_regular(from_acc=account,
                               to_acc=savings,
                               payment=500,
                               interval='monthly',
                               date_start=datetime(2016, 9, 30),
                               day=30,
                               name='Savings')

        simulation.add_regular(from_acc=account,
                               to_acc=loan,
                               payment=1000,
                               interval='monthly',
                               date_start=datetime(2016, 9, 15),
                               day=15,
                               name='Debts',
                               fixed=False,
                               date_stop=lambda cdate: loan.is_finished())

        simulation.add_regular(
            from_acc=account,
            to_acc=loan,
            payment=lambda: min(8000, max(0,
                                          account.get_account() - 4000)),
            interval='yearly',
            date_start=datetime(2016, 11, 20),
            day=20,
            name='Debts',
            fixed=False,
            date_stop=lambda cdate: loan.is_finished())

        simulation.simulate(delta=timedelta(days=2000))

        self.simulation = simulation
        self.account = account
        self.loan = loan