朋友们大家好今天来学习这个主力暗盘资金通达信指标算法,注意:本指标源码用于通达信,友情情提示:代码较多,一定要复制全。本文所述模型算法仅限学术探讨,指标公式作为知识免费分享配资开户查询网,'基于开源数据集的理论推演',仅用于学习交流。
图片配资开户查询网
图片
风险提示:本指标仅供技术研究与学习交流使用。市场具有高度不确定性,任何基于本指标的决策都需要自行承担风险,不构成任何投资建议。01 指标图例
图片
图一
图片
图二02 Py源码
1、安装Python 3.8+ 版本
2、安装必要库
pip install pandas numpy3、设置接口
import pandas as pdimport pandas_ta as taimport numpy as npdef quant_hedge_strategy(df): # 主力暗盘资金副图指标 df['量化对冲1'] = ta.ema(df['close'], length=9) df['量化对冲3'] = ta.ema(df['量化对冲1'] * 1.14, length=5) df['量化对冲4'] = ta.ema(df['close'], length=2) # 计算130日高低点 df['130日高点'] = df['high'].rolling(130).max() df['130日低点'] = df['low'].rolling(130).min() # 计算条件柱状图 df['stickline_cond'] = np.where(df['量化对冲4'] >= df['量化对冲3'], 1, 0) # 计算其他指标 df['40日最低'] = df['low'].rolling(40).min() df['量化对冲2'] = (df['close'] - df['40日最低']) / df['40日最低'] * 100 df['MA40'] = df['close'].rolling(40).mean() df['量化对冲7'] = (df['close'] - df['MA40']) / df['MA40'] * 100 df['40日最低_MA40'] = df['40日最低'].rolling(40).mean() df['量化对冲8'] = (df['close'] - df['40日最低_MA40']) / df['40日最低_MA40'] * 100 df['量化对冲9'] = 28 df['量化对冲10'] = df['close'].rolling(5).mean() df['100日最高'] = df['量化对冲10'].rolling(100).max() df['量化对冲11'] = np.where(df['量化对冲10'] == df['100日最高'], df['量化对冲8'], np.nan) # 成本分布计算(简化为使用移动平均) df['cost90'] = df['close'].rolling(90).mean().shift(1) df['cost10'] = df['close'].rolling(10).mean().shift(1) df['量化对冲12'] = ((df['close'] * df['volume'] - df['cost90'] * df['volume']) / 20 + 250) * 1.2 / 5 df['量化对冲13'] = ((df['cost90'] * df['volume'] - df['close'] * df['volume']) / 20 + 250) * 1.2 / 5 df['量化对冲14'] = ((df['close'] * df['volume'] - df['cost10'] * df['volume']) / 20 + 250) * 1.2 / 5 df['量化对冲15'] = ((df['cost10'] * df['volume'] - df['close'] * df['volume']) / 20 + 250) * 1.2 / 5 # 主力暗盘资金副图指标信号条件 df['量化对冲5'] = ((df['量化对冲14'] > 0) & ((df['量化对冲12'] > df['量化对冲13']) | (df['量化对冲12'] > 0))) df['量化对冲6'] = ((df['量化对冲14'] > 0) & (df['量化对冲12'] > 0) & (df['量化对冲13'] < 0) & (df['量化对冲15'] < 0)) df['量化对冲5_count'] = df['量化对冲5'].rolling(10).sum() df['量化对冲6_count'] = df['量化对冲6'].rolling(60).sum() df['量化对冲16'] = ((df['量化对冲5'] & (df['量化对冲5_count'] == 1)) | (df['量化对冲6'] & (df['量化对冲6_count'] == 1))) df['量化对冲16_count'] = df['量化对冲16'].rolling(20).sum() df['起飞信号'] = np.where(df['量化对冲16'] & (df['量化对冲16_count'] == 1), df['量化对冲2'] * 1.16, np.nan) # 妖股信号 df['量化对冲14_60日高点'] = df['量化对冲14'].rolling(60).max() df['量化对冲14_20日高点'] = df['量化对冲14'].rolling(20).max() df['妖股条件1'] = df['量化对冲14'] >= df['量化对冲14_60日高点'] df['妖股条件2'] = (df['量化对冲14'] >= df['量化对冲14_20日高点']).rolling(20).sum() == 1 df['妖股条件3'] = df['量化对冲14'] > df['量化对冲13'] df['妖股信号'] = np.where(df['妖股条件1'] & df['妖股条件2'] & df['妖股条件3'], df['量化对冲2'] * 1.16, np.nan) # 交叉信号 df['交叉信号'] = np.where(df['量化对冲2'].shift(1) < df['量化对冲9'], df['量化对冲2'], np.nan) return df# 使用示例if __name__ == '__main__': # 读取股票数据(需要包含日期、开盘价、最高价、最低价、收盘价、成交量) data = { 'date': pd.date_range(start='2023-01-01', periods=200), 'open': np.random.uniform(100, 200, 200), 'high': np.random.uniform(110, 220, 200), 'low': np.random.uniform(90, 190, 200), 'close': np.random.uniform(100, 200, 200), 'volume': np.random.randint(10000, 100000, 200) } df = pd.DataFrame(data) df.set_index('date', inplace=True) # 计算量化对冲指标 result_df = quant_hedge_strategy(df) # 输出结果 print(result_df[['量化对冲1', '量化对冲2', '量化对冲3', '量化对冲4', '量化对冲11', '起飞信号', '妖股信号', '交叉信号']].tail())
图片
03 指标源码
通达信复制下方代码即可配资开户查询网,下方代码仅用于学习交流使用。
量化对冲1:=EMA(C,9);量化对冲3:=EMA(量化对冲1*1.14,5),COLORGREEN;量化对冲4:=EMA(C,2),COLORRED;STICKLINE(量化对冲4>=量化对冲3,REFDATE(HHV(H,130),DATE),REFDATE(LLV(L,130),DATE),1,0),COLOR545454;量化对冲2:(C-LLV(LOW,40))/LLV(LOW,40)*100,COLORYELLOW;量化对冲7:(C-MA(C,40))/MA(C,40)*100,NODRAW;量化对冲8:(C-MA(LLV(LOW,40),40))/MA(LLV(LOW,40),40)*100,COLORYELLOW;量化对冲9:28,COLORLIBLUE,DOTLINE;DRAWICON(CROSS(量化对冲2,量化对冲9),量化对冲2,9);量化对冲10:=MA(C,5);量化对冲11:IF((HHV(量化对冲10,100)=量化对冲10),量化对冲8,DRAWNULL),COLORMAGENTA,LINETHICK5;量化对冲12:=((C*V-REF(COST(90),1)*V)/20+250)*1.2/5,COLORMAGENTA;量化对冲13:=((REF(COST(90),1)*V-C*V)/20+250)*1.2/5,COLORCYAN;量化对冲14:=((C*V-REF(COST(10),1)*V)/20+250)*1.2/5,COLORRED;量化对冲15:=((REF(COST(10),1)*V-C*V)/20+250)*1.2/5,COLORBLUE;量化对冲5:=(量化对冲14>0&&CROSS(量化对冲12,量化对冲13)鑫盛优配提示:文章来自网络,不代表本站观点。