Example #1
0
    def __init__(self, name, label=None, symbol=None, dataset=None, **kw):
        """Abstract class defining required methods utilized by Strategy objects"""

        self.name = name.upper()
        self.label = label or self.name
        self.symbol = symbol
        self.dataset = dataset

        self.params = {}

        func_params = kw.get("params", {})
        self._parse_params(func_params)

        self.data = None
        self.outputs = None
        self.current_date = None
        self.result = None
        self.df_results = pd.DataFrame(columns=['pred'])
        self.df_final = pd.DataFrame()
        self.results_pred = []
        self.results_real = []
        self.idx = -1

        self.log = IndicatorLogger(self)
        logger_group.add_logger(self.log)
        self.log.info("Attached {} indicator".format(self.name))
Example #2
0
    def __init__(self, name, columns=None, config=None):
        """Base class of Data Managers

        Data Managers are responsible for all operations related to
        to external datasets, including fetching and visualizing.

        These objects are utilized by Strategy objects during algorithm execution to access
        and integrate external data into algorithm logic.

        The following three methods are to be called during algo execution
        and utilize Catalyst's context object

        `calculate` - calculates registered indicators every iteration
        `record_data` - records external data and indicators every iteration
        `plot` - plots data and indicators after algo execution

        Arguments:
            name {str} -- name of the dataset

        Keyword Arguments:
            columns {list} -- The target columns to analyzed (default: {None})
        """

        self.name = name
        self.columns = columns or []

        if config is None:
            config = DEFAULT_CONFIG

        self.START = pd.to_datetime(config["START"], utc=True)
        self.END = pd.to_datetime(config["END"], utc=True)

        index = pd.date_range(start=self.START, end=self.END)
        self.df = pd.DataFrame(index=index)

        self._indicators = []
        self._indicator_map = {}

        self.current_date = None
        self.log = DataManagerLogger(self)
        logger_group.add_logger(self.log)
Example #3
0
from kryptos import logger_group, setup_logging

from kryptos.utils import tasks
from kryptos.settings import QUEUE_NAMES, REDIS_HOST, REDIS_PORT, SENTRY_DSN, CONFIG_ENV

from kryptos.worker.worker import StratQueue, StratWorker as Worker


client = Client(SENTRY_DSN, transport=HTTPTransport)

CONN = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)


log = logbook.Logger("MANAGER")
logger_group.add_logger(log)

WORKER_PROCESSES = []


def get_queue(queue_name):
    return StratQueue(queue_name, connection=CONN)


def workers_required(queue_name):
    q = get_queue(queue_name)
    return len(q)


def spawn_worker(q, burst=False):
    log.info(f"Creating {q} worker")
Example #4
0
    def __init__(self, name=None, **kw):
        """Central interface used to build and execute trading strategies

        Strategy objects represent a high level interface for constructing
        malleable trading algroithms defined by provided inputs.

        Strategies are repsonsible:
            - applying trade strategy inputs to the catalyst algorithm context
            - integrating external datasets
            - declaring and calculating indicators
            - making trade decisions based on signals

        Three decorators are provided to perform other logic,
        such as modifying Strategy objects, throghout algo execution.

            @init - before algo starts
            @handle_data - at each algo iteration
            @analyze - after algo has completed

        The underlying logic of algorithm execution (market data, making orders,
        persisting data, and iterating through timeseries data) is handled by catalyst.
        """

        self.id = str(uuid.uuid1())

        # name required for storing live algos
        if name is None:
            name = "Strat-" + self.id

        self.name = name
        self.trading_info = DEFAULT_CONFIG
        self._market_indicators = []
        self._ml_models = []
        self.signals = {}
        self._datasets = {}
        self._extra_init = lambda context: None
        self._extra_handle = lambda context, data: None
        self._extra_analyze = lambda context, results, pos: None
        self._extra_plots = 0
        self.viz = True
        self.quant_results = None
        self.in_job = False

        self.telegram_id = None

        self._signal_buy_funcs = []
        self._signal_sell_funcs = []

        # from JSON obj
        self._buy_signal_objs = []
        self._sell_signal_objs = []

        self._override_indicator_signals = False

        self._buy_func = None
        self._sell_func = None

        self.trading_info.update(kw)

        self._live = False
        self._simulate_orders = True

        self.log = StratLogger(self)
        logger_group.add_logger(self.log)
        setup_logging()

        self.current_date = None
        self.last_date = None
        self.filter_dates = None
        self.date_init_reference = None
        self._context_ref = None
        self._state = StratState()