Esempio n. 1
0
    def attach_indicator(self, indicator, col=None):
        """Declares an indicator to be calculated for the given columns

        Any registered indicators are applied to their respective columns
        at each iteration of the algorithm.
        This method can be called before or during algo execution.

        Arguments:
            indicator {str}

        Keyword Arguments:
            cols {list} -- Names of target columns (default: all columns)
        """
        if col is None:
            col = self.columns

        if indicator not in self._indicators:
            try:
                ind_obj = basic.get_indicator(indicator,
                                              symbol=col,
                                              dataset=self.name)
            except LookupError:
                ind_obj = technical.get_indicator(indicator,
                                                  symbol=col,
                                                  dataset=self.name)
            # ind_obj = getattr(basic, indicator.upper())(dataset=self.name)
            self._indicators.append(ind_obj)

        if indicator not in self._indicator_map:
            self._indicator_map[indicator.upper()] = []

        self._indicator_map[ind_obj.name].append(col)
Esempio n. 2
0
 def _load_indicators(self, strat_dict):
     indicators = strat_dict.get("indicators", {})
     for i in indicators:
         if i.get("dataset") in [None, "market"]:
             if not i.get("symbol"):
                 i["symbol"] = self.trading_info["ASSET"]
             ind = technical.get_indicator(**i)
             if ind not in self._market_indicators:
                 self.add_market_indicator(ind)
Esempio n. 3
0
    def add_market_indicator(self, indicator, priority=0, **params):
        """Registers an indicator to be applied to standard OHLCV exchange data"""
        if isinstance(indicator, str):
            indicator = technical.get_indicator(indicator, **params)

        # TODO: allow other assets for indicators
        indicator.symbol = self.trading_info["ASSET"]

        # if "symbol" not in params:
        #     params["symbol"] = self.trading_info["ASSET"]
        #     self.log.debug(f'Setting new indicator symbol as {self.trading_info["ASSET"]}')
        self._market_indicators.insert(priority, indicator)
Esempio n. 4
0
from kryptos.strategy import Strategy
from kryptos.strategy.indicators import technical
from catalyst.api import order_target_percent, order, record

import logbook

log = logbook.Logger("BUY_LOW_SELL_HIGH")
log.level = logbook.INFO

strat = Strategy("BUY_LOW_SELL_HIGH", data_frequency="daily")

rsi = technical.get_indicator("RSI")
rsi.update_param("timeperiod", 14)

strat.add_market_indicator(rsi)


@strat.init
def init(context):
    context.TARGET_POSITIONS = 30
    context.PROFIT_TARGET = 0.1
    context.SLIPPAGE_ALLOWED = 0.02
    context.cost_basis = None
    context.buy_increment = None
    context.i = 0


@strat.handle_data
def handle_data(context, data):
    context.i += 1
Esempio n. 5
0
from kryptos.strategy import Strategy
from kryptos.strategy.indicators import technical

import logbook

log = logbook.Logger('EXAMPLE')
log.level = logbook.INFO

strat = Strategy('Simple Stragey', data_frequency='daily')

bbands = technical.get_indicator('BBANDS')
bbands.update_param('matype', 'EMA')

stoch = technical.get_indicator('STOCH')

strat.add_market_indicator(bbands)
strat.add_market_indicator(stoch)

strat.use_dataset('quandl', columns=['MKTCP'])

strat.use_dataset('google', columns=['bitcoin futures'])
strat.add_data_indicator('google', 'relchange', col='bitcoin futures')

# trading config can be set via json or api
# Note that minute data is not supported for external datasets
# strat.trading_info['CAPITAL_BASE'] = 10000
# strat.trading_info['DATA_FREQ'] = 'minute'
# strat.trading_info['HISTORY_FREQ'] = '1m'
# strat.trading_info['START'] = '2017-12-10'
# strat.trading_info['END'] = '2017-12-11'
Esempio n. 6
0
from kryptos.strategy import Strategy
from kryptos.strategy.indicators import technical
# from kryptos.strategy.signals import utils
# from kryptos.utils import viz
# import matplotlib.pyplot as plt
import logbook

log = logbook.Logger('EXAMPLE')
log.level = logbook.INFO

strat = Strategy('MacdFix')

macdfix_9 = technical.get_indicator('MACDFIX', label='MACDFIX_9')

macdfix_18 = technical.get_indicator('MACDFIX', label='MACDFIX_18')
macdfix_18.update_param('signalperiod', 18)

strat.add_market_indicator(macdfix_9)
strat.add_market_indicator(macdfix_18)


@strat.init
def init(context):
    log.info('Algo is being initialzed, setting up context')
    context.i = 0


@strat.handle_data
def handle_data(context, data):
    log.debug('Processing new trading step')
    context.i += 1