Exemple #1
0
# See the License for the specific language governing permissions and
# limitations under the License.
import math
import uuid

from six import text_type

import zipline.protocol as zp
from zipline.assets import Asset
from zipline.utils.enum import enum
from zipline.utils.input_validation import expect_types

ORDER_STATUS = enum(
    'OPEN',
    'FILLED',
    'CANCELLED',
    'REJECTED',
    'HELD',
)

SELL = 1 << 0
BUY = 1 << 1
STOP = 1 << 2
LIMIT = 1 << 3

ORDER_FIELDS_TO_IGNORE = {'type', 'direction', '_status', 'asset'}


class Order(object):
    # using __slots__ to save on memory usage.  Simulations can create many
    # Order objects and we keep them all in memory, so it's worthwhile trying
Exemple #2
0
    """Warning used to signal that no deltas could be found and none
    were provided.

    Parameters
    ----------
    expr : Expr
        The expression that was searched.
    """
    def __init__(self, expr):
        self._expr = expr

    def __str__(self):
        return 'No deltas could be inferred from expr: %s' % self._expr


no_deltas_rules = enum('warn', 'raise_', 'ignore')


def get_deltas(expr, deltas, no_deltas_rule):
    """Find the correct deltas for the expression.

    Parameters
    ----------
    expr : Expr
        The baseline expression.
    deltas : Expr, 'auto', or None
        The deltas argument. If this is 'auto', then the deltas table will
        be searched for by walking up the expression tree. If this cannot be
        reflected, then an action will be taken based on the
        ``no_deltas_rule``.
    no_deltas_rule : no_deltas_rule
Exemple #3
0
    """Warning used to signal that no deltas could be found and none
    were provided.

    Parameters
    ----------
    expr : Expr
        The expression that was searched.
    """
    def __init__(self, expr):
        self._expr = expr

    def __str__(self):
        return 'No deltas could be inferred from expr: %s' % self._expr


no_deltas_rules = enum('warn', 'raise_', 'ignore')


def get_deltas(expr, deltas, no_deltas_rule):
    """Find the correct deltas for the expression.

    Parameters
    ----------
    expr : Expr
        The baseline expression.
    deltas : Expr, 'auto', or None
        The deltas argument. If this is 'auto', then the deltas table will
        be searched for by walking up the expression tree. If this cannot be
        reflected, then an action will be taken based on the
        ``no_deltas_rule``.
    no_deltas_rule : no_deltas_rule
Exemple #4
0
# See the License for the specific language governing permissions and
# limitations under the License.
import math
import uuid

from six import text_type

import zipline.protocol as zp
from zipline.assets import Asset
from zipline.utils.enum import enum
from zipline.utils.input_validation import expect_types

ORDER_STATUS = enum(
    'OPEN',
    'FILLED',
    'CANCELLED',
    'REJECTED',
    'HELD',
)

SELL = 1 << 0
BUY = 1 << 1
STOP = 1 << 2
LIMIT = 1 << 3

ORDER_FIELDS_TO_IGNORE = {'type', 'direction', '_status', 'asset'}


class Order(object):
    # using __slots__ to save on memory usage.  Simulations can create many
    # Order objects and we keep them all in memory, so it's worthwhile trying
Exemple #5
0
        return CustomBusinessDay(
            holidays=[],
            calendar=None,
            weekmask='Sun Mon Tue Wed Thu Fri Sat'
        )

#aoe =AlwaysOpenExchange()
#print('is open',aoe.is_open_on_minute(pd.Timestamp('2013-01-07 15:03:00+0000', tz='UTC')))
register_calendar("AlwaysOpen",AlwaysOpenExchange())

# order validity enum
# similar to ORDER_STATUS: https://github.com/quantopian/zipline/blob/3350227f44dcf36b6fe3c509dcc35fe512965183/zipline/finance/order.py#L24
from zipline.utils.enum import enum
ORDER_VALIDITY = enum(
  'GTC',
  'GTD',
  'DAY'
)

# my own blotter/order class to allow for order validity
from zipline.finance.order import Order
class MyOrder(Order):
  def __init__(self, validity, *args, **kwargs):
    super(MyOrder,self).__init__(*args, **kwargs)
    self.validity = validity

class MyBlotter(Blotter):
  # Copied from original, with the difference of MyOrder instead of Order
  # https://github.com/quantopian/zipline/blob/3350227f44dcf36b6fe3c509dcc35fe512965183/zipline/finance/blotter.py#L77
  def order(self, sid, amount, style, order_id=None, validity=None):
    if amount == 0:
Exemple #6
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import math
import uuid

import zipline.protocol as zp
from zipline.assets import Asset
from zipline.utils.enum import enum
from zipline.utils.input_validation import expect_types

ORDER_STATUS = enum(
    "OPEN",
    "FILLED",
    "CANCELLED",
    "REJECTED",
    "HELD",
)

SELL = 1 << 0
BUY = 1 << 1
STOP = 1 << 2
LIMIT = 1 << 3

ORDER_FIELDS_TO_IGNORE = {"type", "direction", "_status", "asset"}


class Order(object):
    # using __slots__ to save on memory usage.  Simulations can create many
    # Order objects and we keep them all in memory, so it's worthwhile trying
Exemple #7
0
from six import with_metaclass, iteritems
from collections import namedtuple
from toolz import groupby

from zipline.utils.enum import enum
from zipline.utils.numpy_utils import vectorized_is_element
from zipline.assets import Asset


Restriction = namedtuple(
    'Restriction', ['asset', 'effective_date', 'state']
)


RESTRICTION_STATES = enum(
    'ALLOWED',
    'FROZEN',
)


class Restrictions(with_metaclass(abc.ABCMeta)):
    """
    Abstract restricted list interface, representing a set of assets that an
    algorithm is restricted from trading.
    """

    @abc.abstractmethod
    def is_restricted(self, assets, dt):
        """
        Is the asset restricted (RestrictionStates.FROZEN) on the given dt?

        Parameters
Exemple #8
0
import abc
from numpy import vectorize
from functools import partial, reduce
import operator
import pandas as pd
from collections import namedtuple
from toolz import groupby

from zipline.utils.enum import enum
from zipline.utils.numpy_utils import vectorized_is_element
from zipline.assets import Asset

Restriction = namedtuple("Restriction", ["asset", "effective_date", "state"])

RESTRICTION_STATES = enum(
    "ALLOWED",
    "FROZEN",
)


class Restrictions(metaclass=abc.ABCMeta):
    """
    Abstract restricted list interface, representing a set of assets that an
    algorithm is restricted from trading.
    """
    @abc.abstractmethod
    def is_restricted(self, assets, dt):
        """
        Is the asset restricted (RestrictionStates.FROZEN) on the given dt?

        Parameters
        ----------
from six import with_metaclass, iteritems
from collections import namedtuple
from toolz import groupby

from zipline.utils.enum import enum
from zipline.utils.numpy_utils import vectorized_is_element
from zipline.assets import Asset


Restriction = namedtuple(
    'Restriction', ['asset', 'effective_date', 'state']
)


RESTRICTION_STATES = enum(
    'ALLOWED',
    'FROZEN',
)


class Restrictions(with_metaclass(abc.ABCMeta)):
    """
    Abstract restricted list interface, representing a set of assets that an
    algorithm is restricted from trading.
    """

    @abc.abstractmethod
    def is_restricted(self, assets, dt):
        """
        Is the asset restricted (RestrictionStates.FROZEN) on the given dt?

        Parameters