本文整理汇总了Python中BasicData类的典型用法代码示例。如果您正苦于以下问题:Python BasicData类的具体用法?Python BasicData怎么用?Python BasicData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BasicData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analyze
def analyze(stock_code, date, period):
score = 0.0
signal = ""
RSI = getRSI(stock_code, date)
if 90 > RSI > 80:
score -= 1
signal += "[-1]当六日指标上升到达80时,表示股市已有超买现象;"
if RSI > 90:
score -= -1
signal += "[-1]超过90以上时,则表示已到严重超买的警戒区,股价已形成头部,极可能在短期内反转回转;"
if 10 < RSI < 20:
score += 1
signal += "[1]六日强弱指标下降至20时,表示股市有超卖现象;"
if RSI < 10:
score += 1
signal += "[1]一旦继续下降至10以下时则表示已到严重超卖区域,股价极可能有止跌回升的机会;"
close_in_period = bd.getBasicDataInPeriod("CLOSE_TODAY", stock_code, date, period)
RSI_in_period = bd.getTechDataInPeriod("CCI", stock_code, date, period)
close_k = mu.getPoly(close_in_period, 1)[0]
RSI_k = mu.getPoly(RSI_in_period, 1)[0]
if close_k > 0 and RSI_k < 0:
signal += "强弱指标下降而股价反趋上涨,产生的背离现象;"
if close_k < 0 and RSI_k > 0:
signal += "强弱指标上升而股价反而下跌, 产生的背离现象;"
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("RSI", str(score) + ";" + signal, stock_code, date)
return [score, signal]
示例2: calcROC
def calcROC(stock_code, date, period):
pday = bd.getStockDate(stock_code, date, period)
BX = bd.getBasicData("CLOSE_TODAY", stock_code, pday)
close_today = bd.getBasicData("CLOSE_TODAY", stock_code, date)
AX = close_today - BX
ROC = AX / BX * 100
return round(ROC, 3)
示例3: analyze
def analyze(stock_code, date, period1, period2):
signal = ""
score = 0.0
recent_high_price = bd.getHighPriceInPeriod("CLOSE_TODAY", stock_code, date, period1)
recent_low_price = bd.getLowPriceInPeriod("CLOSE_TODAY", stock_code, date, period1)
close_today = bd.getBasicData("CLOSE_TODAY", stock_code, date)
BBI = getBBI(stock_code, date)
if (abs(close_today - recent_high_price) / recent_high_price <= HIGH_OFFSET / 100) and (BBI > close_today):
score = score - 1
signal = signal + "[-1]股价在高价区以收市价跌破多空线为卖出信号;"
if (abs(close_today - recent_low_price) / recent_low_price <= LOW_OFFSET / 100) and (BBI < close_today):
score = score + 1
signal = signal + "[1]股价在低价区以收市价突破多空线为买入信号;"
BBIs = getBBIs(stock_code, date, period2)
K = mu.getPoly(BBIs, 1)[0]
if (K > 0) and (BBI > close_today):
score += 1
signal += "[1]多空指数由下向上递增,股价在多空线上方,表明多头势强,可以继续持股;"
if (K < 0) and (BBI < close_today):
score -= 1
signal += "[-1]多空指数由上向下递减,股价在多空线下方,表明空头势强,一般不宜买入;"
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("BBI", str(score) + ";" + signal, stock_code, date)
return [score, signal]
示例4: calcAverageGain
def calcAverageGain(stock_code, date, period):
global iterator_count
price_changed = bd.getBasicData("PRICE_CHANGED", stock_code, date)
current_gain = 0.0
if price_changed > 0:
current_gain = price_changed
if iterator_count >= max_iterator:
return calcFirstAverageGain(stock_code, date, period)
else:
iterator_count += 1
average_gain = (calcAverageGain(stock_code, bd.getStockDate(stock_code, date, 1), period) * (
period - 1) + abs(current_gain)) / period
# print date + " Average Gain: " + str(average_gain) + " Current Gain: " + str(current_gain)
return round(average_gain, 3)
示例5: calcEMA
def calcEMA(stock_code, date, period):
if ITERATOR_COUNT >= MAX_ITERATOR:
EXPMA = MA.calcMA(stock_code, date, period)
# print "MIN Date: " +date+ " MA:"+ str(EXPMA)
return EXPMA
else:
global ITERATOR_COUNT
ITERATOR_COUNT = ITERATOR_COUNT + 1
close_today = bd.getBasicData("CLOSE_TODAY", stock_code, date)
pday = du.convertDateToString(bd.getStockDate(stock_code, date, 1), "%Y-%m-%d")
EXPMA_pday = calcEMA(stock_code, pday, period)
EXPMA = 2 * (close_today - EXPMA_pday) / (period + 1) + EXPMA_pday
# print date + ": EXPMA: "+str(EXPMA_PDAY)+" CLOSE: " + str(CLOSE_TODAY) + " EXPMA = " +str(EXPMA)
return round(EXPMA, 3)
示例6: calcAverageLoss
def calcAverageLoss(stock_code, date, period):
global iterator_count
price_changed = bd.getBasicData("PRICE_CHANGED", stock_code, date)
current_loss = 0.0
if price_changed < 0:
current_loss = price_changed
if iterator_count >= max_iterator:
return calcFirstAverageLoss(stock_code, date, period)
else:
iterator_count += 1
average_loss = (calcAverageLoss(stock_code, bd.getStockDate(stock_code, date, 1), period) * (
period - 1) + abs(current_loss)) / period
# print date + " " + str(average_loss) + " Current Loss: " + str(current_loss)
return round(average_loss, 3)
示例7: calcPSY
def calcPSY(stock_code, date, period):
result_set = bd.getBasicDataInPeriod("CLOSE_TODAY, CLOSE_PERVIOUS_DAY", stock_code, date, period)
count = 0.0
for each in result_set:
if each[0] > each[1]:
count += 1
PSY = count / period * 100
return round(PSY, 3)
示例8: calcOBV
def calcOBV(stock_code, date, period):
global ITERATOR_COUNT
close_today = bd.getBasicData("CLOSE_TODAY", stock_code, date)
close_pervious_day = bd.getBasicData("CLOSE_PERVIOUS_DAY", stock_code, date)
volumn = bd.getBasicData("VOLUMN", stock_code, date)
today_volumn = 0.0
if close_today > close_pervious_day:
today_volumn = volumn
if close_today < close_pervious_day:
today_volumn = today_volumn*-1
if ITERATOR_COUNT >= MAX_ITERATOR:
return today_volumn
else:
ITERATOR_COUNT = ITERATOR_COUNT + 1
pday = bd.getStockDate(stock_code, date, 1)
OBV = today_volumn + calcOBV(stock_code, pday, period)
return round(OBV, 3)
示例9: calcFirstAverageGain
def calcFirstAverageGain(stock_code, date, period):
price_changes_in_period = bd.getBasicDataInPeriod("PRICE_CHANGED", stock_code, date, period)
first_average_gain = 0.0
for each in price_changes_in_period:
if first_average_gain > 0:
first_average_gain += each[0]
first_average_gain = first_average_gain / period
print "First Average Gain: " + str(first_average_gain)
return round(first_average_gain, 3)
示例10: calcFirstAverageLoss
def calcFirstAverageLoss(stock_code, date, period):
price_changes_in_period = bd.getBasicDataInPeriod("PRICE_CHANGED", stock_code, date, period)
first_average_loss = 0.0
for each in price_changes_in_period:
if first_average_loss < 0:
first_average_loss += each[0]
first_average_loss = abs(first_average_loss) / period
print "First Average Loss: " + str(first_average_loss)
return round(first_average_loss, 3)
示例11: calcCCI
def calcCCI(stock_code, date, period):
high_today = bd.getBasicData("HIGH_TODAY", stock_code, date)
low_today = bd.getBasicData("LOW_TODAY", stock_code, date)
close_today = bd.getBasicData("CLOSE_TODAY", stock_code, date)
MAn = 0.0
price_in_period = bd.getBasicDataInPeriod("CLOSE_TODAY, HIGH_TODAY, LOW_TODAY", stock_code, date, period)
for each in price_in_period:
MAn += (each[0] + each[1] + each[2])/3
MAn = MAn / period
MD = 0.0
TP = (high_today + low_today + close_today) / 3
for each in price_in_period:
MD += abs(MAn - (each[0] + each[1] + each[2])/3)
MD = MD / period
CCI = (TP - MAn) / MD / 0.015
return round(CCI, 3)
示例12: analyze
def analyze(stock_code, date, period):
signal = ""
score = 0.0
BR = getBR(stock_code, date)
AR = getAR(stock_code, date)
if (BR < AR) and (BR < 100):
score += 1
signal += "[1]BR<AR,且BR<100,可考虑逢低买进;"
if (BR < AR) and (AR < 50):
score += 1
signal += "[1]BR<AR,而AR<50时,是买进信号;"
BRs = getBRs(stock_code, date, period)
ARs = getARs(stock_code, date, period)
BR_K = mu.getPoly(BRs, 1)[0]
AR_K = mu.getPoly(ARs, 1)[0]
if (BR_K >= UP_RATIO_THREHOLD) and (AR_K >= UP_RATIO_THREHOLD):
score -= 1
signal += "[-1]AR和BR同时急速上升,意味着股价已近顶部,持股者应逢高卖出;"
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("BRAR", str(score) + ";" + signal, stock_code, date)
return [score, signal]
示例13: analyze
def analyze(stock_code, date, period):
score = 0
signal = ""
WR = getWR(stock_code, date)
if WR >= 80:
score += 1
signal += "[1]当%R线达到80时,市场处于超卖状况,股价走势随时可能见底。因此,80的横线一般称为买进线,投资者在此可以伺机买入;"
if WR <= 20:
score -= 1
signal += "[-1]当%R线达到20时,市场处于超买状况,走势可能即将见顶,20的横线被称为卖出线;"
WRs = bd.getTechDataInPeriod("WR", stock_code, date, period)
WR_K = mu.getPoly(WRs, 1)[0]
if WR > 50 and WR_K > 0:
score += 1
signal += "[1]当%R向下跌破50中轴线时,市场由弱转强,是买进信号;"
if WR < 50 and WR_K < 0:
score -= 1
signal += "[-1]当%R从超买区向上爬升,突破50中轴线后,可以确认强势转弱,是卖出信号;"
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("WR", str(score) + ";" + signal, stock_code, date)
return [score, signal]
示例14: analyze
def analyze(stock_code, date, period):
score = 0
signal = ""
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("DMI", str(score) + ";" + signal, stock_code, date)
return [score, signal]
示例15: analyze
def analyze(stock_code, date):
score = 0
signal = ""
pday = bd.getStockDate(stock_code, date, 1)
KDJ_K, KDJ_D, KDJ_J = getKDJ(stock_code, date)
KDJ_K_pday, KDJ_D_pday, KDJ_J_pday = getKDJ(stock_code, pday)
if KDJ_K >= 90:
score -= 1
signal += "[-1]K线是快速确认线——数值在90以上为超买;"
if KDJ_K <= 10:
score += 1
signal += "[1]K线是快速确认线——数值在10以下为超卖;"
if KDJ_D >= 80:
score -= 1
signal += "[-1]D线是慢速主干线——数值在80以上为超买;"
if KDJ_D <= 20:
score += 1
signal += "[1]D线是慢速主干线——数值在20以下为超卖;"
if KDJ_J >= 90:
score -= 1
signal += "[-1]J线为方向敏感线,当J值大于90,特别是连续5天以上,股价至少会形成短期头部;"
if KDJ_J <= 10:
score += 1
signal += "[1]J线为方向敏感线,当J值小于10,特别是连续数天以上,股价至少会形成短期底部;"
if KDJ_K_pday < KDJ_D_pday and KDJ_K > KDJ_D:
score += 1
signal += "[1]K线从下方上穿D线,所以在图形上K线向上突破D线时,俗称金叉,即为买进的讯号;"
if KDJ_K < 20 and KDJ_D < 20:
score += 1
signal += "[1]当K,D线在20以下交叉向上,此时的短期买入的信号较为准确;"
# TODO 如果K值在50以下,由下往上接连两次上穿D值,形成右底比左底高的“W底”形态时,后市股价可能会有相当的涨幅。
if KDJ_K_pday > KDJ_D_pday and KDJ_K < KDJ_D:
score -= 1
signal += "[-1]K线从上方下穿D线,显示趋势是向下的,所以在图形上K线向下突破D线时,俗称死叉,即为卖出的讯号;"
if KDJ_K > 20 and KDJ_D > 20:
score -= 1
signal += "[-1]当K,D线在80以上交叉向下,此时的短期卖出的信号较为准确;"
# TODO 如果K值在50以上,由上往下接连两次下穿D值,形成右头比左头低的“M头”形态时,后市股价可能会有相当的跌幅。。
# TODO 4. 通过KDJ与股价背离的走势,判断股价顶底也是颇为实用的方法:4.1股价创新高,而KD值没有创新高,为顶背离,应卖出;4.2股价创新低,而KD值没有创新低,为底背离,应买入
'''
print KDJ_K
print KDJ_D
print KDJ_J
print KDJ_K_pday
print KDJ_D_pday
print KDJ_J_pday
'''
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("KDJ", str(score) + ";" + signal, stock_code, date)
return [score, signal]