def eval_predict(prices, checkpoints, bars_later, expect): result = list() for N in checkpoints: if prices[N + bars_later] >= prices[N] * expect: result.append(1) else: result.append(0) return result
def find_new_high(granularity, range_down, range_up, bars, correction_bars, exchange): pairs = read_coin_pair(granularity, exchange) result = list() for fsym, tsym in pairs: X = get_X(fsym, tsym, granularity, exchange) highs = get_high(X) h = REF(highs, 1) hh = HHV(highs[1:], bars) hhb = HHVBARS(highs[1:], bars) if (h >= hh * range_down) & (h <= hh * range_up) & (hhb > correction_bars): result.append([fsym, tsym, hh, h]) return np.array(result)
def parsePageUrl (self,page): soup = BeautifulSoup(page) print "title==>",soup.title.string if "登录中心 - 支付宝" in soup.title.string: return False hrefs = soup.find_all('td', {'class': "detail-link"})# #hrefs = soup.find_all('a', {'seed': re.compile('detailLink-linkT*')}) print "==>",hrefs result = [] for href in hrefs: result.append(href.find("a")['href']) print "-->",href,"===",href.find("a"),"---",href.find("a")['href'] return result
def dowith(): result=[] csvfile=file('E:\\编程\\数字\\llll.csv','rb') reader=csv.reader(csvfile) csvfile = file('E:\\编程\\数字\\lllll.csv', 'wb') writer = csv.writer(csvfile) i=1 for line in reader: result.append((i,line[0][0])) i=i+1 writer.writerows(result)
def showAllRegistryTag(registry_ip,registry_port): try: r=requests.get('http://'+registry_ip+":"+registry_port+"/v1/search?q=",timeout=5) if r.status_code==200: result=[] re=r.json() repos=re['results'] for repo in repos: r=requests.get('http://'+registry_ip+":"+registry_port+"/v1/repositories/"+repo['name']+"/tags",timeout=5) re=r.json() for k,v in re.items(): t={} t['name']=repo['name'] t['tag']=k t['image_id']=v result.append(t) return result except Exception: return
def macd_crossover(close, fast, slow, signal): result = list() close = np.array([float(i) for i in close]) macd, macdsignal, macdhist = talib.MACD(close, fastperiod=fast, slowperiod=slow, signalperiod=signal) if (len(macdhist)) >= (slow + signal - 1): #ensure macdhist is mature enough for N in range(len(macdhist) - 1): if (macdhist[N + 1] >= 0) & (macdhist[N] < 0): result.append(N) # result.append((N,'gold')) # elif (macdhist[-(N+2)] >= 0) & (macdhist[-(N+1)] < 0): # result.append((N,'dead')) return result
def showAllRegistryTag(registry_ip, registry_port): try: r = requests.get('http://' + registry_ip + ":" + registry_port + "/v1/search?q=", timeout=5) if r.status_code == 200: result = [] re = r.json() repos = re['results'] for repo in repos: r = requests.get('http://' + registry_ip + ":" + registry_port + "/v1/repositories/" + repo['name'] + "/tags", timeout=5) re = r.json() for k, v in re.items(): t = {} t['name'] = repo['name'] t['tag'] = k t['image_id'] = v result.append(t) return result except Exception: return
def classify(train_images,test_images,num_list,n): train_images=changeImage(train_images) test_images=changeImage(test_images) train_images=numpy.array(train_images) test_images=numpy.array(test_images) result=[] listnum=0 for test_line in test_images: poor=train_images-test_line sqr=poor**2 sqDistance=sqr.sum(axis=1) distance=sqDistance**0.5 sortedDistIndicies=distance.argsort() classCount={} for i in range(n): index=num_list[sortedDistIndicies[i]] classCount[index]=classCount.get(index,0)+1 sortedClassCount=sorted(classCount.iteritems(),key=operator.itemgetter(1),reverse=True) result.append([sortedClassCount[0][0]]) print listnum,':\n' print sortedClassCount[0][0] print '\n' listnum+=1 return result