def update_ts(self, ts, context):
        self.catalyst_exchanges = [
            context.exchanges[self.global_exchanges[i]]
            for i in range(self.global_leg_num)
        ]
        self.catalyst_assets = [
            symbol(self.global_symbols[i], self.global_exchanges[i])
            for i in range(self.global_leg_num)
        ]
        if not ts:
            return False
        if not self.ts or self.ts.date() != ts.date():
            self.ts = ts
            eod = self.ts.date()
            file_prefix = self._generate_file_prefix(eod)
            self.storage_log_file = '{}.comics.log'.format(file_prefix)
            self.storage_trade_file = '{}.trade.csv'.format(file_prefix)
            self.storage_snapshot_file = '{}.snapshot.csv'.format(file_prefix)
            self.storage_plot_file = '{}.png'.format(file_prefix)

            logging.basicConfig(
                                filename = os.path.join(self.storage_log_folder, self.storage_log_file),\
                                format   = '%(asctime)s - %(levelname)s - %(message)s',
                                level    = self._get_log_level(self.storage_log_level)
                               )
            logging.info('[multileg_config] updated eod to {}'.format(eod))
            if self.global_mode != 'live':
                set_commission(maker=self.sim_maker_fee_pct,
                               taker=self.sim_taker_fee_pct)
                set_slippage(slippage=self.sim_slippage_pct)
            return True
        return False
Esempio n. 2
0
def initialize(context):
    context.i = 0
    context.asset = symbol('btc_usdt')
    context.base_price = None
    context.trade_price = None
    context.adx_prev = 0
    context.adx_sell = True
    context.last_price = 0
    context.counter = 0
    context.timer = 0
    context.trade_timer = 100

    set_commission(maker=0, taker=0)
Esempio n. 3
0
def initialize(context):
    context.mailema = 0
    context.univers = [
        'btc_usd', 'eos_usd', 'eth_usd', 'etc_usd', 'ltc_usd', 'zec_usd',
        'omg_usd', 'rrt_usd'
    ]
    context.objects = []
    context.basePrice = {}
    context.day = 0
    for obj in context.univers:
        context.objects.append(objectT(obj, 0))
        context.basePrice[obj] = None
    context.objects = dict(zip(context.univers, context.objects))
    set_slippage(0.020)
    set_commission(0.002, 0.002)
Esempio n. 4
0
def initialize(context):
    context.mailema = 0
    context.univers = ['btc_usd',
                    'eos_usd',
                    'eth_usd',
                    'etc_usd',
                    'ltc_usd',
                    'zec_usd',
                    'omg_usd',
                    'rrt_usd'
    ]
    context.objects = []
    context.basePrice = {}
    context.day =0 
    context.dayday = 0
    context.Vreturn = []
    context.base = []
    for obj in context.univers:
        context.objects.append(objectT(obj,0))
        context.basePrice[obj] = None
    context.objects = dict(zip(context.univers,context.objects))
    schedule_function(everyDay,half_days=False)
    set_slippage(0.015)
    set_commission(0.002,0.002)
Esempio n. 5
0
def load_outright_config(context, comics_config):
    context.global_namespace = comics_config['global_namespace']
    context.global_instance = str(comics_config['global_instance'])
    context.global_mode = comics_config['global_mode']
    context.global_bootstrap = comics_config['global_bootstrap']

    if context.global_mode != 'live':
        set_commission(maker = comics_config['sim_maker_fee_pct'], \
              taker = comics_config['sim_taker_fee_pct'])
        set_slippage(slippage=comics_config['sim_slippage_pct'])

    context.exchange_str = comics_config['exchange']
    context.symbol_str = comics_config['symbol']
    context.asset = symbol(comics_config['symbol'])
    context.exchange = context.exchanges[comics_config['exchange']]
    context.base_currency = comics_config['symbol'].split('_')[0]
    context.quote_currency = comics_config['symbol'].split('_')[1]

    context.risk_max_notional = comics_config['risk_max_notional']
    context.risk_max_position = comics_config['risk_max_pos']
    context.risk_max_long_pos = comics_config['risk_max_long_pos']
    context.risk_max_short_pos = comics_config['risk_max_short_pos']
    context.risk_quote_currency = comics_config['risk_quote_currency']
    context.risk_init_position = comics_config.get('risk_init_position')
    context.risk_init_cost_basis = comics_config.get('risk_init_cost_basis')

    context.signal_window = comics_config['signal_window']
    context.signal_update_rate = comics_config['signal_update_rate']
    context.signal_minsd = comics_config['signal_minsd']
    context.signal_ref_price = comics_config['signal_ref_price']
    context.signal_candle_size = comics_config['signal_candle_size']
    context.signal_hist_rate_limit = comics_config['signal_hist_rate_limit']
    context.signal_wait_for_full_hist = comics_config[
        'signal_wait_for_full_hist']

    context.invent_pm = comics_config['invent_pm']  # profit margin
    context.invent_e0 = comics_config['invent_e0']
    context.invent_en = comics_config['invent_en']
    context.invent_spn = comics_config['invent_spn']
    context.invent_min_share = comics_config['invent_min_share']
    context.invent_ticksize = comics_config['invent_ticksize']

    # rounded risk positions by invent_spn, otherwise algo will continuously see working positions:
    context.risk_max_position = _round_position(context.risk_max_position,
                                                context.invent_spn)
    context.risk_max_long_pos = _round_position(context.risk_max_long_pos,
                                                context.invent_spn)
    context.risk_max_short_pos = _round_position(context.risk_max_short_pos,
                                                 context.invent_spn)
    context.risk_init_position = context.risk_init_position

    context.invent_n = int(
        (context.risk_max_long_pos - context.risk_max_short_pos) /
        context.invent_spn / 2)
    context.invent_ignore_partial_fill_value = comics_config[
        'invent_ignore_partial_fill_value']
    assert context.invent_spn >= context.invent_min_share, 'invent_spn < invent_min_share!'

    context.exit_nonew_dt = comics_config.get('exit_nonew_dt')
    context.exit_passive_dt = comics_config.get('exit_passive_dt')
    context.exit_active_dt = comics_config.get('exit_active_dt')
    # context.exit_signal_shift = comics_config.get('exit_signal_shift')
    # context.exit_shift_interval = comics_config.get('exit_shift_interval')

    context.file_prefix = _get_file_prefix(comics_config)
    context.record_path = comics_config['record_path']
    context.record_pickle = '{}.pickle'.format(context.file_prefix)
    context.record_pickle = _join_path(context.record_path,
                                       context.record_pickle)
    context.record_rate = comics_config['record_rate']
    context.trade_path = comics_config.get('trade_path')
    context.snapshot_path = comics_config.get('snapshot_path')
    context.perf_stat_path = comics_config.get('perf_stat_path')

    context.catalyst_logger = catalyst_logger(context.global_namespace)
    context.log_file = '{}.comics.log'.format(context.file_prefix)
    context.log_file = _join_path(comics_config['log_path'], context.log_file)
    context.display_refresh_rate = comics_config['display_refresh_rate']
    context.display_plot = comics_config['display_plot']
    context.display_sim = comics_config['display_sim']
    context.plot_fig = comics_config['plot_fig']
    context.plot_path = comics_config['plot_path']
    context.plot_file = '{}.png'.format(context.file_prefix)
    context.plot_file = _join_path(comics_config['plot_path'],
                                   context.plot_file)
    context.pnl_stat_file = _join_path(
        context.perf_stat_path,
        'pnl.stat.csv') if context.global_mode != 'backtest' else None

    logging.basicConfig(
         filename = context.log_file,\
         format = '%(asctime)s - %(levelname)s - %(message)s',
         level = _get_log_level(comics_config['log_level'])
         )
    logging.info('#######################################################')
    logging.info('initializing outrigt_trader & loading configurations...')
    for k, v in comics_config.items():
        logging.info('{}: {}'.format(k, v))
    logging.info('initialization finished')
    logging.info('#######################################################')