程序代写代做 Quiz 2: R

Quiz 2: R
Submission:
You only need to submit a R file, named QuizR.PolyUID.LastName.FirstName.R.
For example, your name is George Washington and your ID 1900000D, then the R file to submit is QuizR.1900000D.Washington.George.R
Consider a mutual fund using 40/60 strategy, i.e., 40% of fund will be invested in bond and 60% will be invested in stock. Assume rebalancing will be done at the 1st day of each quarter. Suppose the fund was established on 2015-04-01 with $100 million. We use SPY as the proxy of stock and TLT as the proxy of bond. On 2015-04-01, the fund will use $60 million to buy SPY and $40 million to buy TLT. After that, rebalancing will be done at the 1st day of each quarter. For example, on 2015-07-01, if the SPY part had gone down to $50million with SPY price went down and TLT part had gone up to $50 million with TLT price went up. Then the funds should sell $10million of TLT and purchase $10million of SPY to make it still 40/60. In another word, with the price goes up or down, the proportion of SPY and TLT will deviate from 40%/60%. Then at the 1st day of each quarter, a rebalancing is needed. For simplicity, we use the open price of SPY and TLT on the 1st day of each quarter to calculate the portfolio value and how to rebalance.
Write R code to calculate on 2020-1-2, the value of the portfolio, before rebalancing, following the steps below.
1. Read TLT.csv and SPY.csv into TLT data frame and SPY data frame
2. Remove all the not necessary data, including Close, High, Low, Adj.Close, and Volume
3. Add new columns, $year, $month and $day, and assign them value based on $Date
4. Keep only the data of the 1st trading day of the quarter (note: not necessary Jan. 1/Apr.
1…..)
5. Merge the two data frames into Portfolio by Date, year, month, and day
6. Calculate the initial shares of SPY and TLT in the portfolio
7. Rebalancing. Calculate the initial shares of SPY and TLT in the portfolio after rebalancing.
8. Display the portfolio value on 2020-01-02
Quiz starts at 3:20PM and ends at 4:30PM. We allow 30min grace period for submission considering various reported networking problem. Any submission after 5PM will not be accepted.