The following list details the returns on 10 investment funds for the period 2009 - 2018. The information listed is year, name, percentage return.
You are considering investing in one or more of the funds.
You are to develop methods (7) that will (using the data below):
funds = [
[2009, "Emerging Market Equity", 78.51],
[2009, "High-Yield Bond", 58.21],
[2009, "Mid Cap", 40.48],
[2009, "Large Growth", 37.21],
[2009, "International Stocks", 31.78],
[2009, "Small Cap", 27.17],
[2009, "S & P 500", 26.46],
[2009, "Large Value", 19.69],
[2009, "TIPS", 11.41],
[2009, "Bonds", 5.93],
[2010, "Emerging Market Equity", 18.88],
[2010, "High-Yield Bond", 15.12],
[2010, "Mid Cap", 25.48],
[2010, "Large Growth", 16.71],
[2010, "International Stocks", 7.75],
[2010, "Small Cap", 26.85],
[2010, "S & P 500", 15.06],
[2010, "Large Value", 15.51],
[2010, "TIPS", 6.31],
[2010, "Bonds", 6.54],
[2011, "Emerging Market Equity", -18.42],
[2011, "High-Yield Bond", 4.98],
[2011, "Mid Cap", -1.55],
[2011, "Large Growth", 2.64],
[2011, "International Stocks", -12.14],
[2011, "Small Cap", -4.18],
[2011, "S & P 500", 2.11],
[2011, "Large Value", 0.39],
[2011, "TIPS", 13.56],
[2011, "Bonds", 7.84],
[2012, "Emerging Market Equity", 18.22],
[2012, "High-Yield Bond", 15.81],
[2012, "Mid Cap", 17.28],
[2012, "Large Growth", 15.26],
[2012, "International Stocks", 17.32],
[2012, "Small Cap", 16.35],
[2012, "S & P 500", 16.00],
[2012, "Large Value", 17.51],
[2012, "TIPS", 6.98],
[2012, "Bonds", 4.21],
[2013, "Emerging Market Equity", -2.60],
[2013, "High-Yield Bond", 7.44],
[2013, "Mid Cap", 34.76],
[2013, "Large Growth", 33.48],
[2013, "International Stocks", 22.78],
[2013, "Small Cap", 38.82],
[2013, "S & P 500", 32.39],
[2013, "Large Value", 32.53],
[2013, "TIPS", -8.61],
[2013, "Bonds", -2.02],
[2014, "Emerging Market Equity", -2.19],
[2014, "High-Yield Bond", 2.45],
[2014, "Mid Cap", 13.22],
[2014, "Large Growth", 13.05],
[2014, "International Stocks", -4.90],
[2014, "Small Cap", 4.89],
[2014, "S & P 500", 13.69],
[2014, "Large Value", 13.45],
[2014, "TIPS", 3.64],
[2014, "Bonds", 5.97],
[2015, "Emerging Market Equity", -14.92],
[2015, "High-Yield Bond", -4.47],
[2015, "Mid Cap", -2.44],
[2015, "Large Growth", 5.67],
[2015, "International Stocks", -0.81],
[2015, "Small Cap", -4.41],
[2015, "S & P 500", 1.38],
[2015, "Large Value", -3.83],
[2015, "TIPS", -1.44],
[2015, "Bonds", 0.55],
[2016, "Emerging Market Equity", 11.19],
[2016, "High-Yield Bond", 17.13],
[2016, "Mid Cap", 13.80],
[2016, "Large Growth", 7.08],
[2016, "International Stocks", 1.00],
[2016, "Small Cap", 21.31],
[2016, "S & P 500", 11.96],
[2016, "Large Value", 17.34],
[2016, "TIPS", 4.68],
[2016, "Bonds", 2.65],
[2017, "Emerging Market Equity", 37.28],
[2017, "High-Yield Bond", 7.50],
[2017, "Mid Cap", 18.52],
[2017, "Large Growth", 30.21],
[2017, "International Stocks", 25.03],
[2017, "Small Cap", 14.65],
[2017, "S & P 500", 21.83],
[2017, "Large Value", 13.66],
[2017, "TIPS", 3.01],
[2017, "Bonds", 3.54],
[2018, "Emerging Market Equity", -14.58],
[2018, "High-Yield Bond", -2.08],
[2018, "Mid Cap", -9.06],
[2018, "Large Growth", -1.51],
[2018, "International Stocks", -13.79],
[2018, "Small Cap", -11.01],
[2018, "S & P 500", -4.38],
[2018, "Large Value", -8.27],
[2018, "TIPS", -1.26],
[2018, "Bonds", 0.01]
]
Please Done in Python Format please
Find the python3 code below. Methods 2, 3 and 4 asks for average returns.Since it's about the average, year has no significance here. Comments have been provided throughout the code.
funds = [ [2009, "Emerging Market Equity", 78.51], [2009, "High-Yield Bond", 58.21], [2009, "Mid Cap", 40.48], [2009, "Large Growth", 37.21], [2009, "International Stocks", 31.78], [2009, "Small Cap", 27.17], [2009, "S & P 500", 26.46], [2009, "Large Value", 19.69], [2009, "TIPS", 11.41], [2009, "Bonds", 5.93], [2010, "Emerging Market Equity", 18.88], [2010, "High-Yield Bond", 15.12], [2010, "Mid Cap", 25.48], [2010, "Large Growth", 16.71], [2010, "International Stocks", 7.75], [2010, "Small Cap", 26.85], [2010, "S & P 500", 15.06], [2010, "Large Value", 15.51], [2010, "TIPS", 6.31], [2010, "Bonds", 6.54], [2011, "Emerging Market Equity", -18.42], [2011, "High-Yield Bond", 4.98], [2011, "Mid Cap", -1.55], [2011, "Large Growth", 2.64], [2011, "International Stocks", -12.14], [2011, "Small Cap", -4.18], [2011, "S & P 500", 2.11], [2011, "Large Value", 0.39], [2011, "TIPS", 13.56], [2011, "Bonds", 7.84], [2012, "Emerging Market Equity", 18.22], [2012, "High-Yield Bond", 15.81], [2012, "Mid Cap", 17.28], [2012, "Large Growth", 15.26], [2012, "International Stocks", 17.32], [2012, "Small Cap", 16.35], [2012, "S & P 500", 16.00], [2012, "Large Value", 17.51], [2012, "TIPS", 6.98], [2012, "Bonds", 4.21], [2013, "Emerging Market Equity", -2.60], [2013, "High-Yield Bond", 7.44], [2013, "Mid Cap", 34.76], [2013, "Large Growth", 33.48], [2013, "International Stocks", 22.78], [2013, "Small Cap", 38.82], [2013, "S & P 500", 32.39], [2013, "Large Value", 32.53], [2013, "TIPS", -8.61], [2013, "Bonds", -2.02], [2014, "Emerging Market Equity", -2.19], [2014, "High-Yield Bond", 2.45], [2014, "Mid Cap", 13.22], [2014, "Large Growth", 13.05], [2014, "International Stocks", -4.90], [2014, "Small Cap", 4.89], [2014, "S & P 500", 13.69], [2014, "Large Value", 13.45], [2014, "TIPS", 3.64], [2014, "Bonds", 5.97], [2015, "Emerging Market Equity", -14.92], [2015, "High-Yield Bond", -4.47], [2015, "Mid Cap", -2.44], [2015, "Large Growth", 5.67], [2015, "International Stocks", -0.81], [2015, "Small Cap", -4.41], [2015, "S & P 500", 1.38], [2015, "Large Value", -3.83], [2015, "TIPS", -1.44], [2015, "Bonds", 0.55], [2016, "Emerging Market Equity", 11.19], [2016, "High-Yield Bond", 17.13], [2016, "Mid Cap", 13.80], [2016, "Large Growth", 7.08], [2016, "International Stocks", 1.00], [2016, "Small Cap", 21.31], [2016, "S & P 500", 11.96], [2016, "Large Value", 17.34], [2016, "TIPS", 4.68], [2016, "Bonds", 2.65], [2017, "Emerging Market Equity", 37.28], [2017, "High-Yield Bond", 7.50], [2017, "Mid Cap", 18.52], [2017, "Large Growth", 30.21], [2017, "International Stocks", 25.03], [2017, "Small Cap", 14.65], [2017, "S & P 500", 21.83], [2017, "Large Value", 13.66], [2017, "TIPS", 3.01], [2017, "Bonds", 3.54], [2018, "Emerging Market Equity", -14.58], [2018, "High-Yield Bond", -2.08], [2018, "Mid Cap", -9.06], [2018, "Large Growth", -1.51], [2018, "International Stocks", -13.79], [2018, "Small Cap", -11.01], [2018, "S & P 500", -4.38], [2018, "Large Value", -8.27], [2018, "TIPS", -1.26], [2018, "Bonds", 0.01] ]
# extract years and sort
years = list(set(i[0] for i in funds))
years.sort()
'''
for ease of operations, let's first transform this list into a dict
dict
key = Name of the fund
value = list of return percentages in order (2009 to 2018)
'''
# sort the list funds based on year, if not sorted
# The given list is already sorted.
# uncomment the following line, if list is unsorted
# funds.sort(key = lambda x: x[0])
funds_dict = dict()
for i in funds:
if i[1] in funds_dict:
funds_dict[i[1]].append(i[2])
else:
funds_dict[i[1]] = [i[2]]
# list of funds_dict items. It's a list of lists
# of the form [[fund name, list of returns in each year]]
average_returns = list(funds_dict.items())
# 1. Calculate the average annual return for each fund (print the average)
print("\n---Average Annual Return---")
for key, value in funds_dict.items():
print(key, "==>", round(sum(value)/len(value), 2))
# 2. Find the fund with the highest average return (print the fund name, year and return)
print("\n---Highest Average Return---")
# here, year has no significance as it's average
# sort average_returns based on the sum of return values
average_returns.sort(key = lambda x : sum(x[1]), reverse = True)
max_return_fund = average_returns[0]
print(max_return_fund[0], years[0], "->", years[-1], "==>", round(sum(max_return_fund[1]) / len(max_return_fund[1]), 2))
# 3. Find the fund with the lowest average return (print the fund name, year and return)
print("\n---Lowest Average Return---")
# here, year has no significance as it's average
# average_returns list is already sorted based on the sum of return values
min_return_fund = average_returns[-1]
print(min_return_fund[0], years[0], "->", years[-1], "==>", round(sum(min_return_fund[1]) / len(min_return_fund[1]), 2))
# 4. Find the fund with the average return closest to the average of all of the funds (print the fund name, year and return)
print("\n---Average Return Closest to Overall Average---")
# here, year has no significance as it's average
# find aveage of all the funds
overall_average_return = 0
for i in average_returns:
overall_average_return += (sum(i[1]) / len(i[1]))
# to get average, divide it by total number of funds (10)
overall_average_return /= len(average_returns)
# sort average_returns based on the difference between
# its average return and overall average return
average_returns.sort(key = lambda x : abs(overall_average_return - (sum(x[1]) / len(x[1]))))
nearest_return_fund = average_returns[0]
print(nearest_return_fund[0], years[0], "->", years[-1], "==>", round(sum(nearest_return_fund[1]) / len(nearest_return_fund[1]), 2))
# 5. Find the fund with the highest single year return (print the fund name, year and return)
print("\n---Highest Single Year Return---")
# sort average_returns based on the maximum return value in any year
average_returns.sort(key = lambda x : max(x[1]), reverse = True)
max_return_fund = average_returns[0]
print(max_return_fund[0], years[max_return_fund[1].index(max(max_return_fund[1]))], "==>", max(max_return_fund[1]))
# 6. Find the fund with the lowest single year return (print the fund name, year and return)
print("\n---Lowest Single Year Return---")
# average_returns list is already sorted based on the maximum return value in any year
min_return_fund = average_returns[-1]
print(min_return_fund[0], years[min_return_fund[1].index(max(min_return_fund[1]))], "==>", max(min_return_fund[1]))
# 7. Calculate the amount you would have on 01/01/2019 if you had invested $10,000 in each fund on 01/01/2008, without any withdrawals. (print the name of and final amount for each fund)
print("\n---Maturity Amount on 01/01/2019---")
for key, value in funds_dict.items():
# initial amount
amount = 10000
# add returns on year
for i in value:
amount += amount * (i/100)
# print final amount
print(key, "==> $", round(amount, 2))
Find sample output below.
---Average Annual Return---
Emerging Market Equity ==> 11.14
High-Yield Bond ==> 12.21
Mid Cap ==> 15.05
Large Growth ==> 15.98
International Stocks ==> 7.4
Small Cap ==> 13.04
S & P 500 ==> 13.65
Large Value ==> 11.8
TIPS ==> 3.83
Bonds ==> 3.52
---Highest Average Return---
Large Growth 2009 -> 2018 ==> 15.98
---Lowest Average Return---
Bonds 2009 -> 2018 ==> 3.52
---Average Return Closest to Overall Average---
Emerging Market Equity 2009 -> 2018 ==> 11.14
---Highest Single Year Return---
Emerging Market Equity 2009 ==> 78.51
---Lowest Single Year Return---
Bonds 2011 ==> 7.84
---Maturity Amount on 01/01/2019---
Emerging Market Equity ==> $ 21629.59
High-Yield Bond ==> $ 28708.01
Mid Cap ==> $ 37159.81
Large Growth ==> $ 41483.21
International Stocks ==> $ 18454.37
Small Cap ==> $ 30981.91
S & P 500 ==> $ 34300.42
Large Value ==> $ 28851.35
TIPS ==> $ 14301.75
Bonds ==> $ 14074.53
Kindly upvote, if ypu find this answer helpful.
Get Answers For Free
Most questions answered within 1 hours.