-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 0.9.13 update * 0.9.13 version start * 0.9.13 fix bug * 0.9.13 update * 0.9.13 fix sig * 0.9.13 新增两个信号函数 * 0.9.13 dummy 方法优化 * 0.9.13 add flow * 0.9.13 新增三买信号 * 0.9.13 新增BE信号 * 0.9.13 新增BE信号 * 0.9.13 新增板块效应分析功能 * 0.9.13 新增信号函数 * 0.9.13 单品种复盘辅助 * 0.9.13 新增笔的表里关系信号 * 0.9.13 新增笔的表里关系信号 * 0.9.13 新增笔的表里关系信号 * 0.9.13 新增信号:100以内质数时序窗口辅助笔结束判断 * 0.9.13 新增交易价格敏感性分析辅助工具 * 0.9.13 SignalsPerformance * 0.9.13 对接掘金终端 * 0.9.13 对接掘金终端 * 0.9.13 update * 0.9.13 优化 plotly K线绘制 * 0.9.13 新增基础信号函数 * 0.9.13 新增 get_raw_bars * 0.9.13 新增 dummy backtest * 0.9.13 新增 dummy backtest * 0.9.13 新增掘金终端对接
- Loading branch information
Showing
29 changed files
with
1,657 additions
and
653 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,18 @@ | |
from czsc.utils.cache import home_path, get_dir_size, empty_cache_path | ||
from czsc.traders import CzscTrader, CzscSignals, generate_czsc_signals, check_signals_acc, get_unique_signals | ||
from czsc.traders import PairsPerformance, combine_holds_and_pairs, combine_dates_and_pairs, stock_holds_performance | ||
from czsc.traders import DummyBacktest | ||
from czsc.strategies import CzscStrategyBase | ||
from czsc.utils import KlineChart, BarGenerator, resample_bars, dill_dump, dill_load, read_json, save_json | ||
from czsc.utils import get_sub_elements, get_py_namespace, freqs_sorted, x_round, import_by_name, create_grid_params | ||
from czsc.utils import cal_trade_price | ||
from czsc.sensors import holds_concepts_effect, StocksDaySensor, ThsConceptsSensor, SignalsPerformance | ||
|
||
|
||
__version__ = "0.9.12" | ||
__version__ = "0.9.13" | ||
__author__ = "zengbin93" | ||
__email__ = "[email protected]" | ||
__date__ = "20230312" | ||
__date__ = "20230314" | ||
|
||
|
||
if envs.get_welcome(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,10 @@ | |
email: [email protected] | ||
create_dt: 2021/11/17 18:50 | ||
""" | ||
import os | ||
import traceback | ||
import pandas as pd | ||
import numpy as np | ||
from tqdm import tqdm | ||
from datetime import timedelta | ||
from collections import Counter | ||
from typing import Callable, List, AnyStr | ||
from sklearn.preprocessing import KBinsDiscretizer | ||
|
||
|
@@ -259,3 +257,48 @@ def report(self, file_xlsx=None): | |
df_.to_excel(writer, sheet_name=sn, index=False) | ||
writer.close() | ||
return res | ||
|
||
|
||
def holds_concepts_effect(holds: pd.DataFrame, concepts: dict, top_n=20, min_n=3, **kwargs): | ||
"""股票持仓列表的板块效应 | ||
原理概述:在选股时,如果股票的概念板块与组合中的其他股票的概念板块有重合,那么这个股票的表现会更好。 | ||
:param holds: 组合股票池数据,样例: | ||
成分日期 证券代码 n1b 持仓权重 | ||
0 2020-01-02 000001.SZ 183.758194 0.001232 | ||
1 2020-01-02 000002.SZ -156.633896 0.001232 | ||
2 2020-01-02 000063.SZ 310.296204 0.001232 | ||
3 2020-01-02 000066.SZ -131.824997 0.001232 | ||
4 2020-01-02 000069.SZ -38.561699 0.001232 | ||
:param concepts: 股票的概念板块,样例: | ||
{ | ||
'002507.SZ': ['电子商务', '超级品牌', '国企改革'], | ||
'002508.SZ': ['家用电器', '杭州亚运会', '恒大概念'] | ||
} | ||
:param top_n: 选取前 n 个密集概念 | ||
:param min_n: 单股票至少要有 n 个概念在 top_n 中 | ||
:return: 过滤后的选股结果,每个时间点的 top_n 概念 | ||
""" | ||
if kwargs.get('copy', True): | ||
holds = holds.copy() | ||
|
||
holds['概念板块'] = holds['证券代码'].map(concepts).fillna('') | ||
holds['概念数量'] = holds['概念板块'].apply(len) | ||
holds = holds[holds['概念数量'] > 0] | ||
|
||
new_holds = [] | ||
dt_key_concepts = {} | ||
for dt, dfg in tqdm(holds.groupby('成分日期'), desc='计算板块效应'): | ||
# 计算密集出现的概念 | ||
key_concepts = [k for k, v in Counter([x for y in dfg['概念板块'] for x in y]).most_common(top_n)] | ||
dt_key_concepts[dt] = key_concepts | ||
|
||
# 计算在密集概念中出现次数超过min_n的股票 | ||
dfg['强势概念'] = dfg['概念板块'].apply(lambda x: ','.join(set(x) & set(key_concepts))) | ||
sel = dfg[dfg['强势概念'].apply(lambda x: len(x.split(',')) >= min_n)] | ||
new_holds.append(sel) | ||
|
||
dfh = pd.concat(new_holds, ignore_index=True) | ||
dfk = pd.DataFrame([{"成分日期": k, '强势概念': v} for k, v in dt_key_concepts.items()]) | ||
return dfh, dfk |
Oops, something went wrong.