分享

编写一个股票选股代码

 干货馆 2023-02-24 发布于安徽

​股票选股代码

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]

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多