def is_third_buy(stock_code, type): bars = get_data_from_tdxfile(stock_code, type) c = CZSC(bars, freq="日线") if c.signals['倒1形态'] in [Signals.LI0.value]: return True else: return False
def is_third_buy(symbol): """判断一个股票现在是否有日线三买""" bars = get_kline(symbol, freq="D", end_date=datetime.now(), count=1000) c = CZSC(bars, freq="日线") if c.signals['倒1形态'] in [Signals.LI0.value]: return True else: return False
def is_third_buy(symbol): """判断一个股票现在是否有日线三买""" bars = get_kline(symbol, freq="D", end_date=datetime.now(), count=1000) c = CZSC(bars, freq="日线") # 在这里判断是否有五笔三买形态,也可以换成自己感兴趣的形态 if c.signals['倒1五笔'] in [Signals.X5LB0.value, Signals.X5LB1.value]: return True else: return False
def test_kline_pro(): file_kline = os.path.join(cur_path, "data/000001.SH_D.csv") kline = pd.read_csv(file_kline, encoding="utf-8") bars = [ RawBar(symbol=row['symbol'], id=i, freq=Freq.D, open=row['open'], dt=row['dt'], close=row['close'], high=row['high'], low=row['low'], vol=row['vol']) for i, row in kline.iterrows() ] ka = CZSC(bars) # ka.open_in_browser() file_html = 'czsc_render.html' chart = ka.to_echarts() chart.render(file_html) assert os.path.exists(file_html) os.remove(file_html)
def test_kline_pro(): file_kline = os.path.join(cur_path, "data/000001.SH_D.csv") kline = pd.read_csv(file_kline, encoding="utf-8") bars = [ RawBar(symbol=row['symbol'], open=row['open'], dt=row['dt'], close=row['close'], high=row['high'], low=row['low'], vol=row['vol']) for _, row in kline.iterrows() ] ka = CZSC(bars, freq="日线")
def is_third_buy(ts_code): """判断一个股票现在是否有日线三买""" # 调用tushare的K线获取方法,Tushare数据的使用方法,请参考:https://tushare.pro/document/2 end_date = datetime.now() start_date = end_date - timedelta(days=1000) df = ts.pro_bar(ts_code=ts_code, adj='qfq', asset="E", start_date=start_date.strftime("%Y%m%d"), end_date=end_date.strftime("%Y%m%d")) bars = format_kline(df) c = CZSC(bars, freq="日线") # 在这里判断是否有五笔三买形态,也可以换成自己感兴趣的形态 if c.signals['倒1五笔'] in [Signals.X5LB0.value, Signals.X5LB1.value]: return True else: return False
def is_tushathird_buy(ts_code): """判断一个股票现在是否有日线三买""" # 调用tushare的K线获取方法,Tushare数据的使用方法,请参考:https://tushare.pro/document/2 end_date = datetime.now() start_date = end_date - timedelta(days=2000) df = ts.pro_bar(ts_code=ts_code, adj='qfq', asset="E", freq='D', start_date=start_date.strftime("%Y%m%d"), end_date=end_date.strftime("%Y%m%d")) bars = format_tushare_kline(df) c = CZSC(bars, freq="日线", max_bi_count=20) if c.signals['倒1形态'] in [Signals.LI0.value]: return True else: return False
def is_third_buy(symbol): """判断一个股票现在是否有日线三买""" bars = get_kline(symbol, freq="D", end_date=datetime.now(), count=1000) c = CZSC(bars, get_signals=get_default_signals) factor_ = Factor( name="类三买选股因子", signals_any=[ Signal("日线_倒1笔_基础形态_类三买_任意_任意_0"), Signal("日线_倒1笔_类买卖点_类三买_任意_任意_0"), ], signals_all=[ Signal("日线_倒1笔_拟合优度_小于0.2_任意_任意_0") ] ) if factor_.is_match(c.signals): return True else: return False
def stocks_dwm_selector(event: Event, get_signals: Callable, max_count: int = 3000, end_date: [str, datetime] = datetime.now(), wx_key=None): """大级别选股(日线&月线&周线)""" if isinstance(end_date, str): end_date = pd.to_datetime(end_date) kgd_path = "./data/kgd" os.makedirs(kgd_path, exist_ok=True) df = get_instruments(exchanges='SZSE,SHSE', sec_types=1, fields="symbol,sec_name", df=True) records = df.to_dict('records') home_path = os.path.expanduser('~') push_text(content="start running selector", key=wx_key) results = [] for row in tqdm(records, desc=f"{end_date} - get signals"): symbol = row['symbol'] try: file_kgd = os.path.join(kgd_path, f'{symbol}.kgd') if os.path.exists(file_kgd): kgd: KlineGeneratorD = read_pkl(file_kgd) if kgd.end_dt.date() != datetime.now().date() and datetime.now( ).isoweekday() <= 5: k0 = get_kline(symbol, freq="1d", end_time=datetime.now(), count=1) k0 = [x for x in k0 if x.dt > kgd.end_dt] if k0: print(k0) for bar in k0: kgd.update(bar) else: k0 = get_kline(symbol, end_time=end_date, freq='1d', count=10000, adjust=ADJUST_PREV) kgd = KlineGeneratorD() for bar in k0: kgd.update(bar) save_pkl(kgd, file_kgd) # assert kgd.end_dt.date() == datetime.now().date(), f"kgd.end_dt = {kgd.end_dt}" last_vols = [ k_.open * k_.vol for k_ in kgd.bars[Freq.D.value][-10:] ] if min(last_vols) < 1e8: continue c0 = CZSC(kgd.bars[Freq.D.value][-max_count:], get_signals=get_signals) c1 = CZSC(kgd.bars[Freq.W.value][-max_count:], get_signals=get_signals) c2 = CZSC(kgd.bars[Freq.M.value][-max_count:], get_signals=get_signals) s = OrderedDict(row) s.update(c0.signals) s.update(c1.signals) s.update(c2.signals) m, f = event.is_match(s) if m: msg = f"{s['sec_name']}: {f}\n" msg += f"最新时间:{kgd.end_dt.strftime(dt_fmt)}\n" msg += f"同花顺F10:http://basic.10jqka.com.cn/{symbol.split('.')[1]}\n" msg += f"新浪行情:https://finance.sina.com.cn/realstock/company/{symbol[:2].lower()}{symbol[-6:]}/nc.shtml" push_text(content=msg, key=wx_key) res = { 'symbol': symbol, 'name': s['sec_name'], 'reason': f, 'end_dt': kgd.end_dt.strftime(dt_fmt), 'F10': f"http://basic.10jqka.com.cn/{symbol.split('.')[1]}", 'Kline': f"https://finance.sina.com.cn/realstock/company/{symbol[:2].lower()}{symbol[-6:]}/nc.shtml" } results.append(res) print(res) except: print("fail on {}".format(symbol)) traceback.print_exc() file_results = os.path.join( home_path, f"selector_results_{end_date.strftime('%Y%m%d')}.xlsx") df_r = pd.DataFrame(results) df_r.to_excel(file_results, index=False) push_file(file_results, key=wx_key) push_text(content="end running selector", key=wx_key)