dysonance / Temporal.jl

Time series implementation for the Julia language focused on efficiency and flexibility
Other
101 stars 27 forks source link

Streaming feature #1

Open femtotrader opened 7 years ago

femtotrader commented 7 years ago

Hello,

I wonder if Temporal.jl have streaming feature ie a kind of circular buffer datastructure which is able to receive for example tick events and store them or to resample to candlestick (OHLCV).

Kind regards

PS: see StreamTimeArray https://github.com/femtotrader/TimeSeriesIO.jl/blob/master/src/stream_timearray.jl StreamTimeArrayOHLCV https://github.com/femtotrader/TimeSeriesIO.jl/blob/master/src/stream_timearray_ohlcv.jl

dysonance commented 7 years ago

@femtotrader This is something that I would definitely like to add on later. Something I am always considering is the amount of dependencies required to use my packages. As the package becomes more fully developed and feature-rich, additional dependencies will surely follow, but for now I'm trying to keep the pre-requisites in moderation. For now my primary goal is to be able to analyze and manipulate time series data as efficiently as possible, so that my planned efforts to develop a systematic trading & backtesting platform will go smoothly. Getting live streaming quotes strikes me as something that would come after much of the historical analytical side of things has been fully implemented.

femtotrader commented 7 years ago

You might be interested by https://github.com/femtotrader/TALib.jl see https://github.com/femtotrader/TALib.jl/issues/19

femtotrader commented 7 years ago

Some inspiration from Python ecosystem with streamz https://github.com/JuliaQuant/MarketTechnicals.jl/issues/93#issuecomment-341361834

femtotrader commented 6 years ago

A streaming example (probably not very efficient)

using Temporal
import Base: circshift!, push!

function circshift!(ts::TS, n)
    ts.values = circshift(ts.values, n)
    ts.index = circshift(ts.index, n)
    ts
end

function push!(ts::TS, values::Array, idx::Vector)
    n = length(idx)
    circshift!(ts, -n)
    ts.values[end-n+1:end,:] = values
    ts.index[end-n+1:end] = idx
    ts
end

srand(1234)
idx=DateTime(2010,1,1):Dates.Hour(1):DateTime(2017,1,1)-Dates.Hour(1)
n=length(idx)
price=100+cumsum(2*(rand(n)-0.5))
volume=rand(n)*1000
ts = TS([price volume], collect(idx), [:price, :volume])
println(ts)

#ts = circshift(ts, -1)
#println(ts)

new_values = [204.0 100.0]
new_idx = [DateTime(2017,1,1,0,0,0)]

push!(ts, new_values, new_idx)

new_values = [205.0 100.1 ; 206.0 100.2]
new_idx = [DateTime(2017,1,1,1,0,0),DateTime(2017,1,1,2,0,0)]
push!(ts, new_values, new_idx)

println(ts)