開始使用免費開始

彙總不規則的日內資料

日內資料量通常非常龐大:每天可能有數十萬筆觀測值、每月數百萬筆、每年上億筆。這類資料集在你開始分析之前,往往需要先做彙總。

你已在「Introduction to xts and zoo」課程中學過如何彙總每日資料。這個練習會使用 to.period() 將日內資料彙總為 OHLC 序列。彙總日內資料時,你通常需要同時指定 periodk 參數。

intraday_xts 物件包含隨機產生的一個交易日資料。

本練習屬於課程

在 R 匯入與管理金融資料

檢視課程

練習說明

  • 使用 to.period()intraday_xts 轉換成 5 秒價位序列,命名為 xts_5sec
  • 使用 to.period()intraday_xts 轉換成 10 分鐘價位序列,命名為 xts_10min
  • 使用 to.period()intraday_xts 轉換成 1 小時價位序列,命名為 xts_1hour

動手互動練習

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

# Convert raw prices to 5-second prices
xts_5sec <- to.period(intraday_xts, period = "___", k = ___)

# Convert raw prices to 10-minute prices
xts_10min <-

# Convert raw prices to 1-hour prices
xts_1hour <- to.period(___, period = "___", k = ___)
編輯並執行程式碼