Source reformatted

This commit is contained in:
7u83 2016-12-26 10:11:40 +01:00
parent 354f739f83
commit 5515dddb30
1 changed files with 71 additions and 76 deletions

View File

@ -3,86 +3,81 @@ package SeSim;
import java.util.Random; import java.util.Random;
public class MTrader implements Trader { public class MTrader implements Trader {
Exchange ex;
Random rand;
public MTrader (Exchange ex1, long shares, double money){
account.money=money;
account.shares=shares;
this.ex=ex;
rand = new Random();
}
public void DoBuy() Exchange ex;
{ Random rand;
// System.out.println("AAA");
public MTrader(Exchange ex1, long shares, double money) {
if (account.orderpending) account.money = money;
return; account.shares = shares;
this.ex = ex;
if (account.money <= 0) rand = new Random();
return; }
double perc = rand.nextDouble() * 1.0; public void DoBuy() {
double lp = ex.lastprice; // System.out.println("AAA");
double limit = lp/100 * perc + lp;
if (account.orderpending) {
return;
}
if (account.money <= 0) {
return;
}
double perc = rand.nextDouble() * 1.0;
double lp = ex.lastprice;
double limit = lp / 100 * perc + lp;
// System.out.println("HW"); // System.out.println("HW");
long size = (int)(account.money/limit); long size = (int) (account.money / limit);
account.Buy(size, limit, ex);
return;
}
public void DoSell() account.Buy(size, limit, ex);
{ return;
}
public void DoSell() {
// System.out.println("SoSell"); // System.out.println("SoSell");
if (account.orderpending)
return;
if (account.shares<=0)
return;
double perc = rand.nextDouble() * 1.0;
double lp = ex.lastprice;
double limit = lp - lp/100 * perc;
long size = (int)(account.shares);
account.Sell(size, limit, ex);
return;
}
if (account.orderpending) {
return;
public void trade(){ }
if (account.shares <= 0) {
// What to do? return;
int action = rand.nextInt(3); }
// System.out.print("Action");
// System.out.println(action); double perc = rand.nextDouble() * 1.0;
if (action==0) double lp = ex.lastprice;
return; double limit = lp - lp / 100 * perc;
if (action == 1) long size = (int) (account.shares);
{
DoBuy(); account.Sell(size, limit, ex);
return; return;
} }
public void trade() {
// What to do?
int action = rand.nextInt(3);
// System.out.print("Action");
// System.out.println(action);
if (action == 0) {
return;
}
if (action == 1) {
DoBuy();
return;
}
if (action == 2) {
DoSell();
return;
}
//System.out.printf("MyPrice: %.2f\n",price);
}
if (action == 2)
{
DoSell();
return;
}
//System.out.printf("MyPrice: %.2f\n",price);
}
} }