Esempio n. 1
0
def evaluate(expression,
             start=None,
             end=None,
             loader=None,
             logger=None,
             backend=None,
             **kwargs):
    '''Evaluate the timeseries ``expression`` into
an instance of an instance of :class:`dynts.dsl.dslresult` which can be used
to obtain timeseries and/or scatters.
This is probably the most used function of the library.
    
:parameter expression: A timeseries expression string or an instance
                       of :class:`dynts.dsl.Expr` obtained using
                       the :func:`dynts.parse` function.
:parameter start: Start date or ``None``.
:parameter end: End date or ``None``. If not provided today values is used.
:parameter loader: Optional :class:`dynts.data.TimeSerieLoader`
                   class or instance to use.
                   
                   Default ``None``.
                   
:parameter logger: Optional python logging instance, used if you required
                    logging.
                    
                    Default ``None``.
                    
:parameter backend: :class:`dynts.TimeSeries` backend name or ``None``.

The ``expression`` is parsed and the :class:`dynts.dsl.Symbol` are sent to the
:class:`dynts.data.TimeSerieLoader` instance for retrieving
actual timeseries data.
It returns an instance of :class:`dynts.dsl.dslresult`.

Typical usage::

    >>> import dynts
    >>> r = dynts.evaluate('min(GS,window=30)')
    >>> r
    min(GS,window=30)
    >>> ts = r.ts()
    '''
    if isinstance(expression, strtype):
        expression = parse(expression)
    if not expression or expression.malformed():
        raise CouldNotParse(expression)
    symbols = expression.symbols()
    start = start if not start else todate(start)
    end = end if not end else todate(end)
    data = providers.load(symbols,
                          start,
                          end,
                          loader=loader,
                          logger=logger,
                          backend=backend,
                          **kwargs)
    return dslresult(expression, data, backend=backend)
Esempio n. 2
0
def evaluate(expression, start = None, end = None,
             loader = None, logger = None, backend = None,
             **kwargs):
    '''Evaluate the timeseries ``expression`` into
an instance of an instance of :class:`dynts.dsl.dslresult` which can be used
to obtain timeseries and/or scatters.
This is probably the most used function of the library.
    
:parameter expression: A timeseries expression string or an instance
                       of :class:`dynts.dsl.Expr` obtained using
                       the :func:`dynts.parse` function.
:parameter start: Start date or ``None``.
:parameter end: End date or ``None``. If not provided today values is used.
:parameter loader: Optional :class:`dynts.data.TimeSerieLoader`
                   class or instance to use.
                   
                   Default ``None``.
                   
:parameter logger: Optional python logging instance, used if you required
                    logging.
                    
                    Default ``None``.
                    
:parameter backend: :class:`dynts.TimeSeries` backend name or ``None``.

The ``expression`` is parsed and the :class:`dynts.dsl.Symbol` are sent to the
:class:`dynts.data.TimeSerieLoader` instance for retrieving
actual timeseries data.
It returns an instance of :class:`dynts.dsl.dslresult`.

Typical usage::

    >>> import dynts
    >>> r = dynts.evaluate('min(GS,window=30)')
    >>> r
    min(GS,window=30)
    >>> ts = r.ts()
    '''
    if isinstance(expression,strtype):
        expression = parse(expression)
    if not expression or expression.malformed():
        raise CouldNotParse(expression)
    symbols = expression.symbols()
    start = start if not start else todate(start)
    end = end if not end else todate(end)
    data = providers.load(symbols, start, end, loader = loader,
                          logger = logger, backend = backend, **kwargs)
    return dslresult(expression, data, backend = backend)
Esempio n. 3
0
def safetodate(dte):
    from ccy import todate

    try:
        return todate(dte)
    except:
        return None
Esempio n. 4
0
 def test_string(self):
     target = date(2014, 1, 5)
     self.assertEqual(todate('2014 Jan 05'), target)
Esempio n. 5
0
 def test_string(self):
     target = date(2014, 1, 5)
     self.assertEqual(todate('2014 Jan 05'), target)
Esempio n. 6
0
def test_string():
    target = date(2014, 1, 5)
    assert todate('2014 Jan 05') == target
Esempio n. 7
0
def safetodate(dte):
    try:
        return todate(dte)
    except:
        return None
Esempio n. 8
0
def safetodate(dte):
    try:
        return todate(dte)
    except:
        return None
Esempio n. 9
0
def test_string():
    target = date(2014, 1, 5)
    assert todate('2014 Jan 05') == target
Esempio n. 10
0
def safetodate(dte):
    from ccy import todate
    try:
        return todate(dte)
    except:
        return None