Beispiel #1
0
 def if_buy(self, context):
     data = context.db.select_data_by_number(context.asset_code, 70,
                                             context.date)
     ohlc = OHLCVD(data)
     ohlc.add_ma(60)
     ohlc.add_ma(10)
     data_frame = ohlc.get_dataframe()
     ma60_value = data_frame.ma60.values[-1]
     low = data_frame.low.values[-1]
     price = data_frame.close.values[-1]
     # print 'ma60 value:', ma60_value
     # print "current price :", price
     rate = (ma60_value - low) / ma60_value
     # self.logger.info("ma60 value :" + str(ma60_value) + " current price "+
     #                  str(price)+" rate is :" + str(rate))
     # print "this is the rate of the ma60 minus low", rate
     if (ma60_value - low) / ma60_value >= 0.1:
         order = context.account.create_buy_order(name=context.asset_code,
                                                  price=price,
                                                  context=context)
         if order.number > 0:
             return order
         else:
             self.logger.info("can not create order")
             return None
     return None
Beispiel #2
0
 def if_buy(self, context):
     data = context.db.select_data_by_number(context.asset_code, 70,
                                             context.date)
     ohlc = OHLCVD(data)
     ohlc.add_ma(60)
     ohlc.add_ma(10)
     data_frame = ohlc.get_dataframe()
     ma60_value = data_frame.ma60.values[-1]
     low = data_frame.low.values[-1]
     price = data_frame.close.values[-1]
     # print 'ma60 value:', ma60_value
     # print "current price :", price
     rate = (ma60_value - low)/ma60_value
     # self.logger.info("ma60 value :" + str(ma60_value) + " current price "+
     #                  str(price)+" rate is :" + str(rate))
     # print "this is the rate of the ma60 minus low", rate
     if (ma60_value - low) / ma60_value >= 0.1:
         order = context.account.create_buy_order(name=context.asset_code,
                                                  price=price,
                                                  context=context
                                                  )
         if order.number > 0:
             return order
         else:
             self.logger.info("can not create order")
             return None
     return None
Beispiel #3
0
    def test_something(self):
        db = MySQLUtils('root', '1988', 'test', 'stock')
        data = db.get_array('sh600741', begin='2015-01-01', end='2016-01-01')
        ohlc = OHLCVD(data)
        ohlc.add_macd()
        ohlc.add_ma(10)
        ohlc.add_rsi_feature()
        ohlc.add_raise_day(5)
        ohlc.add_raise_day(10)
        ohlc.add_recent_down_v_turn()
        data = ohlc.get_array()

        print data.shape[1]
Beispiel #4
0
def prepare_data(db, stock_list, begin, end):
    results = []
    labels = []
    for stock in stock_list:
        tmp_result = db.get_array(stock, begin=begin, end=end)
        print stock
        if tmp_result.shape[0] > 100:
            ohlc = OHLCVD(data=tmp_result)
            ohlc.add_macd()
            ohlc.add_fall_days(5)
            ohlc.add_raise_day(5)
            ohlc.add_raise_day(3)
            ohlc.add_ma(60)
            # ohlc.add_rsi_feature()
            ohlc.add_jump_empty_down()
            ohlc.normalize()
            results.append(ohlc.data)
            label = ohlc.future_return(5)
            labels.append(label)
        print len(results)
        print len(labels)
    return results
Beispiel #5
0
def prepare_data(db, stock_list, begin, end):
    results = []
    labels = []
    for stock in stock_list:
        tmp_result = db.get_array(stock, begin=begin, end=end)
        print stock
        if tmp_result.shape[0] > 100:
            ohlc = OHLCVD(data=tmp_result)
            ohlc.add_macd()
            ohlc.add_fall_days(5)
            ohlc.add_raise_day(5)
            ohlc.add_raise_day(3)
            ohlc.add_ma(60)
            # ohlc.add_rsi_feature()
            ohlc.add_jump_empty_down()
            ohlc.normalize()
            results.append(ohlc.data)
            label = ohlc.future_return(5)
            labels.append(label)
        print len(results)
        print len(labels)
    return results
Beispiel #6
0
# coding=utf-8
__author__ = 'squall'
import numpy as np

from backtest.utils.mysql import MySQLUtils
from data.ohlc import OHLCVD

if __name__ == '__main__':
    db = MySQLUtils('root', '1988', 'stock', 'stock')
    result = db.get_array('sh600741', begin='2007-10-10', end='2015-12-12')
    ohlc = OHLCVD(data=result)
    print result
    print ohlc.get_dataframe()
    ohlc.add_macd()
    ohlc.add_ma(60)
    print ohlc.get_array().shape
    print ohlc.get_dataframe()
    vol_values = ohlc.data_frame.volume.values
    kernel = np.ones(20)*0.05
    result = np.convolve(kernel, vol_values, mode='valid')
    # plt.plot(result)
    # plt.show()