Domain Specific Language

Timeseries Expressions

A light-weight domain specific language used to analyse and modify dynts.TimeSeries. Here few script examples:

  • GOOG a dynts.dsl.Symbol which creates one timeseries
  • GOOG,YHOO two timeseries.
  • 2*GOOG a multiplication
  • GOOG-AMZN a subtraction between two symbols.

Parsing timeserie scripts

Parsing timeseries expressions is accomplished using the dynts.parse() function:

dynts.parse(timeseries_expression, method=None, functions=None, debug=False)

Function for parsing timeseries expressions. If succesful, it returns an instance of dynts.dsl.Expr.

For example:

>>> import dynts
>>> r = dynts.parse('GOOG/2,YHOO')
>>> r.type
'concatenationop'
>>> len(r)
2

Now lets load some data using the built-in data providers:

>>> result = dynts.evaluate(r)
>>> result.expression
goog / 2.0 , yhoo
>>> ts = result.unwind()
>>> len(ts)
2

Abstract Syntax Nodes

Expr

class dynts.dsl.Expr

Base class for abstract syntax nodes

count()

Number of nodes

symbols()

Return a list of dynts.dsl.Symbol instances.

unwind(values, backend, **kwargs)

Unwind expression by applying values to the abstract nodes. the kwargs dictionary can contain data which can be used to override values

Symbol

class dynts.dsl.Symbol(value, field=None)

Timeserie symbol. This expression is replaced by a timeserie value for the symbol

A symbol is any string expression which is not a function. For example:

>>> e = dynts.parse('0.5*GOOG')
>>> e[1].type
'symbol'
>>> e.symbols()
[GOOG]

Symbols are special types of the abstract syntax tree which defines the timeserie DSL. values of symbol are given by external data providers such as blooberg, yahoo finance, google finance and so forth.

Brackets

class dynts.dsl.Bracket(value, pl, pr)

A dynts.dsl.Expr class for enclosing group of dynts.dsl.Expr. It forms the building block of dynts.dsl.Function and other operators.

Function

class dynts.dsl.Function(func, expression, pl, pr)

A dynts.dsl.Bracket representing a function func, an instance of dynts.dsl.FunctionBase. A function is defined a-la Python as:

func(expression, **kwargs)

where kwargs is a dictionary of input parameters. For example, the rolling-standard deviation is defined as:

std(expression,window=20)

Functions Registry

To implement new functions, one needs to derive from the base class:

class dynts.dsl.FunctionBase

Base class for a timeseries function implementation. The only member function to implement is the __call__ method.

__call__(args, **kwargs)

where args is a list of arguments (timeseries or other objects) and kwargs is a dictionary of input parameters. For example, the rolling-standard deviation is defined as:

std(expression,window=20)

Table Of Contents

Previous topic

Design Choices

Next topic

Timeserie Backends

This Page