1 Star 0 Fork 16

小鹏/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rsi.py 2.60 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2017-05-18 15:33 . 加入美股的下载更新
#coding=utf-8
import talib as ta
import numpy as np
import pandas as pd
import os,time,sys,re,datetime
class Rsi:
__instance = None
def __init__(self):
pass
@classmethod
def getInstance(cls):
if(cls.__instance == None):
cls.__instance = Rsi()
return cls.__instance
def set_rsi_data(self, df, type):
pass
#通过RSI判断买入卖出
def get_RSI(self, df):
df = df.sort_values('date', ascending=True)
#参数6, 12
RSI1 = ta.RSI(np.array(df['close']), timeperiod=6)
RSI2 = ta.RSI(np.array(df['close']), timeperiod=12)
#15-16 快速real 慢速real
df['rsi_six']=pd.Series(RSI1,index=df.index) #快速real 6
df['rsi_twl']=pd.Series(RSI2,index=df.index)#慢real 12
df = df.sort_values('date', ascending=False)
fastrealMA5 = ta.MA(RSI1, timeperiod=5, matype=0)
fastrealMA10 = ta.MA(RSI1, timeperiod=10, matype=0)
fastrealMA20 = ta.MA(RSI1, timeperiod=20, matype=0)
slowrealMA5 = ta.MA(RSI2, timeperiod=5, matype=0)
slowrealMA10 = ta.MA(RSI2, timeperiod=10, matype=0)
slowrealMA20 = ta.MA(RSI2, timeperiod=20, matype=0)
operate = 0
#RSI>80为超买区,RSI<20为超卖区
if df.iat[0,18]<20 or df.iat[0,19]<20:
operate = operate + 2
#elif df.iat[0,18]>80 or df.iat[0,19]>80:
#operate = operate - 2
#RSI上穿50分界线为买入信号,下破50分界线为卖出信号
if (df.iat[1,18] <= 50 and df.iat[0,18] > 50) or (df.iat[1,19] <= 50 and df.iat[0,19] > 50):
operate = operate + 4
#elif (df.iat[1,18]>=50 and df.iat[0,18]<50) or (df.iat[1,19]>=50 and df.iat[0,19]<50):
#operate = operate - 4
#RSI掉头向下为卖出讯号,RSI掉头向上为买入信号
if df.iat[0,7] <= df.iat[0,8] and df.iat[0,8] <= df.iat[0,9]:#K线下降
if (slowrealMA5[0]>=slowrealMA10[0] and slowrealMA10[0]>=slowrealMA20[0]) or \
(fastrealMA5[0]>=fastrealMA10[0] and fastrealMA10[0]>=fastrealMA20[0]): #RSI上涨
operate = operate + 1
#elif df.iat[0,7]>=df.iat[0,8] and df.iat[0,8]>=df.iat[0,9]:#K线上涨
#if (slowrealMA5[0]<=slowrealMA10[0] and slowrealMA10[0]<=slowrealMA20[0]) or \
#(fastrealMA5[0]<=fastrealMA10[0] and fastrealMA10[0]<=fastrealMA20[0]): #RSI下降
#operate = operate - 1
#慢速线与快速线比较观察,若两线同向上,升势较强;若两线同向下,跌势较强;若快速线上穿慢速线为买入信号;若快速线下穿慢速线为卖出信号
if df.iat[0,19]> df.iat[0,18] and df.iat[1,19]<=df.iat[1,18]:
operate = operate + 10
#elif df.iat[0,19]< df.iat[0,18] and df.iat[1,19]>=df.iat[1,18]:
#operate = operate - 10
return operate, df
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaopengshijie/traderStock-gui.git
git@gitee.com:xiaopengshijie/traderStock-gui.git
xiaopengshijie
traderStock-gui
traderStock-gui
master

搜索帮助