เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

The time series of weights

In the previous exercise, you explored the functionality of the Return.portfolio() function and created portfolios using two strategies. However, by setting the argument verbose = TRUE in Return.portfolio() you can create a list of beginning of period (BOP) and end of period (EOP) weights and values in addition to the portfolio returns, and contributions.

You can access these from the resultant list-object created from Return.portfolio(). The resultant list contains $returns, $contributions, $BOP.Weight, $EOP.Weight, $BOP.Value, and $EOP.Value.

In this exercise, you will recreate the portfolios you made in the last exercise but extend it by creating a list of calculations using verbose = TRUE. You will then visualize the end of period weights of Apple.

The object returns is pre-loaded in your workspace.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Portfolio Analysis in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Define the vector eq_weights for two equally weighted assets.
  • Create a portfolio of returns by using the buy and hold strategy and setting verbose = TRUE. Call this pf_bh.
  • Create a portfolio of returns using the monthly rebalancing strategy and setting verbose = TRUE. Call this pf_rebal.
  • Create a new object called eop_weight_bhusing the end of period weights of pf_bh.
  • Create a new object called eop_weight_rebal using the end of period weights of pf_rebal.
  • Plot the end of period weights of Apple in eop_weight_bh using plot.zoo(), and the end of period weights of Apple in eop_weight_rebal using plot.zoo(). par(mfrow = c(2, 1), mar = c(2, 4, 2, 2)) is used to organize the plots you create. Do not alter this code.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Create the weights
eq_weights <-

# Create a portfolio using buy and hold
pf_bh <- Return.portfolio(returns, weights = eq_weights, ___ )

# Create a portfolio that rebalances monthly
pf_rebal <- Return.portfolio(returns, weights = eq_weights, rebalance_on = "months", ___ )

# Create eop_weight_bh


# Create eop_weight_rebal


# Plot end of period weights
par(mfrow = c(2, 1), mar=c(2, 4, 2, 2))
plot.zoo(___$AAPL)
plot.zoo(___$AAPL)
แก้ไขและรันโค้ด