/
launcher.py
67 lines (53 loc) · 1.49 KB
/
launcher.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
56
57
58
59
60
61
62
63
64
65
import logging
from datetime import *
from time import clock
from decimal import Decimal
from simulator import Simulator
from strategy import Strategy
LOG_FILE_PATH = 'log/'
LOG_FILENAME = 'run_'
FORMAT = "%(message)s"
class Launcher(object):
def setup_logging(self):
t = datetime.now()
self.tstamp = '%d-%d-%d-%d-%d' % (t.year, t.month, t.day, t.hour, t.minute)
fname = LOG_FILE_PATH + LOG_FILENAME + self.tstamp + '.log'
logging.basicConfig(filename=fname,level=logging.INFO,format=FORMAT)
def configure(self, p):
print('constructing simulator')
self.sim = Simulator(p['ins'], p['strat'], p['start_date'], p['end_date'], p['open_bal'], self.tstamp)
def simulate(self):
print('running simulator')
start = clock()
self.sim.run()
end = clock()
dur_str = 'seconds = %f' % (end - start)
print(dur_str)
logging.info('sim time = ' + dur_str)
def report(self):
print('plotting')
start = clock()
self.sim.plot()
end = clock()
dur_str = 'seconds = %f' % (end - start)
print(dur_str)
logging.info('plot time = ' + dur_str)
def go(self, p):
self.setup_logging()
self.configure(p)
self.simulate()
self.report()
def main():
l = Launcher()
p = {
'start_date' : date(2008, 1, 1),
'end_date' : date(2010, 12, 30),
# equity/JPM
# equity_index/
'ins' : 'equity_index/^GSPC',
'strat' : 'movavg',
'open_bal' : Decimal('10000.00')
}
l.go(p)
if __name__ == '__main__':
main()