1

我正在为 R 构建一个 Lightstreamer 客户端。我设法将流数据(滴答数据)直接导入 R 控制台。为了显示下载流在 R 中的样子,您可以在下面找到重建。我现在需要将流数据转换为包含 OHLC 数据(打开、高、低、关闭)的 xts 对象。我正在使用接收器将流移动到文件。在数据流中,OHLC 数据显示为:[U,3,1,20:00:33|3.04|0.0|2.41|3.67|3.03|3.04|#|#|$],其中内容为 [timestamp ,价格,变化,最小值,最大值,出价,要价,开盘,收盘,状态]。

问题:是否有结构化的方式/方法(在 R 环境中)将流数据转换为 OHLC 数据?

counter <- 1 # Start position of counter 
sink (file = '/lightstreamer_v3/a10.txt', append = TRUE, split = TRUE) # store data to file. Adjust to your path.

# Code to reproduce the Lightstreamer tick-data visible in R console:
repeat {
      counter <- counter + 1  # Handle internal loop
     cat ("<<  Preamble: preparing push", "\n")  # Printouts to R console.
     cat ("<<  Preamble: preparing push","\n")
     cat ("<<  Preamble: preparing push","\n")  
     cat ("<<  Preamble: preparing push","\n")
     cat ("<<","\n")
     cat ("<<","\n")
     cat ("<<","\n")
     cat ("<<  U,3,1,20:00:33|3.04|0.0|2.41|3.67|3.03|3.04|#|#|$","\n") # tick-data
     cat ("<<","\n")
     cat ("<< 7","\n")
     cat (" PROBE","\n")
    if (counter >= 10000) {  # Counter break.
    break 
 } 
 }

 sink () 
4

0 回答 0