-
Notifications
You must be signed in to change notification settings - Fork 240
/
test_opt.py
executable file
·40 lines (31 loc) · 1016 Bytes
/
test_opt.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
#!/usr/bin/env python
try:
import pyaux
pyaux.use_exc_ipdb()
pyaux.use_exc_log()
except:
pass
import datetime
import matplotlib.pyplot as plt
import IPython
import logging
logging.basicConfig()
from pybacktest.testers import SimpleBacktester
from pybacktest.opt import Optimizer
from examples.ma_strategy import MACrossoverStrategy as strategy
from pybacktest.data.pandas_bars import pandas_bars_wrap
from pybacktest.data.quotes import get_daily_quotes_yahoo
bars = pandas_bars_wrap(get_daily_quotes_yahoo('GOLD', '20070101', '20120101'))
bars = [list(bars)]
opt = Optimizer(SimpleBacktester, bars, strategy, log_level=logging.DEBUG)
opt.add_opt_param('fast_period', 5, 20, 1)
#opt.add_opt_param('slow_period', 20, 50, 5)
opt.run(('sharpe',))
print 'Param names: %s' % opt.param_names
print 'Optimization results (param vector : resulting statistics)'
try:
import pprint
pprint.pprint(opt.opt_results)
except:
print opt.opt_results
IPython.embed(banner1='optimizer is in `opt`')