Created
July 18, 2017 03:51
-
-
Save akshaykarnawat/e96a7c4b151ca5108b9afc15c8c963b5 to your computer and use it in GitHub Desktop.
Find the benefit of investing in a CD Ladder compared to the High Yield Online Savings account given some assumptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
''' | |
### Benefits of CD Ladder vs. Online Savings | |
Find the benefit of investing in a CD Ladder compared to the High Yield Online Savings account given some assumptions. | |
Assumptions: | |
* Investment in CD Ladder for various buckets; not the highest CD bucket rate available for the term. | |
* Only considers CD buckets that have the higher interest rate than the online savings account. | |
* Equal distribution into each selected bucket; based on the above assumptions. | |
* Automatic renewal of the CD at the end of the CD bucket term for the numbers of years specified. | |
* If renewal is over the numbers of years specified, the renewal will be ignored and the money from that bucket will not be invested again. | |
''' | |
# #### Inputs: | |
amount_to_invest = float(10000.00) | |
number_of_years_to_invest = int(5) | |
# Goldman Sachs Online Savings interest rate | |
high_yield_savings_rate = {1: 0.012} | |
# cd rates from Barclays Online CDs | |
cd_rates = {0.25: 0.0035, | |
0.50: 0.0055, | |
0.75: 0.0060, | |
1: 0.0144, | |
1.5: 0.0149, | |
2: 0.0169, | |
3: 0.0193, | |
4: 0.0203, | |
5: 0.0227} | |
# #### Calculations: | |
def compound_interest(principal, rate, payments_in_year, number_of_years): | |
return principal*(1+(rate/payments_in_year))**(payments_in_year*number_of_years) | |
# amount at the end of the term if invested into savings | |
# a = principal(1 + (rate/num of payments in year)^(number of payments in year * years to invest) | |
interest_in_savings = compound_interest(amount_to_invest, high_yield_savings_rate.get(1), 12, number_of_years_to_invest) - amount_to_invest | |
print("Interest earned while investing in a High-Yield Savings Account for {0} years: ${1:.2f}".format(number_of_years_to_invest, interest_in_savings)) | |
# assuming equal distribution for initial investment where the % is more than the savings rates | |
# assuming automatic renewal of the CD with the interest earned at the end of each term | |
where_to_invest = {k: v for k, v in cd_rates.items() if v > high_yield_savings_rate.get(1)} | |
amount_to_invest_in_each_bucket = amount_to_invest / len(where_to_invest) | |
print("Investing ${0:.2f} in the following CD buckets: {1}".format(amount_to_invest, where_to_invest)) | |
# for each key value pair in the cd_rates | |
# if the value of the key is greater than the savings rate | |
# then find the amount at the end of the years to invest term | |
total_interest_earned_from_cd = 0 | |
for k, v in where_to_invest.items(): | |
amount_at_end_of_term = compound_interest(amount_to_invest_in_each_bucket, v, 1, int(number_of_years_to_invest/k)*k) | |
total_interest_earned_from_cd += (amount_at_end_of_term - amount_to_invest_in_each_bucket) | |
print("Investing in a {0:<4} year CD @ {1:.2%} {2} time(s) will result in ${3:.2f} at the end of the {4} year term".format(k, v, int(number_of_years_to_invest/k), amount_at_end_of_term, number_of_years_to_invest)) | |
print("Interest earned while investing in a {0} year CD Ladder: ${1:.2f}".format(number_of_years_to_invest, total_interest_earned_from_cd)) | |
print("You will have an additional ${0:.2f} if invested in a CD ladder for {1} years with the assumptions stated above.".format(total_interest_earned_from_cd - interest_in_savings, number_of_years_to_invest)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment