【发布时间】:2014-04-08 02:09:32
【问题描述】:
我正在研究一种可用于交易的 Python 遗传算法。如果您熟悉进化算法,原理很简单: 基因代表交易策略:更具体地说,每个基因都是这种形式的树:
这可以解释为一个布尔值,如下所示:
如果:
50 个最后股票价值的平均值小于 实际价格
和6个最后库存值的min小于实际价格。 然后回答 *True**,否则 False
如果答案为真,则发送买入信号,否则发送卖出信号。
这是我如何在 python 中表示这样的树的示例:
class BinaryRule:
def __init__(self, child1, child2):
self.child1 = child1
self.child2 = child2
class LessThan(BinaryRule):
name = '<'
def eval(self):
return self.child1.eval() < self.child2.eval()
# Here there is the definition of the other classes
# and then I create the tree
tree = rules.LessThan(
rules.Max( rules.Float(1) ),
rules.SMA( rules.Float(15) ),
)
print tree.eval() # True or false
问题是我想不出适合 crossover 和 mutation 运算符的好的技术。有什么想法吗?
【问题讨论】:
-
您目前如何代表这些?
-
你……遗漏了一些非常关键的代码。
标签: python genetic-algorithm genetic-programming