davecliff/BristolStockExchange

corner case in the ZIC agent

Closed this issue · 9 comments

vd1 commented

If I understand correctly this line
quoteprice = random.randint(minprice, limit)
the ZIC agent will place a new bid uniformly at random between the current minimum bid and the limit bid.
But what if the limit is < min-price? (NB: such an order makes sense if the trader expects the price to go down)

randint will throw an error in this case.

That would be a problem in principle, but the rest of the code is written in such a way that it is never intended to happen.

Look at the wider context for that line in ZIC:

    else:
        minprice = lob['bids']['worst']
        maxprice = lob['asks']['worst']
        qid = lob['QID']
        limit = self.orders[0].price
        otype = self.orders[0].otype
        if otype == 'Bid':
            quoteprice = random.randint(minprice, limit)
        else:
            quoteprice = random.randint(limit, maxprice)

When quoteprice = random.randint(minprice, limit) executes, the value of minprice has just (6 lines of code earlier) been set to lob['bids']['worst'], the worst possible bid price (i.e., no bid can ever be lower than that) and that was previously set to bse_sys_minprice when the lob is initialised.

The only way you'd get an error thrown in this bit of code would be if the limit price was lower than the worst price the system allows, which would make it a zero or negative multiple of the tick-size, which would not make much sense from the perspective of the kind of market economics that it's been built to explore -- this code is intended to be used with the various parameters set to reasonable values; it's not intended to be bomb-proof against parameter value set wildly out of expectation.

vd1 commented

I see. I thought lob['bids']['worst'] was returning the current lowest bid. Which means I have misunderstood ZIC itself!

Aha, no worries.

Last week I put a paper on Arxiv that might help: [https://arxiv.org/pdf/2103.11341.pdf]

vd1 commented

Just read the PRZI paper, it is great! Thanks.

Thank you! Glad you enjoyed it. PRZI is in BSE.py -- it was updated a few days ago.

vd1 commented

BSE seems directed primarily at modelling intermediaries relaying a flow of exogenous orders and trying to sell/buy a bit above/below to pocket the difference. What about other classes of agents: 1) directional traders who originate their own orders, 2) market-makers who put offers on both sides and cycle their inventory, 3) other agent types that trade to increase liquidity under a budget. Do you think one can use BSE to run those as well. For 1) the agent code should make a decision about the price with no external input (other than the lob): I guess one could start random and then try to follow the price process. For 2) a market making agent should adjust his/her offers on both sides (at every match?) in relation to its inventory so when the simulator calls the respond() method. It is like a double-sided agent.

BSE seems directed primarily at modelling intermediaries relaying a flow of exogenous orders and trying to sell/buy a bit above/below to pocket the difference.

Yep, exactly that. That approach is commonplace in Experimental Economics research, which is what BSE started out as a tool for the teaching of.

At UoB we've used BSE in classes of 70-120 students where the programming coursework has been something very close to create an agent that is in what you refer to as your classes (1) to (3). Fundamentally the exchange side of BSE allows any kind of trader-agent to send it orders, so the question then is just down to how sophisticated you want the trader-agents to be. One year (2012? 2013? I can't remember) we got students to do exactly (2), i.e. build a market-maker.; and we repeated pretty-much the same assessment when we ran the course again this year -- setting that particular problem once every seven or eight years seems safe enough.

Aha, just checked: it was 2014. Here is the hints-and-tips doc that I made after some students said they were struggling with creating a market-maker. ..

HintsTipsCourseworkOptionB.pdf

vd1 commented

Splendid!