股票选股代码 import talib import pandas as pd # 这里用talib计算MACD指标,以下代码块需要你自行编写 # TODO: # 计算MACD指标 data = pd.DataFrame(df['close'].values, index=df.index, columns=['close']) macd, macdsignal, macdhist = talib.MACD(data['close'].values, fastperiod=12, slowperiod=26, signalperiod=9) data['macd'] = macd data['macdsignal'] = macdsignal data['macdhist'] = macdhist # 将计算出来的指标添加到原数据表中 df = pd.concat([df, data], axis=1) # 选出上升通道,买入股票 up_threshold = 0 buy_stocks = df.loc[df['macd'] > up_threshold] # 选出下降通道,卖出股票 down_threshold = 0 sell_stocks = df.loc[df['macd'] < down_threshold] |
|