Ejemplo n.º 1
0
    def test_pay_fees(self):
        alg = self._init_test()
        self._prefill_db(alg)
        trs = Transactions(FILE_NAME)
        fnds = Funds(FILE_NAME)

        accs = alg.pay_fees()
        self.assertEqual(400.0, alg.portfolio_total_fund)
        accounts = [
            (1, '01', 0.0, accs[0][3], 0, 0.7, 0.7, 1, accs[0][-1]),
            (2, '02', 0.375, accs[1][3], 50, 0.3, 0.9, 1, accs[1][-1]),
            (3, '03', 0.125, accs[2][3], -50, 0.3, 0.9, 1, accs[2][-1]),
            (4, '04', 0.5, accs[3][3], 0, 0.3, 0.9, 1, accs[3][-1]),
        ]
        self.assertEqual(accounts, accs)
        acc_trs = trs.retrieve_transactions_for_account(account_id=2)
        self.assertEqual(50, acc_trs[-1][1])
        acc_trs = trs.retrieve_transactions_for_account(account_id=3)
        self.assertEqual(-50, acc_trs[-1][1])
        acc_trs = trs.retrieve_transactions_for_account(account_id=4)
        self.assertEqual(-50, acc_trs[-2][1])
        self.assertEqual(50, acc_trs[-1][1])

        acc_fnds = fnds.retrieve_funds_for_account(account_id=2)
        self.assertEqual(150, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=3)
        self.assertEqual(50, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=4)
        self.assertEqual(150, acc_fnds[-2][1])
        self.assertEqual(200, acc_fnds[-1][1])
Ejemplo n.º 2
0
    def test_add_account(self):
        alg = self._init_test()
        prt = Portfolio(FILE_NAME)
        fnds = Funds(FILE_NAME)

        accs = alg.add_account(name='01', fee=0, risk=0.7, profit=0.7, fund=0.0)
        self.assertEqual(0.0, alg.portfolio_total_fund)
        accounts = [(1, '01', 0.0, accs[0][3], 0, 0.7, 0.7, 1, accs[0][-1])]
        self.assertEqual(accounts, accs)
        prt_data = prt.retrieve_id(1)
        self.assertEqual(-1, prt_data[-1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=1)
        self.assertEqual(0, acc_fnds[-1][1])

        accs = alg.add_account(name="03", fee=0, risk=0.3, profit=0.9, fund=100.0,  is_main=True)
        self.assertEqual(100.0, alg.portfolio_total_fund)
        accounts = [
            (1, '01', 0.0, accs[0][3], 0, 0.7, 0.7, 1, accs[0][-1]),
            (2, '03', 1.0, accs[1][3], 0, 0.3, 0.9, 1, accs[1][-1]),
        ]
        self.assertEqual(accounts, accs)
        prt_data = prt.retrieve_id(1)
        self.assertEqual(2, prt_data[-1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=2)
        self.assertEqual(100, acc_fnds[-1][1])

        os.remove(FILE_NAME)
    def test_create_Fund(self):
        if os.path.isfile(FILE_NAME):
            os.remove(FILE_NAME)
        create_db(FILE_NAME)
        fund = Funds(FILE_NAME)

        c = fund.create_fund(-20000, 1)
        ts = c[2]
        self.assertEqual((1, -20000, ts, 1), c)

        os.remove(FILE_NAME)
    def test_retrieve_id(self):
        if os.path.isfile(FILE_NAME):
            os.remove(FILE_NAME)
        create_db(FILE_NAME)
        fund = Funds(FILE_NAME)
        fund.create_fund(10, 1)

        c = fund.retrieve_id(id=1)
        ts = c[2]
        self.assertEqual((1, 10, ts, 1), c)

        os.remove(FILE_NAME)
    def test_retrieve_accounts(self):
        if os.path.isfile(FILE_NAME):
            os.remove(FILE_NAME)
        create_db(FILE_NAME)
        fund = Funds(FILE_NAME)
        fund.create_fund(10, 1)
        fund.create_fund(20, 1)

        c = fund.retrieve_funds()
        ts1 = c[0][2]
        ts2 = c[1][2]
        self.assertEqual([(1, 10, ts1, 1), (2, 20, ts2, 1)], c)

        os.remove(FILE_NAME)
Ejemplo n.º 6
0
    def test_make_transaction(self):
        alg = self._init_test()
        self._prefill_db(alg)
        trs = Transactions(FILE_NAME)
        fnds = Funds(FILE_NAME)

        accs = alg.make_transaction('01', 100)
        self.assertEqual(500.0, alg.portfolio_total_fund)
        accounts = [
            (1, '01', 0.2, accs[0][3], 0, 0.7, 0.7, 1, accs[0][-1]),
            (2, '02', 0.2, accs[1][3], 50, 0.3, 0.9, 1, accs[1][-1]),
            (3, '03', 0.2, accs[2][3], -50, 0.3, 0.9, 1, accs[2][-1]),
            (4, '04', 0.4, accs[3][3], 0, 0.3, 0.9, 1, accs[3][-1]),
        ]
        self.assertEqual(accounts, accs)
        acc_trs = trs.retrieve_transactions_for_account(account_id=1)
        self.assertEqual(100, acc_trs[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=1)
        self.assertEqual(100, acc_fnds[-1][1])

        accs = alg.make_transaction('02', -100)
        self.assertEqual(400.0, alg.portfolio_total_fund)
        accounts = [
            (1, '01', 0.25, accs[0][3], 0, 0.7, 0.7, 1, accs[0][-1]),
            (2, '02', 0.0, accs[1][3], 50, 0.3, 0.9, 1, accs[1][-1]),
            (3, '03', 0.25, accs[2][3], -50, 0.3, 0.9, 1, accs[2][-1]),
            (4, '04', 0.5, accs[3][3], 0, 0.3, 0.9, 1, accs[3][-1]),
        ]
        self.assertEqual(accounts, accs)
        acc_trs = trs.retrieve_transactions_for_account(account_id=2)
        self.assertEqual(-100, acc_trs[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=2)
        self.assertEqual(0, acc_fnds[-1][1])

        accs = alg.make_transaction('03', -150)
        self.assertEqual(400.0, alg.portfolio_total_fund)
        self.assertEqual(False, accs)
        acc_trs = trs.retrieve_transactions_for_account(account_id=3)
        self.assertEqual(0, len(acc_trs))
        acc_fnds = fnds.retrieve_funds_for_account(account_id=3)
        self.assertEqual(100, acc_fnds[-1][1])
Ejemplo n.º 7
0
    def test_update_total_fund_without_main(self):
        alg = self._init_test()
        self._prefill_db(alg)
        alg.remove_main()
        fnds = Funds(FILE_NAME)

        accs = alg.update_total_fund(new_fund=800)
        self.assertEqual(800.0, alg.portfolio_total_fund)
        accounts = [
            (1, '01', 0.0, accs[0][3], 0, 0.7, 0.7, 1, accs[0][-1]),
            (2, '02', 0.25, accs[1][3], 50, 0.3, 0.9, 1, accs[1][-1]),
            (3, '03', 0.25, accs[2][3], -50, 0.3, 0.9, 1, accs[2][-1]),
            (4, '04', 0.5, accs[3][3], 0, 0.3, 0.9, 1, accs[3][-1]),
        ]
        self.assertEqual(accounts, accs)
        acc_fnds = fnds.retrieve_funds_for_account(account_id=1)
        self.assertEqual(0, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=2)
        self.assertEqual(200, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=3)
        self.assertEqual(200, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=4)
        self.assertEqual(400, acc_fnds[-1][1])

        accs = alg.update_total_fund(new_fund=200)
        self.assertEqual(200.0, alg.portfolio_total_fund)
        accounts = [
            (1, '01', 0.0, accs[0][3], 0, 0.7, 0.7, 1, accs[0][-1]),
            (2, '02', 0.25, accs[1][3], 50, 0.3, 0.9, 1, accs[1][-1]),
            (3, '03', 0.25, accs[2][3], -50, 0.3, 0.9, 1, accs[2][-1]),
            (4, '04', 0.5, accs[3][3], 0, 0.3, 0.9, 1, accs[3][-1]),
        ]
        self.assertEqual(accounts, accs)
        acc_fnds = fnds.retrieve_funds_for_account(account_id=1)
        self.assertEqual(0, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=2)
        self.assertEqual(50, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=3)
        self.assertEqual(50, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=4)
        self.assertEqual(100, acc_fnds[-1][1])
Ejemplo n.º 8
0
    def test_internal_transaction(self):
        alg = self._init_test()
        self._prefill_db(alg)
        trs = Transactions(FILE_NAME)
        fnds = Funds(FILE_NAME)

        accs = alg.internal_transaction(sender_name='02', reciever_name='01', amount=50)
        self.assertEqual(400.0, alg.portfolio_total_fund)
        accounts = [
            (1, '01', 0.125, accs[0][3], 0, 0.7, 0.7, 1, accs[0][-1]),
            (2, '02', 0.125, accs[1][3], 50, 0.3, 0.9, 1, accs[1][-1]),
            (3, '03', 0.25, accs[2][3], -50, 0.3, 0.9, 1, accs[2][-1]),
            (4, '04', 0.5, accs[3][3], 0, 0.3, 0.9, 1, accs[3][-1]),
        ]
        self.assertEqual(accounts, accs)
        acc_trs = trs.retrieve_transactions_for_account(account_id=1)
        self.assertEqual(50, acc_trs[-1][1])
        acc_trs = trs.retrieve_transactions_for_account(account_id=2)
        self.assertEqual(-50, acc_trs[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=1)
        self.assertEqual(50, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=2)
        self.assertEqual(50, acc_fnds[-1][1])

        accs = alg.internal_transaction(sender_name='02', reciever_name='01', amount=100)
        self.assertEqual(400.0, alg.portfolio_total_fund)
        self.assertEqual(False, accs)
        acc_trs = trs.retrieve_transactions_for_account(account_id=1)
        self.assertEqual(50, acc_trs[-1][1])
        acc_trs = trs.retrieve_transactions_for_account(account_id=2)
        self.assertEqual(-50, acc_trs[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=1)
        self.assertEqual(50, acc_fnds[-1][1])
        acc_fnds = fnds.retrieve_funds_for_account(account_id=2)
        self.assertEqual(50, acc_fnds[-1][1])
    def test_retrieve_funds_for_account(self):
        if os.path.isfile(FILE_NAME):
            os.remove(FILE_NAME)
        create_db(FILE_NAME)
        trs = Funds(FILE_NAME)
        trs.create_fund(10, 1)
        trs.create_fund(20, 2)
        trs.create_fund(30, 1)
        trs.create_fund(40, 3)

        c = trs.retrieve_funds_for_account(1)
        ts1 = c[0][2]
        ts2 = c[1][2]
        self.assertEqual([(1, 10, ts1, 1), (3, 30, ts2, 1)], c)

        os.remove(FILE_NAME)
    def test_delete_id(self):
        if os.path.isfile(FILE_NAME):
            os.remove(FILE_NAME)
        create_db(FILE_NAME)
        fund = Funds(FILE_NAME)
        fund.create_fund(10, 1)
        fund.create_fund(20, 1)

        c = fund.delete_id(1)
        self.assertEqual(True, c)

        c = fund.delete_id(2)
        self.assertEqual(True, c)

        os.remove(FILE_NAME)
    def test_update_id(self):
        if os.path.isfile(FILE_NAME):
            os.remove(FILE_NAME)
        create_db(FILE_NAME)
        fund = Funds(FILE_NAME)
        fund.create_fund(10, 1)

        c = fund.update_id(id=1, amount=20, account_fk=2)
        ts = c[2]
        self.assertEqual((1, 20, ts, 2), c)

        c = fund.update_id(id=1, amount=10)
        ts = c[2]
        self.assertEqual((1, 10, ts, 2), c)

        c = fund.update_id(id=1, account_fk=1)
        ts = c[2]
        self.assertEqual((1, 10, ts, 1), c)

        c = fund.update_id(id=1, amount=0)
        ts = c[2]
        self.assertEqual((1, 0, ts, 1), c)

        os.remove(FILE_NAME)
 def createAccount(self):
     newAccount = Funds()
     self.setFunds(newAccount.getFundslist())
     self.setBalance(newAccount.getBalancelist())