-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfitness.py
55 lines (49 loc) · 1.65 KB
/
fitness.py
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
from abc import ABCMeta, abstractmethod
class AFitness:
"""
Encapsulate an optimization algorithm
"""
__metaclass__ = ABCMeta
pass
class Fitness(AFitness, dict):
"""
Struct which has all fitness value variables that DC java strategy returns.
"""
def __init__(
self,
value: float = 0,
u_sell: int = 0,
u_buy: int = 0,
noop: int = 0,
realised_profit: float = 0,
mdd: float = 0,
ret: float = 0,
wealth: float = 0,
no_of_transactions: int = 0,
no_of_short_selling_transactions: int = 0
):
self.value = value
self.u_sell = u_sell
self.u_buy = u_buy
self.noop = noop
self.realised_profit = realised_profit
self.mdd = mdd
self.ret = ret
self.wealth = wealth
self.no_of_transactions = no_of_transactions
self.no_of_short_selling_transactions = no_of_short_selling_transactions
def __repr__(self):
return "%10.6f\t%10.6f\t%10.6f\t%10.6f\t%10.6f\t%d\t%d\n" % (self.wealth, self.ret, self.value, self.realised_profit, self.mdd, self.no_of_transactions, self.no_of_short_selling_transactions)
from abc import ABCMeta, abstractmethod
from individual import AIndividual
class AFitnessFunction:
"""
Encapsulates a function we want to optimize
"""
__metaclass__ = ABCMeta
@abstractmethod
def fitness(self, individual: AIndividual) -> AFitness:
"""
Fitness function that returns a Fitness object
"""
pass