# Question 1 symbols = ['SBUX'] start_date = datetime(1993, 3, 31) end_date = datetime(2008, 3, 31) fields = "Adj Close" data = da.get_data(symbols, start_date, end_date, fields) monthly = data.asfreq('M', method='ffill') monthly.plot() plt.title('Montly Data') plt.draw() # Question 2 and 3 total_return = Calculator.ret(data) q2 = Calculator.FV(PV=10000, R=total_return) print(2, q2) # Question 3 q3 = Calculator.ann_ret(R=total_return, m=1 / 15) print(3, q3) # Question 4 monthly_ln = monthly.apply(np.log) monthly_ln.plot() plt.title('Montly Natural Logarithm') plt.draw() # Question 5 monthly_returns = Calculator.returns(monthly) monthly_returns.plot()
starbucks = pd.DataFrame(data, columns=['Date', 'Value']).set_index('Date')['Value'] ''' Question 1: Using the data in the table, what is the simple monthly return between the end of December 2004 and the end of January 2005? Ans: -13.40% ''' q1 = Calculator.ret(starbucks, pos=1) # q1 = Calculator.R(PV=data[0][1], FV=data[1][1]) # Other option print(1, q1) ''' Question 2: If you invested $10,000 in Starbucks at the end of December 2004, how much would the investment be worth at the end of January 2005? Ans: $8659.39 ''' q2 = Calculator.FV(PV=10000, R=q1) print(2, q2) ''' Question 3: Using the data in the table, what is the continuously compounded monthly return between December 2004 and January 2005? Ans: -14.39% ''' q3 = Calculator.ret(starbucks, pos=1, cc=True) print(3, q3) ''' Question 4: Assuming that the simple monthly return you computed in Question 1 is the same for 12 months, what is the annual return with monthly compounding? Ans: -82.22% ''' q4 = Calculator.ann_ret(R=q1, m=12) print(4, q4)