예제 #1
0
 def realtime_trading_example():
     '''
     海知平台实盘模拟样例
     :return:
     '''
     engine = Engine(user_name='海知平台测试接口样例',
                     password='******',
                     core='HaiZhi',
                     type='RealTimeTrading',
                     initial_money=1000000)
     # 运行实盘模拟引擎的策略
     engine.run_stratagy(double_ma)
예제 #2
0
    def other():
        #import matplotlib.pyplot as plt
        engine = Engine(user_name='海知平台测试接口样例',
                        password='******',
                        core = 'HaiZhi',
                        type = 'HistoryTrading',
                        initial_time='2018-06-4',
                        end_date='2018-1-5',
                        initial_money=1000000,)

        print engine.context.current_time  
        print engine.buy('000001',1000)
        print engine._core.history_to_csv('records')
예제 #3
0
    def history_trading_example():
        '''
        海知平台历史回测样例
        :return:
        '''
        #初始化回测引擎
        engine = Engine(user_name='海知平台测试接口样例',
                        password='******',
                        #core = 'HaiZhi',
                        #type = 'HistoryTrading',
                        initial_time='2017-01-03',
                        #end_date='2018-1-5',
                        initial_money = 1000000)
        #运行回测引擎的策略
        #print engine.buy('600000',1000)
        engine.run_stratagy(test)

        print engine._core.history_to_csv()
예제 #4
0
    def other():
        #数据准备
        engine = Engine(
            user_name='海知平台测试接口样例',
            password='******',
            #core = 'HaiZhi',
            #type = 'HistoryTrading',
            initial_time='2017-07-01',
            #end_date='2018-1-5',
            initial_money=1000000)

        dm = engine.context.DataModule
        security = '601390'
        name = dm.stock_name(security)
        print engine.context.current_time
        shd = dm.stock_history_data(security)

        #显示数据
        import matplotlib.pyplot as plt
        from matplotlib.dates import YearLocator, MonthLocator, DateFormatter

        plt.rcParams['font.sans-serif'] = ['SimHei']
        plt.rcParams['axes.unicode_minus'] = False

        daysFmt = DateFormatter('%m-%d-%Y')

        fig = plt.figure()
        ax = fig.add_subplot(111)
        print len(shd)
        lma = [ma(shd[:date], 60) for date in shd.index]
        sma = [ma(shd[:date], 10) for date in shd.index]

        ax.plot_date(shd.index, lma, '-')
        ax.plot_date(shd.index, sma, '-')
        # format the ticks
        ax.xaxis.set_major_formatter(daysFmt)
        ax.autoscale_view()

        # format the coords message box
        def price(x):
            return '$%1.2f' % x

        ax.fmt_xdata = DateFormatter('%Y-%m-%d')
        ax.fmt_ydata = price
        ax.grid(True)

        fig.autofmt_xdate()
        print name
        plt.title(name)
        plt.show()
예제 #5
0
            dtw[i, j] = float('inf')

    dtw[0,0] = 0

    for i in range(1,len(x)+1):
        for j in range(1,len(y)+1):
            cost = distance(x[i-1],y[j-1])

            dtw[i,j] = cost+np.min([dtw[i-1,j],dtw[i,j-1],dtw[i-1,j-1]])
    return dtw[1:,1:]

if __name__=='__main__':
    engine = Engine(user_name='海知平台测试接口样例',
                    password='******',
                    core='HaiZhi',
                    type='HistoryTrading',
                    initial_time='2018-06-4',
                    end_date='2018-1-5',
                    initial_money=1000000, )

    dm = engine.context.DataModule

    x = dm.stock_history_data('000001')[:10]
    z = dm.stock_history_data('000002')[:10]
    y = dm.stock_history_data('000004')[:10]

    x = pd.Series(list(x['pct_change']), index=x.index)
    y = pd.Series(list(y['pct_change']), index=y.index)
    z = pd.Series(list(z['pct_change']), index=z.index)

    print x.corr(y)