jMarkets Developer Guide
Table of Contents
How to add a new Payoff Function
Note: While there are 6 different payoff functions in version 1.5 and higher, you should pay attention to only one, namely, GenericPayoffFunction. StockBondPayoff function was used for testing purposes. However, all 5 are specific cases of GenericPayoffFunction, so you better ignore them or study the code to understand how they work.
Generic Payoff Function
GenericPayoffFunction allows you to specify the end-of-period payoff for each of the securities available for trade during a period. You provide the per-unit payoff when configuring the experiment. End-of-period earnings will then be computed as number of units held at the end of the period times per-unit payoff, summed over all securities.
Your experiment may involve risky securities, i.e., securities whose payoff are not known to all subjects with certainty until after the end of trading. To implement such a situation, you need to draw the payoffs before the experiment and enter them in the GenericPayoffFunction. Again, it should not be too difficult to change the GenericPayoffFunction to draw payoffs when the function is called by jMarkets.
Implementing new Payoff Function
GenericPayoffFunction will not allow you to compute end-of-period earnings as a nonlinear function of end-of-period holdings of a basket of securities. For those who has a basic understanding of object-oriented programming and knows the syntax of JAVA language, however, it should be straightforward to add a payoff function to jMarkets that implements nonlinear payoffs. New Payoff functions should implement the PayoffFunction interface and be placed in the edu/caltechUcla/sselCassel/projects/jMarkets/shared/functions/ package. The jMarkets server will dynamically discover the new class at runtime using JAVA reflection API.
How to add a new Bankruptcy Function
Note: While there are 4 different bankruptcy functions in version 1.5 and higher, you should pay attention to only one, namely, GenericBankruptcyFunction and GenericLtdBankruptcyFunction. StockBond was used for testing purposes and is a specific case of GenericBankruptcyFunction.
Generic Bankruptcy Function
GenericBankruptcyFunction allows you to bar orders from being sent to the market which subjects cannot deliver upon in certain circumstances or "states of the world." For each possible state of the world (the number of states is to be specified when configuring the experiment), the program computes the net earnings that the subject would receive if the proposed and all submitted orders were to be executed. For the program to be able to do so, the experimenter needs to specify, during configuration, the unit payoff of each of the securities in each of the states of the world. Net earnings are computed as in the GenericPayoffFunction. If in some state of the world, net losses (minus net earnings) would be more than bankruptcy_cutoff (also to be declared during configuration), the order is automatically canceled and the subject receives a message to that effect.
Generic Limited Bankruptcy Function
GenericLtdBankruptcy function is a slightly more 'relaxed' or 'limited', depending on one's standing orders, bankruptcy constraint implementation as compared to GeneralBankruptcyFunction. It works as follows. Instead of taking into account of all standing orders like in GeneralBankruptcy, only orders within 25% of the best order on either side of the market are chosen to compute the bankruptcy state. More specifically:
- Bid side: if a standing bid is less than 0.75*(price level of the highest bid order in the market) then ignore it.
- Sell side: if a standing ask is more than 1.25*(price level of the lowest ask order in the market) then ignore it.
Implementing new Bankruptcy Function
GenericBankruptcyFunction will not allow you to compute end-of-period earnings as a nonlinear function of holdings upon execution of proposed and already submitted orders. For those who has a basic understanding of object-oriented programming and knows the syntax of JAVA language, however, it should be straightforward to add a payoff function to jMarkets that implements nonlinear payoffs. New Bankruptcy functions should implement the BankruptcyFunction interface and be placed in the edu/caltechUcla/sselCassel/projects/jMarkets/shared/functions/ package. The jMarkets server will dynamically discover the new class at runtime using JAVA reflection API.
