示例#1
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())))
示例#2
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))
示例#3
0
def test_valueCalculation():
    cd = CertificateDeposit.CertificateDeposit(start=Calendar.Calendar(
        10, 2018),
                                               apy=1.2,
                                               term=4,
                                               principle=14)

    expectedValue = 14.056084056
    result = cd.getMaturityValue()
    assert math.fabs((result - expectedValue)) < 5.0e-11, "Diff = " + str(
        math.fabs(expectedValue - result))
示例#4
0
def test_monthlyValue():
    cd = CertificateDeposit.CertificateDeposit(start=Calendar.Calendar(
        10, 2018),
                                               apy=1.2,
                                               term=4,
                                               principle=14)

    expectedValue = [14, 14.014, 14.028014, 14.042042014, 14.056084056]
    result = cd.getMonthlyValue()

    for expected, value in zip(expectedValue, result):
        assert math.fabs(expected - value) < 5.0e-11, "Diff = " + str(
            math.fabs(expected - value))
示例#5
0
def test_Construction():
    cd = CertificateDeposit.CertificateDeposit(start=Calendar.Calendar(
        10, 2018),
                                               apy=1.2,
                                               term=3,
                                               principle=1)

    assert cd.getMatureDate().date() == (1, 2019)

    cd2 = CertificateDeposit.CertificateDeposit(start=Calendar.Calendar(
        10, 2018),
                                                apy=1.2,
                                                term=18,
                                                principle=1)
    assert cd2.getMatureDate().date() == (4, 2020)

    # Check error conditions on construction
    with pytest.raises(AssertionError):
        cd1 = CertificateDeposit.CertificateDeposit(start=None,
                                                    apy=1.2,
                                                    term=3)
        cd2 = CertificateDeposit.CertificateDeposit(start=Calendar.Calendar(
            2, 2000),
                                                    apy=-1,
                                                    term=3,
                                                    principle=1)
        cd3 = CertificateDeposit.CertificateDeposit(start=Calendar.Calendar(
            2, 2000),
                                                    apy=101,
                                                    term=3,
                                                    principle=1)
        cd4 = CertificateDeposit.CertificateDeposit(start=Calendar.Calendar(
            2, 2000),
                                                    apy=1,
                                                    term=-3,
                                                    principle=1)
        cd5 = CertificateDeposit.CertificateDeposit(start=Calendar.Calendar(
            2, 2000),
                                                    apy=1,
                                                    term=3,
                                                    principle=-1)
示例#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))
示例#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))