示例#1
0
文件: nn.py 项目: ralex1975/q-trader
def run_ensemble():
    global ds
    conf = p.conf
    # All In (from 0.5)
    # Strategy Return: 128611.19
    # Sortino Ratio: 8.35

    # Position Sizing (from 0)
    # Strategy Return: 71163.77
    # Sortino Ratio: 8.73

    d1 = runModel('ETHUSDNN1')
    d2 = runModel('ETHUSDNN1S')
    d3 = runModel('ETHUSDNN2')

    # Reloading config after previous models
    p.load_config(conf)

    d1 = d1[['date', 'open', 'high', 'low', 'close',
             'signal']].rename(columns={'signal': 'signal_1'})
    d2 = d2[['date', 'signal']].rename(columns={'signal': 'signal_2'})
    d3 = d3[['date', 'signal']].rename(columns={'signal': 'signal_3'})
    ds = pd.merge(d1, d2, on='date', how='left')
    ds = pd.merge(ds, d3, on='date', how='left')
    y_pred_val = (np.where(ds.signal_1 == 'Buy', 1, 0) + np.where(
        ds.signal_2 == 'Buy', 1, 0) + np.where(ds.signal_3 == 'Buy', 1, 0)) / 3

    ds = gen_signal(ds, y_pred_val)
    ds['size'] = ds['y_pred_val']
    td = bt.run_backtest(ds, conf)

    return td
示例#2
0
文件: nn.py 项目: ralex1975/q-trader
def runModel(conf):
    global td

    p.load_config(conf)
    td = globals()[p.model_type]()
    print(str(get_signal_str(td=td)))

    return td
示例#3
0
def init(conf):
    global actions
    global tl
    global qt

    p.load_config(conf)

    qt = init_q()  # Initialise Model
    actions = pd.DataFrame(np.linspace(-1 if p.short else 0, 1, p.actions))
    if os.path.isfile(p.tl):
        tl = pickle.load(open(p.tl, "rb"))
    else:
        tl = t.TradeLog()
示例#4
0
文件: bot.py 项目: dxcv/q-trader
def test_execute():
    conf = 'ETHUSDNN'
    p.load_config(conf)
    s = get_signal(conf)
    p.order_size = 0.02
    s = {}
    s['action'] = 'Buy'
    s['new_trade'] = False
    s['sl'] = False
    s['tp'] = False
    s['sl_price'] = 100
    s['tp_price'] = 200

    execute(s)
示例#5
0
def test_order2():
    p.load_config('ETHUSDNN')

    # Create Market Order
    ex.createOrder('ETH/USD', 'market', 'buy', 0.02)
    ex.createOrder('ETH/USD', 'market', 'sell', 0.02)
    ex.createOrder('ETH/USD', 'market', 'buy', 0.02, 0)  # Price is ignored

    # Create Limit Order for fixed price
    ex.createOrder('ETH/USD', 'limit', 'buy', 0.02, 100)
    # Create Limit Order for -1% to market price
    ex.createOrder('ETH/USD', 'limit', 'buy', 0.02, 0, {'price': '-1%'})

    # Fetch Open Orders
    orders = ex.fetchOpenOrders()
    # Order Size
    orders[0]['amount']

    ex.fetchBalance()['ETH']
示例#6
0
def test_order1():
    p.load_config('ETHUSDNN')
    p.order_size = 0.02
    # Print available API methods
    print(dir(ex))

    # Buy
    ex.fetch_balance()['free']
    # Close SL Order
    cancel_orders()

    ex.fetchOpenOrders()

    ex.fetchClosedOrders('ETH/USD')

    # Get Open Positions
    ex.privatePostOpenPositions()

    # Limit Order with current price
    create_order('Buy', 'limit', 0.02, {'price': '+0%'})

    ex.createOrder('ETH/USD', 'market', 'buy', 0.02)
示例#7
0
def test_order3():
    p.load_config('ETHUSDNN')
    p.order_size = 0.02
    p.order_wait = 10
    open_position('Buy')
    print(get_balance())

    res = take_profit('Buy', 200)
    res = stop_loss('Buy', 100)
    res = close_position('Buy', wait=False)
    get_balance('ETH')
    ex.fetchOpenOrders()
    cancel_sl()
    cancel_tp()
    cancel_orders()
    get_price()

    res = ex.privatePostOpenPositions()
    len(res['result'])
    open_position('Sell')
    close_position('Sell', wait=False)
    ex.fetchOpenOrders()
    get_price()
    create_order('buy', 10, 215.19, 'stop-loss', 1, False)
示例#8
0
文件: nn.py 项目: dxcv/q-trader
def runModel(conf):
    p.load_config(conf)
    globals()[p.model_type]()
示例#9
0
def load_ticker(ticker):
    p.load_config('ETHUSDNN')
    p.ticker = ticker
    ds = load_data_cc()
    ds.to_csv('./data/' + ticker + '.csv')
示例#10
0
def loglog():
    p.load_config('ETHUSDNN')
    p.datasource = 'cc'
    ds = load_data()
    ds['days'] = ds.date - ds.date.iloc[0]
    ds.plot(x='days', y='close', loglog=True)
示例#11
0
    tsret.loc[tsret['Today'].abs() < 0.0001, ['Today']] = 0.0001

    # Create the lagged percentage returns columns
    for i in range(0, lags):
        tsret['Lag%s' % str(i+1)] = \
            tslag['Lag%s' % str(i+1)].pct_change() * 100.0

    # Create the "Direction" column (+1 or -1) indicating an up/down day
    tsret['Direction'] = np.sign(tsret['Today'])
    tsret = tsret.dropna()

    return tsret


if __name__ == '__main__':
    p.load_config('ETHUSDNN')
    p.datasource = 'cc'
    p.signal_threshold = 0

    ts = dl.load_data().set_index('date')
    ts['date'] = ts.index

    ds = create_lagged_series(ts, lags=5)

    # Use the prior two days of returns as predictor
    # values, with direction as the response
    X = ds[['Lag1', 'Lag2']]
    y = ds['Direction']

    # The test data is split into two parts: Before and after 1st Jan 2017.
    start_test = dt(2019, 1, 1)