Beispiel #1
0
def test_BalanceWithStartingValue():

    acc = SavingsAccount.SavingsAccount()

    acc.setStartDate((6, 2018))
    acc.setEndDate((3, 2019))
    acc.setStartingBalance(421)

    acc.addMonthlyContribution(10.0)
    available, unavailable, balance = acc.calculateBalance()

    expectedBalance = [431, 441, 451, 461, 471, 481, 491, 501, 511, 521]
    assert len(balance) == len(expectedBalance)
    for result, expected in zip(balance, expectedBalance):
        assert math.fabs(expected - result) < 5.0e-11, "Diff = " + str(
            math.fabs(expected - result))

    cd1 = CertificateDeposit.CertificateDeposit(Calendar.Calendar(8, 2018),
                                                1.2, 4, 14.0)
    acc.addCertificateDeposit(cd1)

    available, unavailable, balance = acc.calculateBalance()
    expectedBalance = [
        431, 441, 451, 461.014, 471.028014, 481.042042014, 491.056084056,
        501.056084056, 511.056084056, 521.056084056
    ]
    assert len(balance) == len(expectedBalance)
    for result, expected in zip(balance, expectedBalance):
        assert math.fabs(expected - result) < 5.0e-11, "Diff = " + str(
            math.fabs(expected - result))
Beispiel #2
0
def main():
    account = SavingsAccount.SavingsAccount()
    account.setStartDate((10, 2018))
    account.setEndDate((12, 2021))
    account.setGoal(40000.0)
    account.setStartingBalance(4609.29)

    # Setting up simulation
    account.addMonthlyContribution(1600.0)
    cds = []

    # Bought this cd apy=2.7, term=17 on Oct 18
    cds += [
        CertificateDeposit.CertificateDeposit(
            Calendar.Calendar(month=10, year=2018), 2.7, 17, 4609.29)
    ]
    account.addCertificateDeposit(cds[-1])

    # Below is plan to buy
    cds += [
        CertificateDeposit.CertificateDeposit(
            Calendar.Calendar(month=1, year=2019), 1.65, 18, 6400.0)
    ]
    account.addCertificateDeposit(cds[-1])
    cds += [
        CertificateDeposit.CertificateDeposit(
            Calendar.Calendar(month=4, year=2019), 1.4, 15, 4800.0)
    ]
    account.addCertificateDeposit(cds[-1])
    cds += [
        CertificateDeposit.CertificateDeposit(
            Calendar.Calendar(month=7, year=2019), 1.4, 12, 4800.0)
    ]
    account.addCertificateDeposit(cds[-1])
    cds += [
        CertificateDeposit.CertificateDeposit(
            Calendar.Calendar(month=11, year=2019), 0.2, 8, 10200)
    ]
    account.addCertificateDeposit(cds[-1])

    # Planned Deposit from TDECU
    account.addDeposit(Calendar.Calendar(month=11, year=2019), 3800.0)

    # account.plotSimulation()
    account.printBalance()
    for cd in cds:
        value = cd.getMaturityValue() - cd.principle
        thousands = int(value / 1000)
        leftover = value - thousands * 1000
        valueFormat = "{0:6.2f}".format(leftover)
        if thousands > 0:
            valueFormat = " {0:3d},".format(thousands) + valueFormat
        else:
            valueFormat = "     " + valueFormat
        print("Interest Earned: {0:s}, Matured: {1:s}".format(
            valueFormat,
            Calendar.Calendar.convertDateToWords(cd.getMatureDate().date())))
Beispiel #3
0
def test_BalanceWithContribution():

    acc = SavingsAccount.SavingsAccount()

    acc.setStartDate((6, 2018))
    acc.setEndDate((3, 2019))
    acc.addMonthlyContribution(12.0)

    available, unavailable, balance = acc.calculateBalance()

    expectedBalance = [
        12.0, 24.0, 36.0, 48.0, 60.0, 72.0, 84.0, 96.0, 108.0, 120.0
    ]

    for result, expected in zip(balance, expectedBalance):
        assert result == expected
Beispiel #4
0
def test_SetAndGet():

    acc = SavingsAccount.SavingsAccount()

    acc.setStartDate((6, 2018))
    date = Calendar.Calendar(6, 2018)
    assert acc.getStartDate().isDateSame(date.date())

    acc.setEndDate((7, 2018))
    date.setDate(7, 2018)
    assert acc.getEndDate().isDateSame(date.date())

    with pytest.raises(AssertionError):
        acc.setStartDate((8, 2018))
    with pytest.raises(AssertionError):
        acc.setEndDate((5, 2018))
Beispiel #5
0
def test_addDeposit():

    acc = SavingsAccount.SavingsAccount()

    acc.setStartDate((6, 2018))
    acc.setEndDate((3, 2019))
    acc.setStartingBalance(421)

    acc.addDeposit(Calendar.Calendar(8, 2018), 25.4)
    acc.addDeposit(Calendar.Calendar(1, 2019), 56.1)

    expectedBalance = [
        421, 421, 446.4, 446.4, 446.4, 446.4, 446.4, 502.5, 502.5, 502.5
    ]

    available, unavailable, balance = acc.calculateBalance()

    for expected, result in zip(expectedBalance, balance):
        assert math.fabs(expected - result) < 5.0e-11, "Diff = " + str(
            math.fabs(expected - result))
Beispiel #6
0
def test_BalanceWithCDonly():

    acc = SavingsAccount.SavingsAccount()

    acc.setStartDate((6, 2018))
    acc.setEndDate((3, 2019))
    acc.setStartingBalance(14)

    cd1 = CertificateDeposit.CertificateDeposit(Calendar.Calendar(6, 2018),
                                                1.2, 4, 14.0)
    acc.addCertificateDeposit(cd1)

    available, unavailable, balance = acc.calculateBalance()

    expectedBalance = [
        14, 14.014, 14.028014, 14.042042014, 14.056084056, 14.056084056,
        14.056084056, 14.056084056, 14.056084056, 14.056084056
    ]

    assert len(balance) == len(expectedBalance)
    for result, expected in zip(balance, expectedBalance):
        assert math.fabs(expected - result) < 5.0e-11, "Diff = " + str(
            math.fabs(expected - result))
Beispiel #7
0
def test_BalanceWithCDandContribution():

    acc = SavingsAccount.SavingsAccount()

    acc.setStartDate((6, 2018))
    acc.setEndDate((3, 2019))

    acc.addMonthlyContribution(10.0)

    cd1 = CertificateDeposit.CertificateDeposit(Calendar.Calendar(8, 2018),
                                                1.2, 4, 14.0)
    acc.addCertificateDeposit(cd1)

    available, unavailable, balance = acc.calculateBalance()

    expectedBalance = [
        10, 20, 30, 40.014, 50.028014, 60.042042014, 70.056084056,
        80.056084056, 90.056084056, 100.056084056
    ]

    assert len(balance) == len(expectedBalance)
    for result, expected in zip(balance, expectedBalance):
        assert math.fabs(expected - result) < 5.0e-11, "Diff = " + str(
            math.fabs(expected - result))
Beispiel #8
0
def test_Construction():

    acc = SavingsAccount.SavingsAccount()
    assert acc.getStartDate() is None
    assert acc.getEndDate() is None
    assert acc.getMonthlyContribution() == []