Skip to content

Instantly share code, notes, and snippets.

@GerardBCN
Created April 22, 2019 19:02
Show Gist options
  • Save GerardBCN/3bd78cd4952808a7e081e79095ef21d7 to your computer and use it in GitHub Desktop.
Save GerardBCN/3bd78cd4952808a7e081e79095ef21d7 to your computer and use it in GitHub Desktop.
Tickbar generator
# expects a numpy array with trades
# each trade is composed of: [time, price, quantity]
def generate_tickbars(ticks, frequency=1000):
times = ticks[:,0]
prices = ticks[:,1]
volumes = ticks[:,2]
res = np.zeros(shape=(len(range(frequency, len(prices), frequency)), 6))
it = 0
for i in range(frequency, len(prices), frequency):
res[it][0] = times[i-1] # time
res[it][1] = prices[i-frequency] # open
res[it][2] = np.max(prices[i-frequency:i]) # high
res[it][3] = np.min(prices[i-frequency:i]) # low
res[it][4] = prices[i-1] # close
res[it][5] = np.sum(volumes[i-frequency:i]) # volume
it += 1
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment