My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package dk.bettingai.tradingoptimiser

import org.junit._
import Assert._
import java.io.File
import dk.bettingai.marketsimulator.trader._
import ITrader._
import dk.bettingai.marketsimulator.betex.api._
import IMarket._
import IBet.BetTypeEnum._
import CoevolutionHillClimbingTest._
import ICoevolutionHillClimbing._
import org.slf4j.LoggerFactory
import dk.bettingai.marketsimulator.betex.PriceUtil._
import java.util.Random
import scala.collection.immutable.TreeMap

object CoevolutionHillClimbingTest {
class PriceTrader(val price: Double) extends ITrader {

val market1Id = 101655622
val market1RunnerId = 4207432

val market2Id = 101655610
val market2RunnerId = 3364827

def execute(ctx: ITraderContext) = {

if (ctx.marketId == market1Id) {
val bestPrices = ctx.getBestPrices(market1RunnerId)
if (bestPrices._1.price > price) ctx.fillBet(2, bestPrices._1.price, BACK, market1RunnerId)
}

if (ctx.marketId == market2Id) {
val bestPrices = ctx.getBestPrices(market2RunnerId)
if (bestPrices._1.price > price) ctx.fillBet(2, bestPrices._1.price, BACK, market2RunnerId)
}

}

override def toString = "PriceTrader [price=%s]".format(price)
}
}

class CoevolutionHillClimbingTest {

private val log = LoggerFactory.getLogger(getClass)

val trader = new PriceTrader(2.22)

private val populationSize = 10
private val generationNum = 10

private val rand = new Random(System.currentTimeMillis)

@Test
def testOneMarket {

log.info("Initial trader=" + trader)

val marketDataDir = new File("./src/test/resources/one_hr_10mins_before_inplay")
val marketDataSources = TreeMap(marketDataDir.listFiles.filter(_.getName.endsWith(".csv")).map(f => f.getName.split("\\.")(0).toLong -> f): _*)
val progress = (iter: Int, best: Solution[PriceTrader], current: Solution[PriceTrader]) => log.info("Iter number=" + iter + ", bestSoFar=" + best + ", currentBest=" + current)
val mutate = (solution: Solution[PriceTrader]) => new PriceTrader(move(solution.trader.price, rand.nextInt(11) - 5))
val bestSolution = CoevolutionHillClimbing.optimise(marketDataSources, trader, mutate, populationSize, generationNum, progress)

log.info("Best solution=" + bestSolution)
}

@Test
def testTwoMarkets {

log.info("Initial trader=" + trader)

val marketDataDir = "./src/test/resources/two_hr_10mins_before_inplay"
val mutate = (solution: Solution[PriceTrader]) => new PriceTrader(move(solution.trader.price, rand.nextInt(11) - 5))
val bestSolution = CoevolutionHillClimbing.optimise(marketDataDir, trader, mutate, populationSize, generationNum)

log.info("Best solution=" + bestSolution)
}

@Test
def testNoMarketData {
log.info("Initial trader=" + trader)

val marketDataSources: TreeMap[Long, File] = TreeMap()
val progress = (iter: Int, best: Solution[PriceTrader], current: Solution[PriceTrader]) => log.info("Iter number=" + iter + ", bestSoFar=" + best + ", currentBest=" + current)
val mutate = (solution: Solution[PriceTrader]) => new PriceTrader(move(solution.trader.price, rand.nextInt(11) - 5))
val bestSolution = CoevolutionHillClimbing.optimise(marketDataSources, trader, mutate, populationSize, generationNum, progress)
assertEquals(Solution(trader, Double.MinValue, 0), bestSolution)

log.info("Best solution=" + bestSolution)
}

@Test
def testEmptyMarketFiles {
log.info("Initial trader=" + trader)

val marketDataDir = "./src/test/resources/empty_market_files"
val mutate = (solution: Solution[PriceTrader]) => new PriceTrader(move(solution.trader.price, rand.nextInt(11) - 5))
val bestSolution = CoevolutionHillClimbing.optimise(marketDataDir, trader, mutate, populationSize, generationNum)
assertEquals(Solution(trader, Double.MinValue, 0), bestSolution)

log.info("Best solution=" + bestSolution)
}
}

Change log

r266 by daniel.korzekwa on Mar 4, 2011   Diff
[maven-release-plugin]  copy for tag
betting-ai-1.3
Go to: 
Project members, sign in to write a code review

Older revisions

r253 by daniel.korzekwa on Feb 22, 2011   Diff
 Issue 77 :       Create Abstract Test
Runner for co-evolution tests
 Issue 79 :       Create unit test for
Simulator Report.
 Issue 94 :       Progress bar in
...
r252 by daniel.korzekwa on Feb 20, 2011   Diff
 Issue 74 :       Add restart capability
to PricePriceSlopeTrader optimisation.
r244 by daniel.korzekwa on Feb 15, 2011   Diff
 Issue 71 :       Create
CoevolutionTraderOptimisation
Extending market simulator to be able
to test multiple traders.
All revisions of this file

File info

Size: 4020 bytes, 106 lines
Powered by Google Project Hosting