LispTick Wiki

Tick Time Series dedicated functions

backward

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

(backward timeserie)

parameter

  • timeserie: input timeserie

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.

(clockref timeserie)

parameter

  • timeserie: timeserie than will become the reference for time

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

parameter

  • timeserie: input timeserie

forward

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

(forward timeserie)

parameter

  • timeserie: input timeserie

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

parameters

  • nbr: should be the number of pixels of the graph you will create with timeserie.
  • timeserie: input timeserie

example

  • graph show all S&P E-Mini future bid prices not null on a Full HD screen (more than 2 million points)
(graphsample 1920 (keep (timeserie @bid-price "trth" "ESH6" 2016-01-11) not= 0))

keep

Only keep points in timeserie that fulfill the given condition

(keep timeserie condition value)

parameters

  • timeserie: input timeserie
  • condition: can be <, >, <=, >=, =, not=,
  • value: number compared to each timeserie point value

localize

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

(localize time location)

parameters

  • time: input time
  • location: timezone, can be any tz data name like "US/Eastern" see TZ Wiki

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

merge

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

(merge timeserie1 timeserie2 ...)

parameters

  • timeserie1: first input timeserie
  • timeserie2: second input timeserie
  • ...: as many timeseries as you want

now

Retrieve current time

(now)

example

  • graph trade prices since 00h00 UTC until now for Bitcoin from Bitstamp
(timeserie @trade-price "bitstamp" "BTC" (now))

one

Replace value of every update by 1.0 .

(one timeserie)

parameter

  • timeserie: input timeserie

prune

Filter points in timeserie where value doesn't change.

(prune timeserie)

parameter

  • timeserie: input timeserie

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 timeserie start stop)

parameters

  • timeserie: input timeserie
  • start: a time with or without date
  • stop: a time with or without date

sigma

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

(sigma timeserie)

parameter

  • timeserie: input timeserie

example

  • graphCompute full volume traded during the day at any time.
(sigma (timeserie @trade-volume "rnd" "STRIGI.PA" 2017-10-18))

sign

Replace value of every update by its sign:

  • value < 0 → -1
  • value == 0 → 0
  • value > 0 → 1
(sign timeserie)

parameter

  • timeserie: input timeserie

sliding

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

(sliding period|int samplemode timeserie)

parameters

  • period|int: a duration or an int, defines the window size in time or in number of updates
  • samplemode: how to choose point to keep, can be open, high, low, close, sum, count
  • timeserie: input timeserie

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.

  • graph Average
(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 timeserie)

parameters

  • period: a duration, defines the period size
  • samplemode: how to choose point to keep, can be open, high, low, close, sum, count
  • timeserie: input timeserie

examples

Request 5 minutes timebar for a stock.

  • graph Open
(subsample 5m open (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
  • graph High
(subsample 5m high (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
  • graph Low
(subsample 5m low (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
  • graph Close
(subsample 5m close (timeserie @trade-price "trth" "BNPP.PA" 2016-02-01))
  • graph Volume
(subsample 5m sum (timeserie @trade-volume "trth" "BNPP.PA" 2016-02-01 filter-volume))
  • graph Number of 1st limit bid update per hour for S&P E-Mini future
(subsample 1h count (timeserie @bid-price "trth" "ESH6" 2016-01-11))

tget

Get time at a precise index in a timeserie

(tget timeserie i)

parameters

  • timeserie: input timeserie
  • i: index of the data to retrieve, 0 is first -1 is last

example

  • graph Use the first and last timeserie times to compute the day quotation duration
(def ts (timeserie @trade-price "rnd" "STRIGI.PA" 2017-10-18))
(- (tget ts -1) (tget ts 0))

time-as-value

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

(time-as-value timeserie)

parameter

  • timeserie: input timeserie

timeserie

Create timeserie by hand or retrieve data from a source

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

parameters

  • origin: which tick data you want to look at, can be, depending on source:
    • @trade-price
    • @trade-volume
    • @bid-price
    • @bid-volume
    • @ask-price
    • @ask-volume
    • @[ask|bid]-[price|volume]-n retrieve nth limit (i.e. ask-price-1 should be equal to ask-price depending on source)
  • source: data provider source name
  • code: a code related to source (e.g. a RIC like "BNPP.PA")
  • date: a LispTick Date without time
  • stop: optional LispTick Date, several days timeserie from [date to stop]
  • filter: optional string argument, used by source to filter output

examples

  • graph bid prices for fictitous "rnd" "STRIGI.PA" random source
(timeserie @bid-price "rnd" "STRIGI.PA" 2017-10-18)
  • graph Hard coded time serie
(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 timeserie)

parameter

  • timeserie: input timeserie

vget

Get value at a precise index in a timeserie

(vget timeserie i)

parameters

  • timeserie: input timeserie
  • i: index of the data to retrieve, 0 is first -1 is last

example

  • graph Use first timeserie value to compute the serie return
(def ts (timeserie @trade-price "rnd" "STRIGI.PA" 2017-10-18))
(/ ts (vget ts 0))