代码拉取完成,页面将自动刷新
同步操作将从 macroan/traderStock-gui 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。