def start_up(self, env, mod_config): self._env = env self._mod_config = mod_config self._enabled = (mod_config.record or mod_config.plot or mod_config.output_file or mod_config.plot_save_file or mod_config.report_save_path or mod_config.bechmark) if self._enabled: env.event_bus.add_listener(EVENT.POST_SYSTEM_INIT, self._subscribe_events) if not mod_config.benchmark: if getattr(env.config.base, "benchmark", None): user_system_log.warning( _("config 'base.benchmark' is deprecated, use 'mod.sys_analyser.benchmark' instead" )) mod_config.benchmark = getattr(env.config.base, "benchmark") if mod_config.benchmark: self._benchmark = self._parse_benchmark(mod_config.benchmark) self._plot_store = PlotStore(env) export_as_api(self._plot_store.plot)
def start_up(self, env, mod_config): if DEFAULT_ACCOUNT_TYPE.STOCK not in env.config.base.accounts: return from .scheduler import Scheduler, market_close, market_open self._scheduler = Scheduler(env.config.base.frequency) export_as_api(self._scheduler, name='scheduler') export_as_api(market_open) export_as_api(market_close)
quarter, interval, order_book_ids, if_adjusted, max_info_date=int_date, market='cn') if result is None: return pd.DataFrame() if if_adjusted == 'ignore': result = result.reset_index().sort_values('info_date') result = result.groupby(['order_book_id', 'end_date'], as_index=False).fillna(method='ffill') result = result.drop(['info_date', 'if_adjusted'], axis=1) result = result.drop_duplicates(['order_book_id', 'end_date'], keep='last') result = result.set_index(['order_book_id', 'end_date']).sort_index() return result @export_as_api @apply_rules(verify_that('entities').are_valid_query_entities()) def query(*entities): return rqdatac.query(*entities) export_as_api(rqdatac.financials, name='financials') export_as_api(rqdatac.financials, name='Financials') export_as_api(rqdatac.fundamentals, name='fundamentals') export_as_api(rqdatac.Fundamentals, name='Fundamentals')
from rqalpha.utils.exception import RQInvalidArgument from rqalpha.utils.i18n import gettext as _ from rqalpha.utils.arg_checker import apply_rules, verify_that from rqalpha.api import export_as_api from rqalpha.utils.logger import user_log as logger, user_system_log, user_print from rqalpha.model.instrument import Instrument from rqalpha.model.tick import TickObject from rqalpha.const import ( EXECUTION_PHASE, ORDER_STATUS, SIDE, POSITION_EFFECT, ORDER_TYPE, MATCHING_TYPE, RUN_TYPE, POSITION_DIRECTION, ) from rqalpha.model.order import Order, MarketOrder, LimitOrder, OrderStyle from rqalpha.core.events import EVENT, Event from rqalpha.core.strategy_context import StrategyContext from rqalpha.portfolio.position import Position export_as_api(logger, name='logger') export_as_api(user_print, name='print') export_as_api(LimitOrder, name='LimitOrder') export_as_api(MarketOrder, name='MarketOrder') export_as_api(ORDER_STATUS, name='ORDER_STATUS') export_as_api(SIDE, name='SIDE') export_as_api(POSITION_EFFECT, name='POSITION_EFFECT') export_as_api(POSITION_DIRECTION, name='POSITION_DIRECTION') export_as_api(ORDER_TYPE, name='ORDER_TYPE') export_as_api(RUN_TYPE, name='RUN_TYPE') export_as_api(MATCHING_TYPE, name='MATCHING_TYPE') export_as_api(EVENT, name='EVENT') def assure_instrument(id_or_ins): if isinstance(id_or_ins, Instrument):
Instrument, IndustryCode as industry_code, IndustryCodeItem, SectorCode as sector_code, SectorCodeItem ) from rqalpha.model.order import Order, MarketOrder, LimitOrder, OrderStyle from rqalpha.interface import AbstractPosition from rqalpha.utils import is_valid_price from rqalpha.utils.arg_checker import apply_rules, verify_that from rqalpha.utils.exception import RQInvalidArgument from rqalpha.utils.i18n import gettext as _ from rqalpha.utils.logger import user_system_log from rqalpha.mod.rqalpha_mod_sys_scheduler.scheduler import market_close, market_open from rqalpha.mod.rqalpha_mod_sys_scheduler import scheduler # 使用Decimal 解决浮点数运算精度问题 getcontext().prec = 10 export_as_api(market_close) export_as_api(market_open) export_as_api(industry_code, name='industry_code') export_as_api(sector_code, name='sector_code') @export_as_api @ExecutionContext.enforce_phase( EXECUTION_PHASE.OPEN_AUCTION, EXECUTION_PHASE.ON_BAR, EXECUTION_PHASE.ON_TICK, EXECUTION_PHASE.SCHEDULED, EXECUTION_PHASE.GLOBAL ) @apply_rules(verify_that('id_or_ins').is_valid_stock(), verify_that('amount').is_number(),
from rqalpha.model.instrument import IndustryCode as industry_code from rqalpha.model.instrument import IndustryCodeItem, Instrument from rqalpha.model.instrument import SectorCode as sector_code from rqalpha.model.instrument import SectorCodeItem from rqalpha.model.order import LimitOrder, MarketOrder, Order, OrderStyle from rqalpha.utils import INST_TYPE_IN_STOCK_ACCOUNT, is_valid_price from rqalpha.utils.arg_checker import apply_rules, verify_that from rqalpha.utils.datetime_func import to_date from rqalpha.utils.exception import RQInvalidArgument from rqalpha.utils.i18n import gettext as _ from rqalpha.utils.logger import user_system_log # 使用Decimal 解决浮点数运算精度问题 getcontext().prec = 10 export_as_api(industry_code, name='industry_code') export_as_api(sector_code, name='sector_code') KSH_MIN_AMOUNT = 200 def _get_account_position_ins(id_or_ins): ins = assure_instrument(id_or_ins) account = Environment.get_instance().portfolio.accounts[ DEFAULT_ACCOUNT_TYPE.STOCK] position = account.get_position(ins.order_book_id, POSITION_DIRECTION.LONG) return account, position, ins def _get_ksh_amount(amount): return 0 if abs(amount) < KSH_MIN_AMOUNT else amount // 1