基于VNPY进行功能拓展
Project description
vnpy_extra
一、 简介
1. 功能简介
本工具包是基于vnpy的回测库的一些增强函数
2. 版本历史(按周汇总)
-
2021-08-06 v0.7.20210806.0
feat: add param output_available_only on backtest_by_json.
feat: add plot_with_weights.
feat: add AccountStrategyMapping.strategy_settings.alias("strategy_settings_of_account") column.
feat: add CtaSignal.pos.
feat: add CtaSignal.strategy_parameters.
feat: add do_update_base_positions on test_po.
feat: log 最短周期策略 and None check.
feat: add check_signal_name_list param at get_signal_params on MultiSignalsTemplate.
feat: add exit_price, keep_win_loss_counter, daily_trade_stats_list.
feat: add short_name_with_file_name_if_exist on fix: output_available_only=False on backtest_by_json.
fix: root_folder_name missing for root_folder_path.
fix: ignore duplicate records.
fix: return None if self.charts_data is None on get_balance_df.
fix: rr_df plot wrong on plot_with_weights.
fix: lw_dd_pct, lw_drawdown error if drawdown_s.count() <= 1.
fix: [make_param_2_str() for key, _ in kwargs.items() if key not in ('module_name', )] on get_name_by_param.
refactor: move STOP_OPENING_POS_PARAM = "stop_opening_pos" ENABLE_COLLECT_DATA_PARAM = "enable_collect_data" to constants.py.
refactor: enhance get_interval_str and get_name_by_param.
refactor: params_str = '_'.join([str(v) for v in signal_name_id_name_dic.values()]).
refactor: ignore_fields='auto'. -
2021-07-30 v0.7.20210730.2
feat: add monthly_holding_rr_distributions.
feat: add strategy_obj param on CtaSignal.
feat: add loss win hist bars on monthly_holding_rr_distributions_dic.
feat: backtest_by_json supports bulk_backtest_with_backtest_params_iter.
feat: latest_reject_response_order reset to None when on_stop.
feat: generate_strategy_setting_file(ignore_stop_opening_pos_stg=True).
feat: add PortfolioOptimizeGoalEnum.
feat: add param ignore_stop_opening_pos_stg.
fix: exchange wrong and name_idx_dic = {v: k for k, v in structure_df['字段名'].items()}.
fix: msg missing and "【非交易时段】" check if self._is_realtime_mode.
fix: handle StrategyInfo.get_strategy_class_by_name(strategy_class_name) error.
fix: AttributeError: 'weakref' object has no attribute 'vt_symbol_price_tick'.
fix: update AccountStrategyMapping but StrategyBacktestStats.
refactor: instrument_type = get_instrument_type(symbol, pattern=PATTERN_INSTRUMENT_TYPE_OPTION, error_log=False).
refactor: engine_kwargs['end'] = end or date.today() of backtest_by_json.
refactor: CtaSignal strategy_obj 参数为必输项。 -
2021-07-23 v0.7.20210722.3
feat: add replace_vt_symbol_2_main_contract_of_settings.
feat: add file_name_include_symbol.
feat: add user_name_broker_id_pair_list on backtest_all_strategies.
feat: add get_vt_symbol_multiplier.
feat: add AccountStrategyMapping.get_stats_by_account, StrategyBacktestStats.get_stats_key, StrategyBacktestStats.get_stats_key_str, StrategyBacktestStats.get_balance_df.
feat: add SymbolsInfo.get_symbol_latest_price_dic StrategyBacktestStats.set_base_position.
feat: add stg_list param on generate_strategy_setting_file.
feat: add PortfolioOptimize.
fix: change shown_name to file_name_header by default.
fix: setting file format error.
fix: ignore KeyError on pop all traded order.
fix: ignore IntegrityError on backup to archive.
fix: engine_kwargs[vt_symbol_key] = engine_kwargs[vt_symbol_key].split("_") if it's portfolio.
fix: .execute() missing on AccountStrategyMapping.insert.
fix: set shown_name, short_name if they are not None.
fix: z_score_days: typing.Optional[int].
fix: None check -> unavailable check on cta signal params.
fix: add MacpMacmaPrAndFutures2Options demo.
fix: add try catch on run_backtesting.
refactor: user_name: str = CharField(max_length=50, help_text="用户名") broker_id: str = CharField(max_length=20, help_text="经纪商代码") on AccountStrategyMapping.
refactor: numpy>=1.20.3. 重新配置环境:pip uninstall enum34 -y pip install "numpy-1.21.0+mkl-cp37-cp37m-win_amd64.whl" pip install vnpy_extra-0.7.20210722.1-py3-none-any.whl pip install cvxpy==1.1.13 pip install cvxopt==1.2.6 opencv_python==4.5.3
-
2021-07-16 v0.7.20210716.0
feat: add start, end on backtest_all_strategies of track_performance.py。
feat: add column visible on strategy_info.ALTER TABLE `vnpy`.`strategy_info` ADD COLUMN `visible` TINYINT NULL DEFAULT 1 AFTER `backtest_folder_path`;
feat: add function backup_tables_2_zips to backup.
feat: add generate_setting_json_file on backtest funcs.
feat: add gross profits.
feat: close -> open if position conflict on report.
fix: z_score_days error on macd signal.
fix: add indent=4 on json file.
refactor: 5 years for track backtest.
refactor: add index on bac.ALTER TABLE `vnpy`.`strategy_backtest_stats` DROP INDEX `query_symbol_status` , ADD INDEX `query_symbol_status` (`backtest_status` ASC, `symbols_info_id` ASC, `stg_info_id` ASC) VISIBLE, DROP INDEX `query_symbol_available` , ADD INDEX `query_symbol_available` (`available` ASC, `symbols_info_id` ASC, `stg_info_id` ASC) VISIBLE;
-
2021-07-09 v0.7.20210709.1
feat: record_file_name = os.path.join(output_folder, f"{zip_file_name}.txt").
feat: add load_days_span on template.py.
feat: add AccountStrategyMapping.insert on import_by_settings.
feat: add TradeDateModel.transfer_from_wind().
feat: raise error if setting not in parameters on template.py.
feat: add send_order_2_target_pos_close_rejected on TargetPosAndPriceNoStopOrderTemplate.
feat: ignore target if target_price<0 on TargetPosAndPriceTemplate. feat: add TargetPosAndPriceFutures2OptionTemplate for futures position -> options positions.、 fix: 发现部分情况下 engine_kwargs 中 symbol 与 stats.symbols_info.symbols 不一致,以后者为准.
fix: remove AccountStrategyMapping.import_by_settings(settings) from import_from_json_file.
fix: ignore 'class_name' in setting.
fix: mismatch symbols' target_price should > 0.
fix: "target_pos" not in self.variables check on TargetPosAndPriceTemplate of cta.
fix: "targets" not in self.variables check on TargetPosAndPriceTemplate of portfolio.
refactor: upload records of uploading tick data of options.
refactor: add nbconvert==5.6.1.
refactor: add logger_name on all cta/portfolio templates. -
2021-07-02 v0.7.20210702.1
feat: Scripts for handling 国泰君安 Option Tick data.
feat: add generate_df, generate_factors, generate_y_s, generate_x_df, load_and_plot_bars.
feat: add logic of generate_x_d.
fix: # noinspection PyUnresolvedReferences import ffn # NOQA
fix: remove cancel_all in on_trade.
fix: sum_df['汇总'] -> sum_df[('区间盈亏', '汇总')].
fix: 隔夜建仓平仓导致一些情况下平仓异常引发warning:"当前持仓 * 手,当前持仓全部订单不足以处理当前平仓,这种情况发生,说明当前持仓数据与交易数据的累加数字不一致,请检查数据是否缺失"。
fix: 1 if trade_data.direction == Direction.SHORT.value else -1.
feat: add output_path_vt_symbol to shorten file_name.
fix: "CY": ["9:00:00", "23:00:00"] on constant.
fix: vt_symbol not in bars check on TargetPosAndPriceTemplate.
fix: order.vt_symbol not in self.targets check.
fix: add strategy_cls=strategy_cls into bulk_backtest_kwargs.
fix: self.set_target_pos(target_pos * self.base_position) on MultiSignalsTemplate.
refactor: lower some log levels. -
2021-06-25 v0.7.20210625.1
feat: add output_path_has_strategy_class_name, output_separate_by_backtest_status.
feat: add MultiSignalsTemplate.
feat: supporting night md available check.
feat: add return to output_report_between, output_monthly_report.
feat: 在output_report_between中增加sum_df行,列的和.
feat: add get_vt_symbol_target_pos_str for logging.
feat: ignore empty columns when generating markdown files.
feat: self.targets[vt_symbol] KeyError check and ignore duplicate recent logs.
fix: db = connect("mysql+pool://{user}:{password}@{host}:{port}/{database}".format(**settings)) if linux.
fix: AttributeError on write_log.
fix: drop(columns=['策略类名']) on report.
fix: RuntimeWarning: divide by zero encountered in double_scalars. -
2021-06-18 v0.7.20210618.1
feat: add get_daily_bar_count on StrategyTemplate.
fix: trade_data.volume == 0 filter.
fix: active_order_waiting_since_dt_dict is None.
fix: vt_symbol key error on.
fix: do not build am if array_size is None.
fix: stg_info, symbols_info is ForeignKeyField.\stg_info 与 StrategyInfo 外键关系在实际数据库中已经解除,但在逻辑关系中保留。 get_available_status_group_by_strategy 函数强烈依赖于该外键关系 ALTER TABLE `vnpy`.`strategy_backtest_stats` DROP FOREIGN KEY `strategy_backtest_stats_ibfk_2`, DROP FOREIGN KEY `strategy_backtest_stats_ibfk_1`;
fix: BarGenerator.is_end_day.
fix: db = MySQLDatabase(**settings) in linux.
fix: with lock on db connections.
refactor: ALTER TABLEvnpy
.dbbardata
ADD PARTITION PARTITIONS 400;
refactor: spread_type check. -
2021-06-11 v0.7.20210611.0
feat: add symbol_is_main_dic for judge the main contract.
feat: add generate_md_by_xls_files.
feat: add signal strategy demo.
fix: engine_kwargs['interval'] = Interval(interval) if interval is not None else Interval.MINUTE.
fix: cover/sell then buy/short on TargetPosAndPriceTemplate.
fix: keep trying bulk insert and backup data if exception.
fix: INSTRUMENT_TYPE_SUBSCRIPTION_DIC 能源所:小写+4个数字.
fix: get_instrument_type_and_exchange.
fix: return_loss_ratio is nan if abs_loss_pnl == 0, return_risk_ratio is nan if return_loss_ratio is nan or 0.
fix: charts_data error when len(vt_symbols)>2.
fix: add output_separate_by_backtest_status for the bug of output folder with backtest_status always.
fix: backtest_status missing.
fix: stg_info -> stg_info_id, symbols_info -> symbols_info_id after remove Foreign Key relations.
refactor: json.dump -obj_2_json.
refactor: change columns order and fix short_name, shown_name order.
refactor: return_loss_ratio with decimals 2.ALTER TABLE `vnpy`.`strategy_backtest_stats` DROP FOREIGN KEY `strategy_backtest_stats_ibfk_2`, DROP FOREIGN KEY `strategy_backtest_stats_ibfk_1`; ALTER TABLE `vnpy`.`strategy_backtest_stats` PARTITION BY KEY(stg_info_id) PARTITIONS 50;
ALTER TABLE `vnpy`.`strategy_backtest_stats_archive` DROP FOREIGN KEY `strategy_backtest_stats_archive_ibfk_2`, DROP FOREIGN KEY `strategy_backtest_stats_archive_ibfk_1`; ALTER TABLE `vnpy`.`strategy_backtest_stats_archive` PARTITION BY KEY(stg_info_id) PARTITIONS 50;
ALTER TABLE `vnpy`.`dbbardata` ADD PARTITION PARTITIONS 400;
-
2021-06-04 v0.7.20210604.1
feat: 增加按策略类统计方法.
feat: StrategyBacktestStats.set_strategy_unavailable.
feat: add StrategyBacktestStats.get_by_keys.
feat: try getting old strategy_stats if strategy_stats_original is None, and reuse backtest_status, short_name, shown_name if they are not None.
feat: add StrategyInfo.get_strategy_class_by_name.
feat: add backtest_by_warning_log.
fix: save to json file if save stats failed.
fix: output_report_between on reports.
fix: z_score = get_daily_min_bar_count() * z_score_days.
fix: daily_bars_needed_at_least on MACDSignal and add short_name on MACD,KDJ,RSI,BOLL.
fix: curr_closing_trade_data is None.
fix: statistics = dict_2_jsonable(statistics).
refactor: beauty log of StrategyBacktestStats.expire_stats.
refactor: add warning '没有找到对应的记录' on update_backtest_status.
refactor: avoid loop import. -
2021-05-28 v0.7.20210528.0
feat: show fire_stop_order in variables if self.stop_loss_rate 0 or self.trailing_stop_rate 0.
feat: add TargetPosAndPriceTemplate on portfolio.
feat: beauty log and add TargetPosAndPriceNoStopOrderTemplate.
feat: enhance ArrayManager with datetime_array.
feat: add spread_type, curr_spread, curr_win_spread, win_spreads, win_am_spread on TargetPosAndPriceSpreadTemplate.
feat: change indicator_dic structure on two engine.
feat: add indicator by trade in portfolio_strategy engine.
fix: show "最新持仓目标 ***" only if target_pos != self.pos and not self.fire_stop_order.
fix: send_and_on_order_dt_dic pop ALLTRADED order.
fix: cancel all stop orders if fire_stop_order and pos -0 done.
fix: cancel_all_stop_orders() -cancel_all().
fix: base_price_type -self.base_price_type.
fix: change way of np.int64 -int.
fix: cancel_all_stop_orders() -cancel_all().
fix: StrategyBacktestStats.update(update_dic).
fix: fire_stop_order_dt is None check.
fix: set 0 when calculate by trade if trades data is None.
fix: (order.volume - order.traded) <= vol <= order.volume on is_same_as_order func and beauty log.
fix: None check on calc_spread_bar.
fix: _update_spread.
refactor: beauty order log. -
2021-05-21 v0.7.20210521.0
feat: add TargetPosAndPriceSpreadTemplate.
feat: add author_list on backtest_all_strategies.
feat: add TargetPosAndPrice2SymbolTemplate.
feat: add get_daily_min_bar_count on enhancement.
feat: add calc_init_load_days on StrategyTemplate.
feat: period_enum become optional. \ feat: 添加calculate_by_trade,通过每笔交易计算指标.
feat: add get_id_name on MACrossPriceSignal.
fix: handle DoesNotExist on apply_2_symbol.
fix: update short_name, shown_name update to None on update_backtest_status.
fix: int64 cannot be json on indicator_dic.
fix: update backtest_status on update_stats.
fix: Duplicate entry error. remove fn.ABS(StrategyBacktestStats.backtest_status) >= StrategyBacktestStatusEnum.QuasiOnline.value condition. -
2021-05-14 v0.7.20210514.0
feat: add z_score_days param on MACDSignal.
feat: add param vt_symbol on CtaSignal.
feat: support period_enum on StrategyTemplate of portfolio strategy.
feat: add strategy_cls name on progress bar.
feat: add param same_direction on is_cross func: 是否要求金叉时一定要方向相同.即:金叉时 price1 方向向上,死叉是 price1 方向向下.
feat: add param same_direction param on MACrossSignal.
feat: update id_name if it's changed when track backtest.
feat: add check_account_mapping on StrategyBacktestStats.update_backtest_status.
feat: add ams of ArrayManager Dict on StrategyTemplate.
fix: avg_entry_price wrong.
fix: TradeDateModel no available date check on is_end_week.
fix: self.set_signal_pos(-flag if self.reverse_bs else flag) on MACrossPriceSignal and add reverse_bs on MACrossSignal.
fix: same_direction is not available param on MACrossPriceSignal.
fix: score +/- wrong.
fix: file extension check ('.csv', '.xls', '.xlsx').
fix: old_id_name = None and add exception log.
fix: only warning if pos status < today and tick data missing.
fix: duplicate key error in some cases of update_stats.
fix: cancel stop_vt_orderids when target position direction changed.
fix: key will not be added in send_and_on_order_dt_dic if stop == True in send_order.
fix: checking bar is None.
fix: handle InterfaceError on StrategyStatus.query_status.
fix: '主连合约' '次主连合约' shown wrong.
fix: do not calc avg_entry_price if self.pos == 0.
fix: load continue data.
refactor: add hint self.window_bar: Optional[BarData] = None.
feat: add new parameter indicator_dic to return of BacktestingEngine.calculate_statistics(), which contain all indicator data.
feat: add new model field indicator_dic to StrategyBacktestStats in orm.py
feat: 数据库变更脚本ALTER TABLE `vnpy`.`strategy_backtest_stats` ADD COLUMN `indicator_dic` JSON NULL DEFAULT NULL AFTER `charts_data`; ALTER TABLE `vnpy`.`strategy_backtest_stats_archive` ADD COLUMN `indicator_dic` JSON NULL DEFAULT NULL AFTER `charts_data`; ALTER TABLE `vnpy`.`strategy_backtest_stats_test` ADD COLUMN `indicator_dic` JSON NULL DEFAULT NULL AFTER `charts_data`;
-
2021-04-30 v0.7.20210430.0
feat: add short_name on sub classes of CtaSignal.
feat: add daily_bars_needed_at_least, get_short_name, get_signal_name_header on CtaSignal.
feat: add unique key of ('stg_info', 'symbols_info', 'short_name',) and ('stg_info', 'symbols_info', 'shown_name',) on StrategyBacktestStats.
feat: auto fill short_name on update_backtest_status.
feat: add update_strategy_stats_by_dir for updating all files in dir.
feat: add score on calculate_statistics.
feat: 追踪回测时,文件名 id_name_[short_name].
feat: merge daily price and profit charts together.
feat: get_available_status_group_by_strategy all filter by symbols list or strategy_class_name list.
feat: lower dependency of FutureAdjFactor table when load_bar_data.
feat: add csv_split_chunk to handle large csv files.
fix: self.current_bars[vt_symbol] is None on send_order of portfolio template.py.
fix: symbols.upper() on get_symbols_id_dict and update_backtest_status.
fix: only warning if pos status < today and tick data missing.
refactor: lru_cache(maxsize=10) lower memory use on load_data.
refactor: root_folder_name = f'{strategy_cls.name}{date_2_str(date.today())}' on bulk_backtest.
refactor: root_folder_name=f'{strategy_cls.name}{vt_symbol}' on bulk_backtest_separated_by_symbol. -
2021-04-23 v0.7.20210423.0
feat: 默认 root_folder_name 使用程序创建时的系统日期,为了防止跨日出现多个不同日期的文件夹,该日期初始化后不再改变。
feat: add avg/max/lw/avg_square/most of drawdown on cta/portfolio backtest engine.
feat: enable strategy_only filter and root_folder_name on backtest_all_strategies.
feat: DEFAULT_STATIC_ITEM -DEFAULT_STATIC_ITEM_DIC. and include items: "return_most_drawdown_ratio", "return_loss_ratio".
feat: change default columns orders of bulk backtest output csv/excel files.
feat: add default params 'stop_opening_pos' 'base_position' on settings of settings files.
feat: support output orders/trades with output_orders/output_trades params on backtest.
feat: add capital param on bulk_backtest_separated_by_symbol.
feat: capital=1000000 by default of run_backtest.
feat: add StrategyBacktestStats.expire_stats for disabling old stats by symbols on both StrategyBacktestStats and AccountStrategyMapping.
feat: add trailing stop and stop loss.
feat: day end at 15:00 of BarGenerator.
fix: df is None check when is_available check.
fix: return_loss_ratio wrong.
fix: vt_symbols wrong of settings files.
fix: self.daily_df = None on clear_data. \ refactor: lru_cache() for TradeDateModel.get_trade_date_dic. -
2021-04-16 v0.7.20210416.1
feat: add INSTRUMENT_TYPE_SUBSCRIPTION_DIC.
feat: add validation rule "最大回撤到最后一个交易日需要出现新高".
feat: add shown "annual_return", "sortino_ratio", "return_risk_ratio" by default.
feat: class_name + param_str by default of id_name of strategy.
fix: generate right vt_symbol for subscription.
fix: enhance change_curr_contract of FutureAdjFactor.
fix: main contract switch wrong on apply_2_symbol.
fix: bar.vt_symbol wrong on mock_load_bar_data. \ fix: is_main check on mock_load_bar_data.
fix: secondary contract reversion rights.
fix: return_loss_ratio error on calculate_statistics.
fix: INSTRUMENT_TYPE_SUBSCRIPTION_DIC wrong.
refactor: make 'id_name', 'backtest_status', 'short_name', 'shown_name' at the end columns of csv/xlsx files. -
2021-04-09 v0.7.20210409.0
feat: add some instrument type on EXCHANGE_INSTRUMENTS_DIC.
feat: add vt_symbol_price_tick on CtaTemplate.
feat: get shown_name and short_name from get_name_by_pattern.
feat: add is_cross on func module feat: add ma on ArrayManager.
feat: add MACrossPriceSignal.
fix: wrong error_count on import results.
fix: on creating instance of StrategyTemplate, CtaTemplate of apply_2_symbol function.
fix: add exception handler on add_2_account_strategy_mapping. -
2021-04-02 v0.7.20210402.0
feat: add output_report_between on report function.
feat: stats ['区间盈亏', '交易次数', '盈利次数', '亏损次数'] on reports.
feat: add rr wh fb cy trade datetime range.
feat: add get_instrument_type_and_exchange.
feat: warning '【非交易时段】' only on realtime mode.
feat: add base_price_type param for default kind of price when calculating indexes.
feat: add add_mapping_all, add_2_account_strategy_mapping, apply_2_symbol on StrategyBacktestStats.
fix: key available check on backtest.
fix: broker_id: str = IntegerField(help_text="经纪商代码") of AccountStrategyMapping.
fix: user_name, broker_id = int(user_name), int(broker_id) on AccountStrategyMapping.add_mapping.
fix: logging track test error.
fix: ignore updating ['id_name', 'backtest_status', 'short_name', 'shown_name'] if insert conflict on backtest.
fix: stats wrong on report.
fix: unique index on ('user_name', 'broker_id', 'short_name',) and ('user_name', 'broker_id', 'shown_name',) of AccountStrategyMapping. -
2021-03-25 v0.7.20210325.0
feat: update_strategy_stats_by_df with AccountStrategyMapping.
feat: new logic of import/export settings with AccountStrategyMapping.
feat: support custom is_available func for strategy template.
feat: support start and end date range for bulk_backtest_separated_by_symbol.
feat: add strict logic of window bar on CtaSignal and BarGenerator.
feat: add GeneralPeriodEnum.
feat: init_load_days = 0 by default.
feat: add enable_entry_exit_price feature.
feat: backtest end at 3 month ago for in-sample test by default. -
2021-03-17 v0.7.20210317.0
feat: update hour bar logic of BarGenerator to vnpy same logic.
feat: add {strategy_cls.name}_ on file name header of backtest.
feat: add user_id on file names on daily reports.
feat: speed up load history bar.
fix: reset error_count on each loop.
refactor: add log on bulk backtest. -
2021-03-11 v0.7.20210311.1
feat: 支持加载主连连续合约作为合约历史行情数据(默认为False).
feat: move TBCtaSignal to vnpy_extra_tb.
feat: reset_index on on f'{key}_{date_2_str(date.today())}.xlsx' files. -
2021-03-09 v0.7.20210309.0
feat: self.load_bar(self.init_load_days) on on_init() for cta/portfolio template.
feat: add remove_old_symbol_until_nth_latest on generate_md_with_adj_factor 删除旧的“带 symbol 标记”的主连行情数据,截止到第N个最新的主力合约.
feat: EXCHANGE_INSTRUMENTS_DIC, INSTRUMENT_EXCHANGE_DIC for constants.
feat: add generate md with adj_factor module. -
2021-03-05 v0.6.20210305.0
feat: add StrategyBacktestStatsArchive.restore.
refactor: LatestTickPriceModel.replace -LatestTickPriceModel.insert.
feat: add pool_size for multi thread.
feat: add TBCtaSignal.
feat: add export_tables_2_csv.
fix: engine_kwargs["vt_symbols"] or engine_kwargs["vt_symbol"] mistake on update_backtest_status.
fix: available_df.shape[0]>0 on backtest.
fix: set_index(multi_valued_param_name_list) on backtest.
fix: statistics available check on StrategyBacktestStats.update_stats.
feat: send_email_qq support msg list.
feat: order_by(StrategyBacktestStats.short_name) on StrategyBacktestStats.get_by_status.
feat: variables = ["target_pos", "target_price", "bar_count"] on template.
feat: add block_size=1024 * 1024 * 10 param on build_emails.
feat: add ignore_error param on csv_2_tables and import_data_2_tables.
fix: is_same_as_order for template.
fix: pd.isna(short_name) check.
fix: IntegrityError handler on import_data_2_tables.
feat: replace insert -on duplicate key update.
feat: add trade count summary on monthly report.
feat: update update_backtest_status logic.
fix: reduce reject order.
fix: StrategyBacktestStats.update_backtest_status.
feat: add last_tick and fill default price if price <= 0.
feat: drop_duplicates and create f'{key}_{date_2_str(date.today())}.xlsx' file. -
2021-02-28 v0.6.20210228.0
fix: order timeout on submit status. and clean tmp data when on_start called.
fix: output f'{key}_{date_2_str(date.today())}.csv' file event if len(df_list) == 1.
fix: ignore save_stats exceptions.
feat: remove duplicate msg.
feat: add check datetime trade available.
refactor: fit INSTRUMENT_RATE_DIC.
feat: email_attachment_2_tables, add csv_2_tables.
refactor: logger = logging.getLogger(f'strategies.*.{strategy_name}').
refactor: write_log(f"最新持仓目标 {target_pos} {self.target_price}", 'debug').
fix: annual return, calmar, sharp.
feat: export_tables_and_send_email.
feat: add password param for email login password. feat: export_tables_and_send_email(password).
fix: Writing to Excel with MultiIndex columns and no index ('index'=False) is not yet implemented.
fix: price <= 0.0 check.
fix: output_file_dic = {}.
fix: strategy.strategy_name is None in some cases.
fix: log and ignore lock error when cleaning TradeDataModel.
refactor: create a unique on strategy_class_name. -
2021-02-19 v0.6.20210219.3
feat: feat: add StopOpeningPos.
feat: return output_file_dic on refresh_position_and_report.
feat: use CalVer.
feat: now all signal classes are subclasses of vnpy_extra.utils.enhancement.CtaSignal.
feat: add filter_n_available=1 param for each subclass.
feat: add check_datetime_available. -
2021-02-12 v0.6.21
fix: some dirty data has to be clean.
fix: charts_data null=True, symbols cannot be unique.
refactor: bigger=1.0
feat: add backtest_status_path on output path.
fix: enable_join_collector.
refactor: add description on progress bar.
feat: add charts_data for showing echarts of strategy.
feat: progress bar shows file_name_header.
feat: support import strategy setting from ["cta_strategy_setting.json", "portfolio_strategy_setting.json"].
feat: auto add main_contract testcase for import_strategy_setting module.
fix: case-insensitive for portfolio portfolio_strategy.engine.BacktestingEngine. -
2021-02-03 v0.6.7
feat: add algo trading on TargetPosAndPriceTemplate.
feat: remove tzinfo from last_tick_time on cta's CtaTemplate and portfolio's StrategyTemplate.
feat: add get_id_name function.
feat: add import_strategy_setting module.
fix: export/import tables and send email by io.
fix: ctaTemplate algo trading logic. -
2021-01-26 v0.6.2
feat: add short_name, shown_name by default null and unique into db.
feat: export/import tables and send email by io.
fix: TargetPosAndPriceTemplate order missing. -
2021-01-22 v0.6.0
feat: add track performance feature.
refactor: quant_vnpy -vnpy_extra. -
2021-01-19 v0.5.12
fix: TargetPosAndPriceTemplate current_pos -target_pos by one step.
fix: strategy_class_name wrong. -
2021-01-15 v0.5.5
fix: add exception handle and logger on TradeDataCollector.
fix: TargetPosAndPriceTemplate current_pos -target_pos by one step.
feat: record backtest stats.
feat: add default rate for backtest.
fix: DCE夜盘交易日期为下一交易日,将会被重写为当前系统日期.
fix: 修复跨日报表统计错误.
fix: cross_limit_method param missing for file_name_func function.
fix: 主力合约、次主力合约数据复权整理 bug. -
2021-01-08 v0.5.0
refactor: merge portfolio run_backtest and cta run_backtest.
feat: set_strategy_status(StrategyStatusEnum.Stopped).
feat: monitor add setting.
refactor: longer interval of plotly.io._orca.cleanup.
feat: backtest: output param file if it's available.
fix: MACDSignal.
fix: check not strategy_status_monitor.is_alive(). -
2020-12-27 v0.4.8
feat: backtest: reset_index on result_df.
fix: portfolio template, last_order_dt -dict.
feat: add new TargetPosAndPriceTemplate, MACrossSignal.
feat: backtest: default rate.
feat: backtest: available filter for return_drawdown_ratio < 2 and np.round for some stats items. -
2020-12-25 v0.4.6
feat: backtest: auto search symbol size.
fix: report gl calc wrong in some cases.
fix: report holding pos status calc wrong.
fix: stop_opening_pos on templates. -
2020-12-22 v0.4.2
fix: order_data_collector error on portfolio_strategy.template.
fix: open_price -last_price. -
2020-12-18 v0.4.0
feat: support user_name, broker_id.
feat: add last_order_dt on template.
fix: orm close connection.
feat: position daily stat.
feat: add CrossLimitMethod.fix_price for backtest.
feat: add quant_vnpy.backtest.cta_strategy.template.CtaTemplate.
feat: backtest cross price method.
add position monitor -
2020-12-11 v0.2.16
feat: on_tick active on_bar by bg on template.py.
feat: add OrderDataCollector, TradeDataCollector class.
feat: add stop_if_pos_2_0 on cta template.
fix: bug fix of on_tick and report error. -
2020-12-04 v0.2.8
feat: more readable log.
-
2020-11-30 v0.2.7
feat: orm add symbols.
fix: bug fix on log format.
fix: bug fix on on_stop of portfolio template.
feat: add strategy status monitor.
feat: add bar_count. -
2020-11-20 v0.1.8
bug fix on portfolio's template.
feat: 对 cta 及 portfolio 增加 template 模板类.
feat: signal 增加 0 判断 当 0 时,默认为 default 值.
feat: add current_bar for cta, portfolio's template classes.
fix: template bugs.
feat: 最新依赖版本 IBATS_Common>=0.20.8,最新支持道 vnpy 2.1.7 版本.
feat: 调整 INSTRUMENT_TRADE_TIME_PAIR_DIC 道 constants.py. -
2020-11-10 v0.1.0
feat: 基于vnpy 2.1.6进行的功能增强。此前版本不支持。
二、 环境设置及组件安装(首次运行前需要)
1. 系统环境包含 Anaconda 或 Miniconda(python 3.7 版本)
2. 安装 vnpy 2.1.6或以上版本 \
3. 运行安装相关组件
pip isntall -r requirement.txt
conda install -c plotly plotly-orca
conda install -c plotly python-kaleido
如果执行遇到问题可分别执行如下:
-
通用组件
pip install -r requirement.txt
-
orca 组件 orca 组件为回测功能中保存回测视图结果的组件,windows系统性需要单独安装,才可保证功能正常使用
安装步骤如下:-
安装组件包
conda install -c plotly plotly-orca
-
下载并安装 orca 应用
组件下载地址:orca组件
安装后设置话就环境变了 Path 加入相应路径,默认情况下window10操作系统 orca 组件将被安装在如下路径: C:\Users\mmmaaaggg\AppData\Local\Programs\orca
- 批量关闭 orca 进程方法
ps -ef | grep orca | grep -v grep | awk '{print $2}' | xargs kill -9
-
-
MD文件转word文档工具
到pandoc官网下载对应的软件并安装后即可运行 Scripts\md_2_docx.bat 脚本 -
pycharm MemoryError 解决方案 打开pycharm安装目录 d:\IDE\JetBrains\PyCharm Community Edition 2020.2.1\bin\ ,找到 pycharm.exe.vmoptions 文件,
-Xms128m -Xmx768m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -XX:CICompilerCount=2 -Dsun.io.useCanonPrefixCache=false -Djava.net.preferIPv4Stack=true -Djdk.http.auth.tunneling.disabledSchemes="" -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Djdk.attach.allowAttachSelf
修改 -Xms为 256m -Xmx为 2048m
-Xms256m -Xmx2048m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -XX:CICompilerCount=2 -Dsun.io.useCanonPrefixCache=false -Djava.net.preferIPv4Stack=true -Djdk.http.auth.tunneling.disabledSchemes="" -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Djdk.attach.allowAttachSelf
4. 不错的 Jupyter 组建
-
nbextension
pip install jupyter_contrib_nbextensions -i https://pypi.mirrors.ustc.edu.cn/simple jupyter contrib nbextension install pip install --user jupyter_nbextensions_configurator -i https://pypi.mirrors.ustc.edu.cn/simple jupyter nbextensions_configurator enable --user
-
jupyter-kite
pip install jupyter-kite jupyter labextension install @kiteco/jupyterlab-kite
-
jupyter-matplotlib
pip install ipympl jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib
-
jupyterlab-system-monitor
pip install nbresuse jupyter labextension install jupyterlab-topbar-extension jupyterlab-system-monitor
-
jupyterlab-variableInspector
jupyter labextension install @lckr/jupyterlab_variableinspector
-
debugger
conda install xeus-python=0.8.0 -c conda-forge jupyter labextension install @jupyterlab/debugger
-
其他
pip install jupyterlab_widgets jupyter labextension install @jupyter-widgets/jupyterlab-manager @jupyterlab/toc jupyterlab-execute-time plotlywidget@4.9.0
三、 常用命令
1. 切换远程仓库地址方法
>git remote
origin
>git remote get-url --all origin
https://github.com/IBATS/vnpy_extra.git
>git remote set-url origin git@gitee.com:ibats/vnpy_extra.git
>git push
Enumerating objects: 82, done.
Counting objects: 100% (82/82), done.
Delta compression using up to 8 threads
Compressing objects: 100% (65/65), done.
Writing objects: 100% (65/65), 14.57 KiB | 710.00 KiB/s, done.
Total 65 (delta 50), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:ibats/vnpy_extra.git
4f85956..fe47acc master -master
2. 数据库命令
1) dump 数据
备份主力合约
"c:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe" -u mg -p --databases vnpy dbbardata --where="symbol in ('rb9999', 'hc9999', 'i9999') and `interval`='1m'" dbbardata_dump.sql
备份主力,次主力合约
"c:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe" -u mg -p vnpy dbbardata --where="(symbol like'%9999' or symbol like'%8888') and `interval`='1m'" dbbardata_dump.sql
2) 数据库分区
ALTER TABLE `vnpy`.`dbbardata`
PARTITION BY KEY (symbol) PARTITIONS 100;
ALTER TABLE `vnpy`.`strategy_backtest_stats`
PARTITION BY KEY(stg_info_id) PARTITIONS 50;
3) 错误解决方案
peewee.OperationalError: (-1, 'MySQL Connection not available.', None)
pip install peewee==3.13.3
3. 压缩命令
zip -r0q /media/mg/Data/output_20201220.zip output
4. 独立启动交易界面(可以多开)
cd d:
cd d:\ide\vnstudio
python.exe -m vnstation runtrader "{'gateway': {'CTP': True}, 'app': {'CtaStrategy': True, 'PortfolioStrategy': True, 'PortfolioManager': True}, 'path': 'D:\\TradeTools\\vnpy\\jianxin_11859077'}"
cd c:\ide\vnstudio
python.exe -m vnstation runtrader "{'gateway': {'CTP': True}, 'app': {'CtaStrategy': True, 'PortfolioStrategy': True, 'PortfolioManager': True}, 'path': r'C:\TradeTools\vnpy_work_root\simnow'}"
四、 各个版本常见错误
2.0.3版本
-
错误提示框太长,无法看到错误信息
python.exe -m vnstation
-
错误提示: ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject 解决方法:
Scripts\pip.exe install numpy==1.16.1 --user
-
穿透式测试通不过,采集不到CPU、硬盘、BIOS信息 修改环境变量 增加目录 C:\Windows\SysWOW64\wbem
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file vnpy_extra-0.7.20210806.0-py3-none-any.whl
.
File metadata
- Download URL: vnpy_extra-0.7.20210806.0-py3-none-any.whl
- Upload date:
- Size: 197.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81879df7951063eb2c0c439920db80904cd0c4d548464f97e00e842b75959802 |
|
MD5 | 873ed987592d98684e601349446b398d |
|
BLAKE2b-256 | 073a29a8d582b257f76d9f093def52b3fdc8f2b558f7760f818bf7039d7d7916 |