Book extra1 has two parameters, book (the order book), and size, which is an integer size between 1 and M, where M is the total volume in the ask book (you can assume that your function will only be tested on such values of size). The function should return the expected value of the midprice after execution of a buy limit order with size size and price drawn uniformly at random from the set of prices in book$ask.
Book extra2 has exactly the same two parameters as book.extra1. The function should return the expected value of the midprice after execution of a buy limit order with size size and price drawn uniformly at random from the integer prices (the tick size is 1) between the best ask price and the highest ask price in the book. For the first 2 extra problems, if size is equal to M then the correct answer is NA.Book extra3 only takes book as an argument. The function should return the expected value of the midprice after execution of a buy market order with size s is executed, assuming that is drawn uniformly at random from the set {1,....,(M-1)}, where M is the total volume in the ask book. For first 3 extra problems, one unified approach is to simulate the relevant orders
using functions that you implemented for book.reconstruct.
Book extra3 has two parameters, book (the order book), and k a non-negative number that will be interpreted as a percentage, e.g., if k=0.4 then k corresponds to 0.4%. The function should return: 0 if the ask book has no orders in it; otherwise the largest amount of buy volume v such that a buy market order with size v causes the mid-price to increase by no more than k % (so an order with size v+1 would either cause the midprice to increase by more than k % or would leave no asks left in the book which means that the mid-price is NA).
Â
The return value should be an integer between 0 and the total ask volume in book. For all 4 extra problems, to increase the chance that your implementations are correct, do one or two examples where you compute the correct expectation by hand on and then check that your code produces the correct answer.