<<
>>

Appendix B

The JAVA Program of URandom Strategy

In order to be familiar with implementing a new strategy in the U-Mart, we need to construct a java program for a particular strategy. Here we merely demonstrate the URandom strategy.[85] This strategy premises the next institutional properties as its default setting[86]:

ReferenceBrand=Futures

TradingBrand=Futures

TradingType=NORMAL

#Price

Price.Buy.Average=Ask

Price.Buy.StandardDeviation=2.5Tick

Price.Sell.Average=Bid

Price.Sell.StandardDeviation=2.5Tick

#Volume

Volume.Buy.Max=10

Volume.Buy.Min=1

Volume.Sell.Max=10

Volume.Sell.Min=1

#Frequency

OrderFrequency=Fixed

(continued)

OrderFrequencyFrequency=O

#OrderFrequency.Average=5

#OrderFrequency.StandardDeviation=2

#OrderLimit

OrderLimiTPosition=-1

OrderLimit.Cash=-1

It is trivial that the institutional setting may be easy to be changed by assigning a different value in the file.

As for “#Frequency”, it may change the frequency framing by either removing # or changing the given numerical values.

package strategyV4;

P

import java.io.IOException;

import server.UBrandInformationManager;

import server.UMachineAgentInformation; import server.UMartTime;

public class URandomStrategy extends UStandardAgent {

private static final double CASH_LIMIT = 1 / 3; private int fCountOfOrderFrequency;

private int fOrderFrequency;

public URandomStrategy(int dummyParam) { super(dummyParam);

}

@Override

public void setParameters(String parameters) throws IOException

{ super.setParameters(parameters); fCountOfOrderFrequency = 0;

fOrderFrequency = getOrderfrequency();

}

©Override

public void action(UMartTime time,

UMachineAgentInformation machineAgentInfo,

UBrandInformationManager brandInfoManager) { super.action(time, machineAgentInfo, brandInfoManager);

if(isOrder()){

//If the random value is zero, buy; if 1, sell. if(getRandomInteger(2) == 0){ buyOrder(brandInfoManager);

}

else{

SellOrdertbrandInfoManager);

}

}

}

/**

* Check the timing whether order should be given

or not.

* ©return

*/

private boolean isOrder() {

if (fOrderFrequency == fCountOfOrderFrequency) { fCountOfOrderFrequency = 0;

fOrderFrequency = getOrderfrequency(); return true;

} fCountOfOrderFrequency++; return false;

}

/**

* Decide the frequency of giving orders.

* If the frequency is fixed, orders are given by a constant frequency.

If it is randomly generated, orders are given by the frequency generated by a normal random number.

* ©return

* I

private int getOrderfrequency() { int count;

if(fSystemParameters.getProperty ("OrderFrequency").equals("Fixed")){ count = fSystemParameters.getIntProperty

("OrderFrequency.Frequency");

} else{ count = (int)getRandomGaussian (fSystemParameters.getDoubleProperty

("OrderFrequency.Average"), fSystemParameters.getDoubleProperty ("OrderFrequency.StandardDeviation"));

}

if (count < 0) {

return 0;

} else {

return count;

}

}

}

<< | >>
Source: Aruka Y.. Evolutionary Foundations of Economic Science: How Can Scientists Study Evolving Economic Doctrines from the Last Centuries? Springer Japan,2015. — 234 p.. 2015
More economic literature on Economics.Studio

More on the topic Appendix B: