開始使用免費開始

彙總對數報酬序列

在統計學中,彙總資料是指由多次量測合併而成的資料。你剛學到,可以用對應的 apply.weekly()apply.monthly()apply.quarterly() 函式,將每日對數報酬加總,來得到每週、每月與每季的對數報酬。

例如,你可以使用以下程式碼,為單變量時間序列 data 與多變量時間序列 mv_data 建立季報酬:

> # apply.quarterly(x, FUN, ...)
> data_q = apply.quarterly(data, sum)
> mv_data_q = apply.quarterly(mv_data, colSums)

在本練習中,你會練習使用這些函式來彙總時間序列資料,並繪製結果。工作環境中已提供 DJDJ_const,以及物件 djx(包含 2000-2015 年道瓊指數的每日對數報酬)與 djreturns(包含 2000-2015 年前四檔 DJ_const 股票的每日對數報酬)。對於單變量時間序列請使用 plot,多變量時間序列請使用 plot.zoo

本練習屬於課程

R 的量化風險管理

檢視課程

練習說明

  • 繪製物件 djx
  • 用單行程式,以直條顯示 djx 的每週對數報酬。
  • 以直條顯示 djx 的每月對數報酬。
  • 使用 plot.zoo 繪製物件 djreturns
  • 使用 plot.zoo 以直條顯示 djreturns 的每月對數報酬。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Plot djx
___(___)

# Plot weekly log-returns of djx
___(___, ___)

# Plot monthly log-returns of djx
___(___, ___)

# Plot djreturns
___(___)

# Plot monthly log-returns of djreturns
___(___, ___)
編輯並執行程式碼