Ejemplo n.º 1
0
def examine(lines, pic_kind):
    resolve = [-36, -5, 97, 44, -24]
    length, same, deltaes,days,opens,actuals,expecteds = 0, 0, [],[],[],[],[]
    for line in lines:
        record = History.get_from_historyline(line)
	record = History.norm(record)
	expected = get_expected(resolve, record)
	actual = record.closed_today 
	delta = expected - actual
	deltaes.append(delta)
	days.append(record.day)
	opens.append(record.open_price)
	actuals.append(actual)
	expecteds.append(expected)
	print 'open: %s,actual: %s, expected: %s, delta: %s' % (record.open_price, actual, expected, delta)

	if (expected - record.open_price) * (actual - record.open_price) > 0:
	    same += 1
	length += 1
    print 'direction_same: %d, length: %d, direction_same/length: %s' % (same, length, float(same)/length)
    x = [ i + 1 for i in range(len(opens))]
    if pic_kind == 'delta':
        pydrawer.draw(x, deltaes, 'bo')
    if pic_kind == 'lines':
        pydrawer.draw(x, opens,'k', x, actuals,'r-', x, expecteds,'bo')
Ejemplo n.º 2
0
def anneal_reducer(lines):
    # 开盘价, 昨结算, 最高价, 最低价
    domain = [(-100, 100), (-100, 100), (-100, 100), (-100, 100), (-2000, 2000)]
    records = set()
    for line in lines:
        history_record = History.get_from_historyline(line)
	history_record = History.norm(history_record)
	records.add(history_record)

    while(True):
        best_cost, best_resolve = optimizations.annealing(domain, get_best_solution(records))
	ave_cost = best_cost / len(records)
	if ave_cost < 3000:
            print 'best_cost: %s, best_resolve: %s, best_ave_cost: %f' % (best_cost, best_resolve, ave_cost)
	    if ave_cost < 1000:
	        break
Ejemplo n.º 3
0
def random_reducer(lines):
    # 开盘价, 昨结算, 最高价, 最低价, 加权平均价, 成交量(千克)持仓量 
#    domain = [(-100, 100), (-100, 100), (-100, 100), (-100, 100), (-100, 100), (-100, 100), (-100, 100), (-2000, 2000)]
    domain = [(-100, 100), (-100, 100), (-100, 100), (-100, 100), (-2000, 2000)]
    records = set()
    for line in lines:
        history_record = History.get_from_historyline(line)
	history_record = History.norm(history_record)
	records.add(history_record)

    best_cost,best_resolve = sys.maxint, None
    for i in range(20):
        cost, resolve = optimizations.randomoptimize(domain, get_best_solution(records))
#        cost, resolve = optimizations.hill_climb(domain, get_best_solution(records))
        print 'i: %s, cost: %s, resolve: %s, ave_cost: %f' % (i, cost, resolve, cost / len(records))
	if cost < best_cost:
	    best_cost = cost 
	    best_resolve = resolve
	# goal: daily_cost <= sqrt(100)
	if best_cost <= len(records) * 100:
	    break
    print 'best_cost: %s, best_resolve: %s, best_ave_cost: %f' % (best_cost, best_resolve, best_cost / len(records))