dysonance / Temporal.jl

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

Provide an example in doc with random values (instead of remote data) #12

Closed femtotrader closed 6 years ago

femtotrader commented 6 years ago

Hello,

A very simple example with random value should probably be given in doc. Maybe something like this (to avoid to rely on remote data, but with a random seed to ensure reproducibility)

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])

Kind regards

dysonance commented 6 years ago

@femtotrader Thanks for the suggestion, much appreciated. I will try to get to this very soon. This actually raises a good point about having better docs about all the different ways to do constructors.

Like for random number generation, the following would work as well.

using Temporal, Base.Dates
n = 100
k = 4
seed = 1234

srand(seed)
X = TS(rand(n, k))

srand(seed)
Y = TS(rand(n, k), today()-Day(n-1):Day(1):today())

srand(seed)
Z = TS(rand(n, k), today()-Day(n-1):Day(1):today(), [:A,:B,:C,:D])

X == Y == Z  # true
femtotrader commented 6 years ago

k is useless. What I prefer in my example using cumsum is that you can easily show plots after (like plotting price of a stock)

About doc, you might try Documenter.jl @iblis17 did an excellent work on https://github.com/JuliaStats/TimeSeries.jl/pull/342

dysonance commented 6 years ago

Good point, will make sure to include cumsum in what gets into the docs

And whoops on k, updated comment to make it non-useless. What is it with me and DRY struggles lately...

But will do both univariate (k=1) and univariate (k>1) examples when I add to docs.

dysonance commented 6 years ago

And I've been meaning to spend the time to learn how to use Documenter and finally just get it done but haven't ever gotten around to it. It's on my todo list but feel free to fork and open a PR if you're getting impatient with my documentation laziness and wanna get the process started a bit.

dysonance commented 6 years ago

Made some changes to the readme to include examples with random values, so going to close this for now. Let me know if more to be done on this and can re-open.