Tick Time Series dedicated functions

backward

Shift all values to previous time. Last time and first value are lost.

(backward ts)

parameter

clockref

Define the timeserie as a clock reference, or metronome. For any operation between several timeseries there will be one update for output if there is one update for the clockref serie. This synchronization mode ensure that length of output timeserie is <= to clockref timeserie. Adding a ref-value ensure length of output timeserie is = to clockref timeserie, uncomputed values due to missing data from other series will be replaced by ref-value.

(clockref ts [ref-value])

parameter

delta

Returns timeserie where each point is the current value minus previous value of the input timeserie. So result length is input length-1, and first output point time is time of second input point time.

(delta ts)

parameter

forward

Shift all values to next time. First time and last value are lost.

(forward ts)

parameter

graphsample

Subsample timeserie in order to minimize number of points but to keep same result on screen. This is useful to get a smaller timeserie that will be drawn like the full timeserie if your output screen is nbr pixel width. As graphsample process on a stream it can’t know the future so sends lots of points at the beginning then less and less.

(graphsample nbr ts)

parameters

example

(graphsample 1920 (keep (timeserie @bid-price "trth" "ESH6" 2016-01-11) not= 0))

history

Return all available dates for a given source and code.

As history can be huge depending on source better call through a LispTick client with streaming (Walk method).

(history source code)

parameter

keep

Only keep points in timeserie that fulfill the given condition

(keep ts func args2 args3 ...)

parameters

examples

Change timeserie ts to keep only positif values

(keep ts > 0)

Limit perimeter to code ending with “.PA”

(defn is-paris[code]
  (cond
    (has-suffix code ".PA") true
    false
  )
)

(keep (perimeter "trth" 2016-02-01) is-paris)

label

Give a name to the timeserie that can be used in a graph for example.

(label name ts)

parameters

localize

Set time location, useful to ensure time precision when created manually.

(localize time location)

parameters

examples

Tests ensuring daylight saving is well handled

(assert (= (localize 2017-12-18T14:12 "Europe/Paris")(localize 2017-12-18T08:12 "US/Eastern")))
(assert (= (localize 2017-11-01T14:12 "Europe/Paris")(localize 2017-11-01T09:12 "US/Eastern")))

max

Max returns maximum of several values. If an argument is a timeserie latest value is used for comparaison. If the only argument is a timeserie result is the point with maximum value.

(max a [b] ...)

parameters

example

(max
  (timeserie @bid-price "bitstamp" "BTC" 2018-02-14)
  (forward (timeserie @bid-price "bitstamp" "BTC" 2018-02-14))
)
(max
  (timeserie @trade-price "bitstamp" "BTC" 2018-02-01 2018-02-28)
)

merge

Merge several timeseries into one, synchronize points from all timeseries.

(merge ts1 ts2 ...)

parameters

min

Min returns minimum of several values. If an argument is a timeserie latest value is used for comparaison. If the only argument is a timeserie result is the point with minimum value.

(min a [b] ...)

parameters

See max for some examples

now

Retrieve current time

(now)

example

(timeserie @trade-price "bitstamp" "BTC" (now))

one

Replace value of every update by 1.0 .

(one ts)

parameter

parallel-sample

Apply undrelying function for all given arguments combination using all available ressources.

(parallel-sample func samplemode args1 args2 ...)

parameter

example

(defn nbr-trade[d code]
  (subsample 1D count
    (timeserie @trade-price "bitstamp" code d)
  )
)
(vget
  (parallel-sample nbr-trade sum (range 2018-02-01 2018-02-28 1D) ["BTC" "ETH" "XRP"])
  0
)

parallel-sample-grid

As parallel-sample but result is a grid with used arguments for kept result instead of a simple timeserie

(parallel-sample-grid func samplemode args1 args2 ...)

parameter

perimeter

Return all available codes for a given source and date.

As perimeter can be huge depending on source better call through a LispTick client with streaming (Walk method).

(perimeter source date)

parameter

prune

Filter points in timeserie where value doesn’t change.

(prune ts)

parameter

range

Create an interator on an range of values. Should be used as an argument to parallel-sample.

(range start stop step)

parameter

example

Every day from 19 January 2018 until 1st May 2018, included

(range 2018-01-19 2018-05-01 1D)

restrict

Only keep timeserie points in [start, stop[. If no timezone is given with start or stop it will be “local” to timeserie timezone.

(restrict ts start stop)

parameters

sigma

Returns a timeserie where each point is the summation of all previous points in the input timeserie.

(sigma ts)

parameter

example

(sigma (timeserie @trade-volume "bitstamp" "BTC" 2018-02-28))

sign

Replace value of every update by its sign: * value < 0 &rarr; -1 * value == 0 &rarr; 0 * value > 0 &rarr; 1

(sign ts)

parameter

sliding

Replace each update by the specified value from the sliding window. Typical usage is a moving average.

(sliding period|int samplemode ts)

parameters

examples

Average weighted by number of updates, like Bollinger Band base. Here the average is done on 1000 updates or on a 2h window. Using a period instead of a number of updates allows to extend Bollinger bands to high frequency data.

Use graphsample to get same graph but with less data transmission.

(defn bollinger[d ts]
  (/
    (sliding d sum ts)
    (sliding d count ts)
  )
)
[
(graphsample 1920 (timeserie @trade-price "bitstamp" "BTC" 2018-02-23))
(graphsample 1920 (bollinger 1000 (timeserie @trade-price "bitstamp" "BTC" 2018-02-23)))
(graphsample 1920 (bollinger 2h (timeserie @trade-price "bitstamp" "BTC" 2018-02-23)))
]

subsample

Keep only one point per period from input timeserie, samplemode defines which point to keep. Each value is taken in the range [i * period, (i+1) * period[, each time value is the time of original point.

(subsample period samplemode ts)

parameters

examples

Request 5 minutes timebar for a stock.

[
  [
    (subsample 5m open (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
    (subsample 5m high (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
    (subsample 5m low (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
    (subsample 5m close (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
  ]
]
(subsample 5m sum (timeserie @trade-volume "trth" "BNPP.PA" 2016-02-01 filter-volume))
(subsample 1h count (timeserie @bid-price "trth" "ESH6" 2016-01-11))

tget

Get time at a precise index in a timeserie. If index is a time return same time if an update exists or return time of update just before.

(tget ts i|time )

parameters

example

(def ts (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
(- (tget ts -1) (tget ts 0))

time-as-array

Return times of timeserie as an array of datetime.

(time-as-array ts)

parameter

time-as-value

Return times of timeserie as a timeserie of Epoch times, number of seconds since 1 January 1970.

(time-as-value ts)

parameter

timeserie

Create timeserie by hand or retrieve data from a source

(timeserie @origin "source" "code" date [stop] [filter] )
(timeserie date value date value ...)

parameters

examples

(timeserie @bid-price "bitstamp" "BTC" 2018-02-14)
(timeserie 2017-10-26T09:19 48.6 2017-10-26T10:30 49 2017-10-26T11:51 49.27)

value-as-array

Return values of timeserie as an array of floats.

(value-as-array ts)

parameter

version

Return LispTick version as a string.

(version)

example

vget

Get value at a precise index in a timeserie. If index is a time return value at time if an update exists or just before.

(vget ts i|time)

parameters

example

(def ts (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
(/ ts (vget ts 0))