本文整理汇总了Python中BasicData.getStockDate方法的典型用法代码示例。如果您正苦于以下问题:Python BasicData.getStockDate方法的具体用法?Python BasicData.getStockDate怎么用?Python BasicData.getStockDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BasicData
的用法示例。
在下文中一共展示了BasicData.getStockDate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calcROC
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
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)
示例2: analyze
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
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]
示例3: calcAMA
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
def calcAMA(stock_code, date, period1, period2, period3):
AMA = calcDMA(stock_code, date, period2, period3)
# print AMA
for i in range(1, period1):
next_date = bd.getStockDate(stock_code, date, i)
# print next_date + " " + str(calcDMA(stock_code, next_date, period2, period3))
AMA += calcDMA(stock_code, next_date, period2, period3)
AMA = AMA / period1
return round(AMA, 3)
示例4: calcTRIX
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
def calcTRIX(stock_code, date, period):
global ITERATOR_COUNT
TR = calcEMA(stock_code, date, period)
pday = du.convertDateToString(bd.getStockDate(stock_code, date, 1), "%Y-%m-%d")
ITERATOR_COUNT = 0
TR_pday = calcEMA(stock_code, pday, period)
print TR
print pday
print TR_pday
return (TR - TR_pday) / TR_pday * 100
示例5: getROCEMAs
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
def getROCEMAs(stock_code, date, period):
ROCEMAs = []
count = 0
last_day = date
while count < period:
ROCEMA = calcROCEMA(stock_code, last_day, ROCEMA_PARAM)
#print last_day + " " + str(ROCEMA)
count += 1
last_day = bd.getStockDate(stock_code, last_day, 1)
ROCEMAs.append(ROCEMA)
return ROCEMAs
示例6: analyze
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
def analyze(stock_code, date, period):
score = 0.0
signal = ""
pday = bd.getStockDate(stock_code, date, 1)
CCI = getCCI(stock_code, date)
CCI_pday = getCCI(stock_code, pday)
CCIs = getCCIs(stock_code, date, period)
CCI_K1 = mu.getPoly(CCIs, 1)[0]
CCI_K2 = mu.getPoly(CCIs, 2)[0]
print CCI
print CCI_pday
print CCIs
print CCI_K1
print CCI_K2
if CCI > 100:
score -= 0.5
signal += "[-0.5]当CCI>﹢100时,表明股价已经进入非常态区间—超买区间;"
if CCI_K1 > 0:
score += 1
signal += "[1]CCI曲线向上突破﹢100线而进入非常态区间后,只要CCI曲线一直朝上运行,就表明股价强势依旧,中短线应及时买入,如果有比较大的成交量配合,买入信号则更为可靠;"
if CCI_K2 < 0 and (CCI -100) >= CCI_THREHOLD:
score -= 1
signal += "[-1]当CCI曲线在﹢100线以上的非常态区间,在远离﹢100线的地方开始掉头向下时,表明股价的强势状态将难以维持,是股价比较强的转势信号。如果前期的短期涨幅过高时,更可确认。此时,投资者应及时逢高卖出股票;"
if CCI < -100:
score += 0.5
signal += "[0.5]当CCI<﹣100时,表明股价已经进入另一个非常态区间—超卖区间;"
if CCI_K1 < 0:
score -= 1
signal += "[-1]当CCI曲线向下突破﹣100线而进入另一个非常态区间后,只要CCI曲线一路朝下运行,就表明股价弱势依旧,投资者可一路观望;"
if CCI_K2 > 0:
score += 0.5
signal += "[0.5]当CCI曲线向下突破﹣100线而进入另一个非常态区间,如果CCI曲线在超卖区运行了相当长的一段时间后开始掉头向上,表明股价的短期底部初步找到,投资者可少量建仓。CCI曲线在超卖区运行的时间越长,越可以确认短期的底部;"
if CCI_pday >= 100 and CCI < 100:
score -= 1
signal += "[-1]当CCI指标从上向下突破﹢100线而重新进入常态区间时,表明股价的上涨阶段可能结束,将进入一个比较长时间的盘整阶段。投资者应及时逢高卖出股票;"
if CCI_pday <= -100 and CCI > -100:
score += 0.5
signal += "[0.5]当CCI指标从下向上突破﹣100线而重新进入常态区间时,表明股价的探底阶段可能结束,又将进入一个盘整阶段。投资者可以逢低少量买入股票;"
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("CCI", str(score) + ";" + signal, stock_code, date)
return [score, signal]
示例7: calcEMA
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
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)
示例8: calcAverageLoss
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
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)
示例9: calcAverageGain
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
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)
示例10: calcOBV
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
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)
示例11: analyze
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
def analyze(stock_code, date, period):
score = 0
signal = ""
pday = bd.getStockDate(stock_code, date, 1)
ROC = getROC(stock_code, date)
ROCMA = calcROCMA(stock_code, date, ROCMA_PARAM)
ROCEMA = calcROCEMA(stock_code, date, ROCEMA_PARAM)
ROC_pday = getROC(stock_code, pday)
ROCMA_pday = calcROCMA(stock_code, pday, ROCMA_PARAM)
ROCEMA_pday = calcROCEMA(stock_code, pday, ROCEMA_PARAM)
ROCs = getROCs(stock_code, date, period)
ROCMAs = getROCMAs(stock_code, date, period)
ROCEMAs = getROCEMAs(stock_code, date, period)
ROC_K = mu.getPoly(ROCs, 1)[0]
ROCMA_K = mu.getPoly(ROCMAs, 1)[0]
ROCEMA_K = mu.getPoly(ROCEMAs, 1)[0]
if ROC < 0 and ROCEMA < 0 and ROCMA < 0:
if ROC > ROC_pday:
if ROC > ROCEMA and ROC > ROCEMA and ROC_pday < ROCEMA_pday and ROC_pday < ROCMA_pday:
if (ROC - ROC_pday)/ROC_pday >= ROC_RAISE_RATE and (ROCMA - ROCMA_pday)/ROCMA_pday >= ROCMA_RAISE_RATE \
and (ROCEMA - ROCEMA_pday)/ROCEMA_pday >= ROCEMA_RAISE_RATE:
score += 1
signal += "[1]当ROC,ROCMA,ROCEMA三条线均小于零轴时,ROC迅速同时上穿ROCMA和ROCEMA两条线,而且ROCMA和ROCEMA两条线也处于缓缓上行中,为短线黑马买入信号;"
if ROC > ROCMA > ROCEMA and ROC_K > ROCMA_K > ROCEMA_K:
score += 1
signal += "[1]当ROC,ROCMA,ROCEMA三条线是处于多头排列中,成交量处于间隙式放大或温和放大过程时,表明股价正运行于上升趋势中,仍有继续上涨趋势;"
if ROC < ROCMA < ROCEMA and ROC_K < ROCMA_K < ROCEMA_K:
score -= 1
signal += "[-1]当ROC,ROCMA,ROCEMA三条线是处于空头排列中,表明股价正运行于下行趋势中,仍有继续下跌趋势;"
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("ROC", str(score) + ";" + signal, stock_code, date)
return [score, signal]
示例12:
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
import BasicData as fd
from datetime import *
import DateUtil as du
import ROC
# Main function
if __name__ == '__main__':
'''
start_date = datetime.strptime("2016-02-01", '%Y-%m-%d')
end_date = date.today()
stocks = fd.getStocks(True)
print stocks
print "**********************************"
stocks = fd.getStocks(False)
print stocks
print "**********************************"
index = fd.getBasicData("0000001", start_date, end_date)
print index
print "**********************************"
rf = fd.getRecoveryFactor("0600079", "600079", start_date)
print rf
print "**********************************"
resultSet = ROC.getROC("000001", "2015-12-21")
print resultSet[0][0]
'''
print du.convertDateToString(fd.getStockDate("000001", "2015-12-21", 1)[0][0], "%Y-%m-%d")
示例13: calcROCEMA
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
def calcROCEMA(stock_code, date, period):
pday = bd.getStockDate(stock_code, date, 1)
ROC_today = getROC(stock_code, date)
ROC_pday = getROC(stock_code, pday)
ROCEMA = (2 * ROC_today + (period - 1) * ROC_pday) / (period + 1)
return round(ROCEMA, 3)
示例14: analyze
# 需要导入模块: import BasicData [as 别名]
# 或者: from BasicData import getStockDate [as 别名]
def analyze(stock_code, date, period):
score = 0.0
signal = ""
DMA = getDMA(stock_code, date)
AMA = getAMA(stock_code, date)
DMAs = getDMAs(stock_code, date, period)
AMAs = getAMAs(stock_code, date, period)
DMA_K1 = mu.getPoly(DMAs, 1)[0]
AMA_K1 = mu.getPoly(AMAs, 1)[0]
DMA_K2 = mu.getPoly(DMAs, 2)[0]
AMA_K2 = mu.getPoly(AMAs, 2)[0]
#1. DMA和AMA的值及线的运动方向
if AMA > 0 and DMA > 0 and AMA_K1 > 0 and DMA_K1 > 0:
score += 1
signal += "[1]当DMA和AMA均大于0,并向上移动时,一般表示为股市处于多头行情中,可以买入或持股;"
if AMA < 0 and DMA < 0 and AMA_K1 < 0 and DMA_K1 < 0:
score -= 1
signal += "[-1]当DMA和AMA均小于0, 并向下移动时,一般表示为股市处于空头行情中,可以卖出股票或观望;"
if AMA > 0 and DMA > 0 and AMA_K2 > 0 and DMA_K2 > 0:
score -= 1
signal += "[-1]当DMA和AMA均大于0,但在经过一段比较长时间的向上运动后,如果两者同时从高位向下移动时,一般表示为股票行情处于退潮阶段,股票将下跌,可以卖出股票和观望;"
if AMA < 0 and DMA < 0 and AMA_K1 < 0 and DMA_K1 < 0:
score += 1
signal += "[1]当DMA和AMA均小于0时,但在经过一段比较长时间的的向下运动后,如果两者同时从低位向上移动时,一般表示为短期行情即将启动,股票将上涨,可以短期买进股票或持股待涨;"
close_in_period = bd.getBasicDataInPeriod("CLOSE_TODAY",stock_code, date, period)
volumn_in_period = bd.getBasicDataInPeriod("VOLUMN", stock_code, date, period)
close_K1 = mu.getPoly(close_in_period, 1)[0]
volumn_K1 = mu.getPoly(volumn_in_period, 1)[0]
#2. DMA曲线和股价曲线的配合使用
if AMA < 0 and DMA < 0 and AMA_K1 > 0 and DMA_K1 > 0 and close_in_period > 0:
score += 1
signal += "[1]当DMA曲线与股价曲线从低位同步上升,表明空头力量已经衰弱、多头力量开始积聚,短期内股价有望止跌企稳,投资者应可以开始少量逢低买入;"
if -1 <= AMA <= 1 and -1 <= DMA <= 1 and AMA_K1 > 0 and DMA_K1 > 0 and volumn_K1 > 0:
score += 1
signal += "[1]当DMA曲线与股价曲线从0值附近向上攀升时,表明多头力量开始大于空头力量,股价将在成交量的配合下,走出一波向上扬升的上涨行情。此时,投资者应逢低买入或坚决持股待涨;"
pday = bd.getStockDate(stock_code, date, 1)
DMA_pday = getDMA(stock_code, pday)
AMA_pday = getAMA(stock_code, pday)
#3. DMA线和AMA线的几次交叉情况
if close_K1 < 0 and DMA_pday < AMA_pday and DMA > AMA:
score += 1
signal += "[1]当股价经过一段很长时间的下跌行情后,DMA线开始向上突破AMA线时,表明股市即将转强,股价跌势已经结束,将止跌朝上,可以开始买进股票,进行中长线建仓;"
if close_K1 > 0 and DMA_pday > AMA_pday and DMA < AMA:
score -= 1
signal += "[-1]当股价经过前期一段很长时间的上升行情后,股价涨幅已经很大的情况下,一旦DMA线向下突破AMA时,表明股市即将由强势转为弱势,股价将大跌,这时应卖出大部分股票而不能买股票;"
print DMA
print DMA_pday
print AMA
print AMA_pday
print score
print signal.decode("utf-8").encode("gbk")
bd.updateAnalysisData("DMA", str(score) + ";" + signal, stock_code, date)
return [score, signal]