devalpha-io / devalpha-node

A stream-based approach to algorithmic trading and backtesting in Node.js
https://devalpha.io
GNU General Public License v3.0
246 stars 40 forks source link

Tick data #14

Open pabx06 opened 5 years ago

pabx06 commented 5 years ago

I see the example use Open high low and close. However i want to back test a hft algo on tick data with quote of bid and and also the book and order flow to ensure my orders get filled or not. Because if submit a limit buy order at the best bid and there is sell market order the buy never get executed ... howver the backtester might think i am long...

So question does devalpha support ticks data ??

fhqvst commented 5 years ago

Hm, I'm not 100% sure I understand what you mean. Are you saying that you want to place a buy order, and then, if at a later point a sell order at your price is placed, you want the order to be executed? I'm afraid this is currently not possible since the backtesting broker executes your order instantly.

DevAlpha has no notion of an order book, but you could model this yourself very easily. Maybe something like this could suffice?

// Holds pending orders
const orders = []

// Create DevAlpha trader
const trader = createTrader({ ... }, (context, action) => {

  if (action.type === 'myOrderbookFeed') {
    orders.forEach((order, index) => {
      if (order.quantity > 0 && action.payload.bestAsk <= order.price) {

        // Place DevAlpha order
        context.order({ ... })

        // Update pending orders
        orders = orders.filter((o, j) => j !== index)

      } else if (...) {
        // Do the same but for sell-side
      }
    })
  }

  if (action.type === 'myMagicSignal') {
    // Add to pending orders
    orders.push({ ... })
  }

});

// Run the thing
trader.resume()

Do you have an example of what you want to accomplish?

pabx06 commented 5 years ago

The notions of: -order book. -limit order -Cancel not filed limit order. Are missing that is too bad. It is very hard to find a back testing platform. Also the back-testing broker makes assumption that you always get a fill. While in real life it is a pain because of orders queuing ...

fhqvst commented 5 years ago

One nice thing about DevAlpha is that you're able to provide as many data sources as you like, and DevAlpha will emit each data point as if they were sorted by timestamp.

On the other hand, this flexibility means that DevAlpha does not know what type of data you feed it, so it does not know whether you feed tick data for a cryptocurrency or a time series of car sales for Toyota.

Regarding limit orders: They're currently the only supported order type, but as you say, during backtesting orders will always get filled instantly. I've added the order book feature to the icebox, and if there's enough need for it I'll make sure to implement it.