Thursday, October 27, 2016

Enclose is the new insert

Here is the code that maintains the block structure  .  All inserts, edxcept the root node, are all 'enclose'.  self encloses subgraph new.

# self prepends the new block
 def enclose(self,new) : #
  i = G.top.traverse(0,UpdateFun,dict(target=self,offset=new.count,func="Update"))

  k = self.traverse(i,IsEqualFun,dict(target=new,func="IsEqual")) # locate the new block
  G.MOVE(i+1,k,new.count) 
  self.count = self.count + new.count

Note the use of recursive descent to scoff graph indices.  It is efficient because one pass down the graph from the top to the enclosed block. Start fro the top until you find self, accumulates indices, then from that point, find the index of new, so one pass in two pats.

Will this work on a massive scale.  Well, it is optimized for wealthy trades trade that happen from the top of the graph down.  Those critical trades can flood in times of stress.

The general procedure is that new trades are appended to the array,enclose by the root, so initially you have one huge subgraph as the first block in the root, and this tiny trade at the end.  From then on the graph site bot will be doing the bubble sort, moving the trade up, with successive call to enclose.. Tiny trades do not bubble far, the bot is bubbling up and checking imbalance at any node, it it is out of variance, another bubble up is required.  Large trades which impact the market will bubble up higher and higher, making the site bot spend  more and more graph cycles.

That is the solvable issue we face. The solutions involve short cuts, leaps down the array, driven because the block counts are accurate, recurse can make the jump, how well it jumps depends on thei mix of bots running the graph.

Queuing on the graph keeps the balance

Bots know the published rules,n the site owner runs under the rule that the graph cannot get more than 5% put of balance.  Any bot can scan the graph and get a measure of imbalance, and determine it time on the net, figure out the queue length.  The longer the queue the more uncertain the trade.  Risk management is automatic, the red/green light, and risk management will maintain the queue, or the site manager will get rich.

No comments: