-
Notifications
You must be signed in to change notification settings - Fork 8
/
TODO
executable file
·70 lines (45 loc) · 2.01 KB
/
TODO
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
Parallel along date axis
========================
Please see file 'orca/alpha/base' and find the '#TODO' label.
The idea is to run a **single** alpha in parallel by splitting simulation along date axis.
For example, paste the following code into a .py file:
.. code-block:: python
from orca.mongo.quote import QuoteFetcher
startdate, enddate = '20140101', '20141017'
close = QuoteFetcher(datetime_index=True, reindex=True).fetch('close', startdate=startdate, enddate=enddate)
from orca.alpha.base import BacktestingAlpha
class MyAlpha(BacktestingAlpha):
def generate(self, date):
self.alphas[date] = close.ix[date]
if __name__ == '__main__':
alpha = MyAlpha()
alpha.run(startdate, enddate, parallel=True)
from orca.utils.testing import frames_equal
assert frames_equal(alpha.get_alphas(), close)
Parallel in parameter space
===========================
See `PyAlgoTrade <http://gbeced.github.io/pyalgotrade/docs/v0.15/html/tutorial.html#optimizing>`_ for reference.
The picture I have in mind is pretty much alike:
.. code-block:: python
from orca.mongo.quote import QuoteFetcher
startdate, enddate = '20140101', '20141017'
close = QuoteFetcher(datetime_index=True, reindex=True).fetch('close', startdate=startdate, enddate=enddate)
from orca.alpha.base import BacktestingAlpha
import time
class MyAlpha(BacktestingAlpha):
def __init__(self, n):
self.n = n
def generate(self, date):
time.sleep(self.n % 100)
self.alphas[date] = close.ix[date] * self.n
def gen_params():
for i in xrange(10000):
yield i
if __name__ == '__main__':
from orca.utils.parallel import local
import multiprocessing
alphas = local.run(MyAlpha,
gen_params,
batch=multiprocessing.cpu_count(),
universe = XXX,
lambda x: x.get_original().get_ir() > 0.1)