def handle(self, *args, **options):
        try:
            #print options
            self.sdate = options.get('sdate', '')
            self.edate = options.get('edate', '') or self.sdate
            self.platforms = [
                s for s in options.get('platforms', '').split(',') if s
            ]
            self.statistics = [
                int(s) for s in options.get('statistics', '').split(',') if s
            ]
            is_create_time = False  #options.get('is_create_time',False)
            is_get_json_file = options.get('get_json_file', '')

            if options.get('cron'):
                self.cron_run()
                return
            PlatFormStatisticManager.create_center_platform_statistic_table()

            if self.sdate:
                sdate = convert_to_datetime(self.sdate)
                edate = convert_to_datetime(self.edate)
                pm = PlatFormStatisticManager(sdate, edate, self.statistics,
                                              self.platforms)
                if is_get_json_file:
                    pm.update_channel_server_data()
                else:
                    pm.start()
        except:
            traceback.print_exc()
예제 #2
0
    def __init__(self,
                 strategy_label,
                 enter_signal,
                 exit_signal,
                 risk_cap,
                 starting_cash,
                 chart_functions,
                 chart_functions_new,
                 symbol_blacklist,
                 trading_symbols,
                 trading_start,
                 trading_end,
                 trading_type,
                 trading_commission,
                 always_plot):

        self.strategy_label     = strategy_label
        p = re.compile('(\s\s*)')
        self.enter_signal       = p.sub(' ', enter_signal)
        self.exit_signal        = p.sub(' ', exit_signal)
        self.risk_cap           = p.sub(' ', risk_cap)
        self.starting_cash      = starting_cash
        self.chart_functions    = chart_functions
        self.chart_functions_new = chart_functions_new

        self.trading_start  = util.convert_to_datetime(trading_start)
        self.trading_end    = util.convert_to_datetime(trading_end)
        symbol_start = self.trading_start - datetime.timedelta(100)

        self.trading_symbols    = sl.SymbolList(trading_symbols,
                                                symbol_blacklist,
                                                symbol_start,
                                                self.trading_end)
        self.trading_symbols_label = trading_symbols
        #self.trading_start  = datetime.strptime(trading_start, "%Y%M%d")
        #self.trading_end    = datetime.strptime(trading_end, "%Y%M%d")
        self.trading_type       = trading_type
        self.trading_commission = trading_commission
        self.always_plot        = always_plot

        self.daterange = util.date_range(self.trading_start, self.trading_end)
        print self.daterange

        # Portfolio to manage the trading transactions of the strategy
        self.portfolio = portfolio.Portfolio(self.starting_cash,
                                             self.trading_start,
                                             self.trading_commission)

        # time series used to store when we are in or out of the market
        self.in_n_out = None

        self.trading_days = None

        # dictionary with time series of computed indicators
        # time series to store the performance of the current trading strategy
        self.performance_index = {}
        self.stock_chart = {}
        self.indicators = {}
예제 #3
0
파일: __init__.py 프로젝트: fcua/x8623
    def __init__(self, **values):
        self.start_date = values.pop('start_date', None)
        if self.start_date:
            self.start_date = convert_to_datetime(self.start_date)

        # Check field names and yank out all None valued fields
        for key, value in list(iteritems(values)):
            if key not in self.FIELD_NAMES:
                raise TypeError('Invalid field name: %s' % key)
            if value is None:
                del values[key]

        self.fields = []
        assign_defaults = False
        for field_name in self.FIELD_NAMES:
            if field_name in values:
                exprs = values.pop(field_name)
                is_default = False
                assign_defaults = not values
            elif assign_defaults:
                exprs = DEFAULT_VALUES[field_name]
                is_default = True
            else:
                exprs = '*'
                is_default = True

            field_class = self.FIELDS_MAP[field_name]
            field = field_class(field_name, exprs, is_default)
            self.fields.append(field)
예제 #4
0
    def __init__(self, strategy_label, enter_signal, exit_signal, risk_cap,
                 starting_cash, chart_functions, chart_functions_new,
                 symbol_blacklist, trading_symbols, trading_start, trading_end,
                 trading_type, trading_commission, always_plot):

        self.strategy_label = strategy_label
        p = re.compile('(\s\s*)')
        self.enter_signal = p.sub(' ', enter_signal)
        self.exit_signal = p.sub(' ', exit_signal)
        self.risk_cap = p.sub(' ', risk_cap)
        self.starting_cash = starting_cash
        self.chart_functions = chart_functions
        self.chart_functions_new = chart_functions_new

        self.trading_start = util.convert_to_datetime(trading_start)
        self.trading_end = util.convert_to_datetime(trading_end)
        symbol_start = self.trading_start - datetime.timedelta(100)

        self.trading_symbols = sl.SymbolList(trading_symbols, symbol_blacklist,
                                             symbol_start, self.trading_end)
        self.trading_symbols_label = trading_symbols
        #self.trading_start  = datetime.strptime(trading_start, "%Y%M%d")
        #self.trading_end    = datetime.strptime(trading_end, "%Y%M%d")
        self.trading_type = trading_type
        self.trading_commission = trading_commission
        self.always_plot = always_plot

        self.daterange = util.date_range(self.trading_start, self.trading_end)
        print self.daterange

        # Portfolio to manage the trading transactions of the strategy
        self.portfolio = portfolio.Portfolio(self.starting_cash,
                                             self.trading_start,
                                             self.trading_commission)

        # time series used to store when we are in or out of the market
        self.in_n_out = None

        self.trading_days = None

        # dictionary with time series of computed indicators
        # time series to store the performance of the current trading strategy
        self.performance_index = {}
        self.stock_chart = {}
        self.indicators = {}
예제 #5
0
    def handle(self, *args, **options):
        keep_connections()
        try:
            print options
            self.sdate = options.get('sdate', '')
            self.edate = options.get('edate', '') or self.sdate
            self.server_ids = [
                s for s in options.get('server_ids', '').split(',') if s
            ]
            self.statistic_ids = [
                s for s in options.get('statistic_ids', '').split(',') if s
            ]

            if options.get('print', ''):
                print '-' * 3, '统计列表', '-' * 3
                for s in Statistic.objects.all().order_by('log_type'):
                    print '%2s :%s' % (s.id, s.name)
                print
                return

            if options.get('cron'):
                self.cron_run()
                return

            if self.sdate:

                sdate = convert_to_datetime(self.sdate)
                edate = convert_to_datetime(self.edate)

                date_list = self.get_date_list_from_month(sdate, edate)
                for i, (s, e) in enumerate(date_list):
                    print '[%s] 第  %s 次执行 统计 时间  %s -%s ' % (
                        datetime.datetime.now(), i + 1, s, e)
                    sm = StatisticManager(s, e, self.statistic_ids,
                                          self.server_ids)
                    sm.start_update()
                    print '[%s] 第  %s 次执行 统计 时间  %s -%s 完成!' % (
                        datetime.datetime.now(), i + 1, s, e)
        except:
            traceback.print_exc()
예제 #6
0
    def handle(self, *args, **options):
        try:
            self.edate = options.get('edate', '') or datetime_to_str(
                datetime.datetime.now())
            self.sdate = options.get('sdate', '') or self.edate

            self.server_ids = [
                s for s in options.get('server_ids', '').split(',') if s
            ]

            if options.get('cron'):
                self.cron_run()
                return

            if self.edate:
                sdate = convert_to_datetime(self.sdate)
                edate = convert_to_datetime(self.edate)
                im = InsertOnlineDateManager(sdate, edate, self.server_ids)
                im.run()
                close_connections()
            else:
                print '没有提供参数!'
        except:
            traceback.print_exc()
예제 #7
0
 def __init__(self, run_date=None, timezone=None):
     timezone = astimezone(timezone) or get_localzone()
     if run_date is not None:
         self.run_date = convert_to_datetime(run_date, timezone, 'run_date')
     else:
         self.run_date = datetime.now(timezone)