用于R的Lightstreamer客户端 - 将数据转换为OHLC格式

时间:2017-06-04 20:43:56

标签: r transformation xts http-live-streaming lightstreamer

我正在为R构建一个Lightstreamer客户端。我设法将流数据(tick数据)直接输入R控制台。为了显示下载流在R中的外观,下面是一个重建。我现在需要将流数据转换为包含OHLC数据(开放,高,低,关闭)的xts对象。我正在使用接收器将流移动到文件。在数据流中,OHLC数据表示为:[U,3,1,20:00:33 | 3.04 | 0.0 | 2.41 | 3.67 | 3.03 | 3.04 |#|#| $],其中内容为[时间戳,价格,变化,最小,最大,出价,要求,开放,关闭,状态]。

问题:是否有结构化的方法/方法(在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 () 

0 个答案:

没有答案