コード例 #1
0
    def get_all_instruments(self):
        con_col = self._db.realtime_future_contract_info
        prod_col = self._db.realtime_future_product_info
        code_list = con_col.distinct('CODE')
        inst_list = []

        for c in code_list:
            con_info = con_col.find_one({'CODE': c},
                                        sort=[('DATE', pmg.DESCENDING)])
            prod_info = prod_col.find_one(
                {'CLASS_CODE': con_info['CLASS_CODE']},
                sort=[('DATE', pmg.DESCENDING)])
            inst = {
                # 'abbrev_symbol': 'null',
                'contract_multiplier': con_info['CON_SIZE'],
                'de_listed_date': con_info['DATE_TO'].strftime('%Y-%m-%d'),
                'exchange': 'HKEX',
                'listed_date': con_info['DATE_FROM'].strftime('%Y-%m-%d'),
                'margin_rate': 0.05,
                'maturity_date': con_info['EXPIRY_DATE'].strftime('%Y-%m-%d'),
                'order_book_id': con_info['CODE'],
                'product': 'Index',
                'round_lot': 1.0,
                'settlement_method': 'CashSettlementRequired',
                'symbol': prod_info['PROD_NAME'],
                # 'trading_unit': '5',
                'type': 'Future',
                'underlying_order_book_id': con_info['Filler'],
                'underlying_symbol': con_info['CLASS_CODE']
            }
            inst_list.append(Instrument(inst))
        return inst_list
コード例 #2
0
ファイル: data_souce.py プロジェクト: linshilogin/quant_sdk
    def get_all_instruments(self):
        """
        获取所有Instrument。

        :return: list[:class:`~Instrument`]
        """

        symList = ['SHFE.rb1905']
        instmentList = get_instruments(
            symbols=symList,
            exchanges=None,
            sec_types=None,
            names=None,
            skip_suspended=True,
            skip_st=True,
            fields=
            'symbol,exchange,sec_type,price_tick,listed_date,delisted_date,multiplier,margin_ratio',
            df=False)

        #给退市日期字段 改个名字,从掘金来的名字 和 rqaplha中的名字不一样。改成rqalpha中的名。
        for aInstu in instmentList:
            aInstu.update(de_listed_date=aInstu.pop("delisted_date"))
            aInstu.update(contract_multiplier=aInstu.pop("multiplier"))
            if aInstu['sec_type'] == 4:
                del aInstu["sec_type"]
                aInstu['type'] = "Future"

        instruments = [Instrument(i) for i in instmentList]
        return instruments
コード例 #3
0
    def __init__(self, path, custom_future_info):
        if not os.path.exists(path):
            raise RuntimeError('bundle path {} not exist'.format(
                os.path.abspath(path)))

        def _p(name):
            return os.path.join(path, name)

        funds_day_bar_store = DayBarStore(_p('funds.h5'))
        self._day_bars = {
            INSTRUMENT_TYPE.CS: DayBarStore(_p('stocks.h5')),
            INSTRUMENT_TYPE.INDX: DayBarStore(_p('indexes.h5')),
            INSTRUMENT_TYPE.FUTURE: FutureDayBarStore(_p('futures.h5')),
            INSTRUMENT_TYPE.ETF: funds_day_bar_store,
            INSTRUMENT_TYPE.LOF: funds_day_bar_store
        }  # type: Dict[INSTRUMENT_TYPE, AbstractDayBarStore]

        self._future_info_store = FutureInfoStore(_p("future_info.json"),
                                                  custom_future_info)

        self._instruments_stores = {
        }  # type: Dict[INSTRUMENT_TYPE, AbstractInstrumentStore]
        self._ins_id_or_sym_type_map = {}  # type: Dict[str, INSTRUMENT_TYPE]
        with open(_p('instruments.pk'), 'rb') as f:
            instruments = [
                Instrument(
                    i, lambda i: self._future_info_store.get_future_info(i)[
                        "tick_size"]) for i in pickle.load(f)
            ]
        for ins_type in self.DEFAULT_INS_TYPES:
            self.register_instruments_store(
                InstrumentStore(instruments, ins_type))

        dividend_store = DividendStore(_p('dividends.h5'))
        self._dividends = {
            INSTRUMENT_TYPE.CS: dividend_store,
            INSTRUMENT_TYPE.ETF: dividend_store,
            INSTRUMENT_TYPE.LOF: dividend_store,
        }

        self._calendar_providers = {
            TRADING_CALENDAR_TYPE.EXCHANGE:
            ExchangeTradingCalendarStore(_p("trading_dates.npy"))
        }

        self._yield_curve = YieldCurveStore(_p('yield_curve.h5'))

        split_store = SimpleFactorStore(_p('split_factor.h5'))
        self._split_factors = {
            INSTRUMENT_TYPE.CS: split_store,
            INSTRUMENT_TYPE.ETF: split_store,
            INSTRUMENT_TYPE.LOF: split_store,
        }
        self._ex_cum_factor = SimpleFactorStore(_p('ex_cum_factor.h5'))
        self._share_transformation = ShareTransformationStore(
            _p('share_transformation.json'))

        self._suspend_days = [DateSet(_p('suspended_days.h5'))
                              ]  # type: List[AbstractDateSet]
        self._st_stock_days = DateSet(_p('st_stock_days.h5'))
コード例 #4
0
 def get_instruments_from_mongo(self):
     instruments = []
     codes_cursor = self.db[INSTRUMENT_COL].find().sort(
         "windCode", pymongo.ASCENDING)
     for doc in codes_cursor:
         instrument_dict = {
             'industry_name': 'UNKNOWN',
             'symbol': doc['name'],
             'sector_code': 'UNKNOWN',
             'special_type': 'Normal',
             'industry_code': 'UNKNOWN',
             'type': 'CS',
             'listed_date': '2014-06-01',
             'de_listed_date': '0000-00-00',
             'status': 'Active',
             'concept_names': 'null',
             'abbrev_symbol': 'UNKNOWN',
             'round_lot': 100.0,
             'board_type': 'UNKNOWN',
             'exchange': doc['windCode'].split('.')[1],
             'order_book_id': doc['windCode'],
             'sector_code_name': 'UNKNOWN'
         }
         instruments.append(Instrument(instrument_dict))
     return instruments
コード例 #5
0
    def get_all_instruments(self):
        """
        获取所有Instrument。

        :return: list[:class:`~Instrument`]
        """
        mongo_data = self._instruments["instruments"].find({}, {"_id": 0})
        return [Instrument(i) for i in mongo_data]
コード例 #6
0
    def __init__(self, f):
        with open(f, 'rb') as store:
            d = pickle.load(store)

        self._instruments = []
        for i in d:
            ins = Instrument(i)
            if ins.type in self.SUPPORTED_TYPES:
                self._instruments.append(ins)
コード例 #7
0
    def __init__(self, f, future_info_store):
        # type: (str, FutureInfoStore) -> None
        with open(f, 'rb') as store:
            d = pickle.load(store)

        self._instruments = []
        for i in d:
            ins = Instrument(i, future_info_store)
            if ins.type in self.SUPPORTED_TYPES:
                self._instruments.append(ins)
コード例 #8
0
def mock_instrument(order_book_id="000001",
                    _type="CS",
                    exchange="XSHE",
                    **kwargs):
    from rqalpha.model.instrument import Instrument

    ins_dict = {
        "order_book_id": order_book_id,
        "type": _type,
        "exchange": exchange,
    }
    ins_dict.update(kwargs)

    return Instrument(ins_dict)
コード例 #9
0
    def get_all_instruments(self):
        """
        获取所有Instrument。

        :return: list[:class:`~Instrument`]
        """

        symList = ['SHFE.RB']
        instmentList = get_instruments(symbols=symList,
                                       exchanges=None,
                                       sec_types=None,
                                       names=None,
                                       skip_suspended=True,
                                       skip_st=True,
                                       fields=None,
                                       df=False)

        #给退市日期字段 改个名字,从掘金来的名字 和 rqaplha中的名字不一样。改成rqalpha中的名。
        for aInstu in instmentList:
            aInstu.update(de_listed_date=aInstu.pop("delisted_date"))

        instruments = [Instrument(i) for i in instmentList]
        return instruments
コード例 #10
0
    def get_all_instruments(self):
        """
        获取所有Instrument。---再封装一层,单独写个cache
        :return: list[:class:`~Instrument`]
        """
        if IsFutuMarket_HKStock() is True:
            if self._cache['basicinfo_hk'] is None:
                ret_code, ret_data = self._get_hk_cache()
            else:
                ret_code, ret_data = 0, self._cache['basicinfo_hk']

        elif IsFutuMarket_USStock() is True:
            if self._cache['basicinfo_us'] is None:
                ret_code, ret_data_cs = self._get_us_cache()
            else:
                ret_code, ret_data = 0, self._cache['basicinfo_us']
        else:
            raise ValueError

        if ret_code == RET_ERROR or ret_data is None:
            raise NotImplementedError

        all_instruments = [Instrument(i) for i in ret_data]
        return all_instruments
コード例 #11
0
ファイル: instrument_store.py プロジェクト: zhaopsoul/rqalpha
 def __init__(self, f, market):
     with open(f, 'rb') as store:
         d = pickle.load(store)
     self._instruments = [
         Instrument(update_instrument_dict(i, market=market)) for i in d
     ]
コード例 #12
0
 def __init__(self, f):
     with open(f, 'rb') as store:
         d = pickle.load(store)
     self._instruments = [Instrument(i) for i in d]
コード例 #13
0
 def get_all_instruments(self):
     inst_list = [Instrument(instructment_HSI)]
     return inst_list
コード例 #14
0
ファイル: DataSource.py プロジェクト: hadrianl/rqalpha_kairui
    def get_all_instruments(self):
        Collection = self._db.future_1min
        code_list = Collection.distinct('code')
        inst_list = []
        for c in code_list:
            market = Collection.find_one({'code': c}, {'market': 1})['market']
            # _listed_date =  Collection.find_one({'code': c}, {'datetime': 1}, sort=[('datetime', pymongo.ASCENDING)])['datetime'].date()
            # _maturity_date = Collection.find_one({'code': c}, {'datetime': 1}, sort=[('datetime', pymongo.DESCENDING)])['datetime'].date()
            _listed_date = '0000-00-00'
            _maturity_date = '0000-00-00'
            underlying_symbol, contract = re.findall(r'([A-Z]+?)(L*\d+)', c)[0]
            if c[-2] == 'L':
                is_continuous = True
            else:
                is_continuous = False

            if market == 47:
                _p = 'Index' if c[0] == 'I' else 'Government'
            else:
                _p = 'Commodity'

            instructment = {
                'order_book_id':
                c,
                'symbol':
                c,
                'margin_rate':
                FUTURE_INFO[underlying_symbol]['margin_rate'],
                'abbrev_symbol':
                'null' if is_continuous else c,
                'round_lot':
                1.0,
                'listed_date':
                '0000-00-00' if is_continuous else str(_listed_date),
                'de_listed_date':
                '0000-00-00',
                'type':
                'Future',
                'contract_multiplier':
                FUTURE_INFO[underlying_symbol]['contract_multiplier'],
                'underlying_order_book_id':
                'null' if underlying_symbol not in ('IF', 'IH', 'IC') else
                underlying_symbol,
                'underlying_symbol':
                underlying_symbol,
                'maturity_date':
                '0000-00-00' if is_continuous else str(_maturity_date),
                'settlement_method':
                'CashSettlementRequired',
                'product':
                _p,
                'exchange': {
                    28: 'CZCE',
                    29: 'DCE',
                    30: 'SHFE',
                    47: 'CFFEX'
                }[market],
                # 'trading_unit': '5'
            }
            inst_list.append(Instrument(instructment))
        return inst_list