예제 #1
0
def finished(db, start_date):
    print "finishing"
    for stock in db.get_stocks_list():        
        stock_code=stock.stock_code
        stock_name=stock.stock_name 
        stock_data=db.get_stock_data(stock_code, ['trade_date','open_price','high_price','low_price','close_price'])
        data_count=stock_data.count()
        if data_count:
             if stock_data[data_count-1]['trade_date'] != date.today():
                print "[%06d] data is old ignore" % stock_code, stock_data[data_count-1]['trade_date'].strftime('%Y-%m-%d')
                db.add_stock_gradient(stock_code, 0, 0, 0) 
                continue
             if data_count>20:
                data_count-=20
             else:
                data_count=0
             stock_data=map(lambda m:[m['high_price'], m['open_price'], m['close_price'], m['low_price']], list(stock_data[data_count:]))
             gradient,b,k=linear_trend(stock_data)
             db.add_stock_gradient(stock_code, gradient, b, k) 
        else:
             print "[%06d] data is empty" % stock_code
             db.add_stock_gradient(stock_code, 0, 0, 0) 
    update_post(db)
    ioloop.IOLoop.instance().stop()
예제 #2
0
 def test_linear_trend(self):
     data=[[4.09, 3.98, 4.07, 3.98], [4.19, 4.07, 4.16, 4.05], [4.23, 4.16, 4.16, 4.08], [4.25, 4.16, 4.2, 4.12], [4.45, 4.21, 4.35, 4.2], [4.33, 4.31, 4.28, 4.23], [4.3, 4.27, 4.15, 4.1], [4.18, 4.13, 4.17, 4.08], [4.2, 4.17, 4.03, 4.01], [4.05, 4.02, 4.03, 3.99], [4.09, 4.03, 4.08, 4.03], [4.13, 4.1, 4.12, 4.06], [4.12, 4.12, 4.09, 4.05], [4.13, 4.09, 4.1, 4.03], [4.12, 4.07, 4.09, 4.06], [4.11, 4.08, 4.04, 4.01], [4.09, 4.02, 4.08, 4.01], [4.1, 4.08, 4.1, 4.07], [4.1, 4.1, 4.07, 4.04], [4.13, 4.08, 4.11, 4.07], [4.28, 4.11, 4.17, 4.1], [4.2, 4.15, 4.15, 4.12], [4.25, 4.16, 4.23, 4.16], [4.28, 4.19, 4.17, 4.14], [4.22, 4.17, 4.16, 4.13], [4.21, 4.16, 4.21, 4.1], [4.26, 4.2, 4.13, 4.13], [4.23, 4.13, 4.2, 4.13], [4.33, 4.19, 4.32, 4.15], [4.34, 4.31, 4.32, 4.25], [4.65, 4.27, 4.39, 4.25], [4.57, 4.36, 4.46, 4.32], [4.63, 4.45, 4.54, 4.41], [4.53, 4.52, 4.41, 4.33], [4.48, 4.41, 4.37, 4.37], [4.81, 4.39, 4.81, 4.38], [5.29, 4.8, 5.28, 4.61], [5.47, 5.05, 5.25, 5.0], [5.3, 5.2, 5.06, 5.04], [5.13, 5.09, 4.99, 4.93], [5.45, 5.02, 5.22, 4.97], [5.3, 5.2, 5.04, 4.86], [5.34, 5.04, 5.28, 4.94], [5.48, 5.2, 5.21, 5.19], [5.37, 5.18, 5.19, 5.16], [5.63, 5.2, 5.39, 5.2], [5.48, 5.31, 5.39, 5.3], [5.47, 5.44, 5.25, 5.21], [5.25, 5.24, 5.24, 5.01], [5.27, 5.23, 5.21, 5.14], [5.22, 5.21, 5.19, 5.1], [5.26, 5.26, 5.12, 5.1], [5.2, 5.12, 5.17, 5.06], [5.32, 5.18, 5.27, 4.97], [5.53, 5.27, 4.96, 4.9], [4.95, 4.95, 4.72, 4.63], [4.8, 4.7, 4.64, 4.6], [4.66, 4.63, 4.6, 4.54], [4.79, 4.6, 4.77, 4.57]]
     (a,b,k) = LT.linear_trend(data[len(data)-20:])
     print a
     d2svg.to_image('test.svg',data[len(data)-20:],a,b,k)