def optimize(): optimizer = Optimizer() optimizer.strategy_class = RSIStrategy #optimizer.data_feed = DataFeedList(['20081210.SPY.1m.csv','20081211.SPY.1min.csv','20081212.SPY.1min.csv'],data_type='B') #optimizer.data_feed = DataFeedList(['20081210.SPY.30s.csv','20081211.SPY.30s.csv','20081212.SPY.30s.csv'],data_type='I') optimizer.data_feed = DataFeedList(['SPY.csv'], data_type='D') ## set population size optimizer.size = 40 optimizer.max_generations = 50 optimizer.outfile = '%s_%s.xls' % (__file__[:-3], datetime.now().strftime("%Y%m%d")) optimizer.tolerance = 0.01 #optimizer.reset_on_EOD = False ## parameter space to search over ## rsi = rsi length ## top/btm = rsi buy sell thresholds ## average(optional) trend filter ## duration = trade duration optimizer.add_parameter( dict(name='rsi', min_val=10, max_val=40, steps=16, converter=int)) optimizer.add_parameter( dict(name='top', min_val=60, max_val=80, steps=4, converter=int)) optimizer.add_parameter( dict(name='btm', min_val=20, max_val=40, steps=4, converter=int)) optimizer.add_parameter( dict(name='average', min_val=20, max_val=200, steps=64, converter=int)) optimizer.add_parameter( dict(name='duration', min_val=5, max_val=20, steps=8, converter=int)) optimizer.run()
def simulate(): ''' strategy_params=dict(top=60,btm=40,rsi=14,average=111,duration=5)) +--------+-----+-------+------+---------+---------+---------+---------+ | _score | cnt | w_pct | pr | pnl | mtm_pnl | max_equ | max_dd | +--------+-----+-------+------+---------+---------+---------+---------+ | 5.70 | 97 | 0.61 | 1.25 | 7163.57 | 7163.57 | 7608.81 | 1129.33 | +--------+-----+-------+------+---------+---------+---------+---------+ equity curve = 570x.png strategy_params=dict(top=60,btm=40,rsi=12,average=180,duration=7)) +--------+-----+-------+------+----------+----------+----------+---------+ | _score | cnt | w_pct | pr | pnl | mtm_pnl | max_equ | max_dd | +--------+-----+-------+------+----------+----------+----------+---------+ | 7.56 | 106 | 0.67 | 1.22 | 11139.79 | 11139.79 | 11158.79 | 1330.16 | +--------+-----+-------+------+----------+----------+----------+---------+ equity curve = 756x.png ''' m = RSIStrategy(name='rsi2_spy', strategy_params=dict(top=60, btm=40, rsi=12, average=180, duration=7)) s = Simulator() s.add_strategy(m) s.run(DataFeedList(['SPY.csv'], data_type='D')) s.write('rsi2_SPY_%s' % datetime.now().strftime("%Y%m%d"))
def simulate_AAPL_SPY(): m = RSIStrategy(name='rsi2_aapl_spy', strategy_params=dict(top=60, btm=40, rsi=12, average=180, duration=7)) s = Simulator() s.add_strategy(m) s.run(DataFeedList(['AAPL.csv', 'SPY.csv'], data_type='D')) s.write('rsi2_AAPL_SPY_%s' % datetime.now().strftime("%Y%m%d"))
def simulate_SPY_AAPL_composite(): ''' test to make sure that a composite file (AAPL and SPY combined) is the same as the individuals (AAPL.csv and SPY.csv separately) ''' m = RSIStrategy(name='rsi2_spy_v_aapl', strategy_params=dict(top=60, btm=40, rsi=12, average=180, duration=7)) s = Simulator() s.add_strategy(m) s.run(DataFeedList(['SPY_AAPL.csv'], data_type='D')) s.write('rsi2_SPYvAAPL_%s' % datetime.now().strftime("%Y%m%d"))
from Treadmill import Treadmill from RetraceStrategy import RetraceStrategy from DataFeed import DataFeedList ''' testing the EOD flag making sure that treadmill output is consistent across multiple datafeed versus if the datafeed where combined into single data file ''' t = Treadmill() t.strategy_class = RetraceStrategy t.strategy_params = dict(average=141,momentum=21,duration=15) #t.data_feed = DataFeedList(['daily.SPY.csv','daily.SPY.csv'],data_type='D') t.data_feed = DataFeedList(['top.SPY.csv','bottom.SPY.csv'],data_type='D') t.reset_on_EOD = False t.run(20)
from Simulator import Simulator from RetraceStrategy import RetraceStrategy from DataFeed import DataFeedList if __name__ == '__main__': r = RetraceStrategy('tiger', strategy_params=dict(average=150, duration=20, momentum=40)) d = DataFeedList(['tiger_data.csv'], data_type='D') s = Simulator() s.add_strategy(r) s.run(d) s.write('tiger_150_20_40') s.show()
from Simulator import Simulator from RetraceStrategy import RetraceStrategy from DataFeed import DataFeedList if __name__ == '__main__': r = RetraceStrategy('retrace_mini', strategy_params=dict(average=150, duration=20, momentum=65)) d = DataFeedList(['SPY.csv'], data_type='D') s = Simulator() s.add_strategy(r) s.run(d) s.write('retrace_spy_universe')
#data_feed = DataFeedList(['daily.SPY.csv','daily.SPY.csv'],data_type='D') data_feed = DataFeedList(['daily.SPY.csv','daily.SPY.csv'],data_type='D') s.run(data_feed) s.write('R2') ## testing DataFeedBar serial files strat = MStrategy2('M2',strategy_params = dict(length=20,duration=15)) #strat.capture_data = True s.add_strategy(strat) s.reset_on_EOD = False data_feed = DataFeedList(['20081210.SPY.1min.csv','20081211.SPY.1min.csv','20081212.SPY.1min.csv'],data_type='B') s.run(data_feed) #strat.dump_data().to_csv('M2_data_dump.csv') s.write('M2') ''' ## testing DataFeedIntraday serial files strat = MStrategy2('M2', strategy_params=dict(length=30, duration=50)) #strat.capture_data = True s.add_strategy(strat) s.reset_on_EOD = False #data_feed = DataFeedList(['20081210.SPY.30s.csv','20081211.SPY.30s.csv'],data_type='I') #data_feed = DataFeedList(['combo.SPY.30s.csv'],data_type='I') data_feed = DataFeedList( ['20081210.SPY.30s.csv', '20081211.SPY.30s.csv', '20081212.SPY.30s.csv'], data_type='I') s.run(data_feed) #strat.dump_data().to_csv('M2_data_dump.csv') s.write('MI2')
from RSIStrategy import RSIStrategy from DataFeed import DataFeedList from Optimizer import Optimizer from datetime import datetime if __name__ == '__main__': optimizer = Optimizer() optimizer.strategy_class = RSIStrategy #optimizer.data_feed = DataFeedList(['20081210.SPY.1m.csv','20081211.SPY.1min.csv','20081212.SPY.1min.csv'],data_type='B') #optimizer.data_feed = DataFeedList(['20081210.SPY.30s.csv','20081211.SPY.30s.csv','20081212.SPY.30s.csv'],data_type='I') optimizer.data_feed = DataFeedList(['SPY.csv'], data_type='D') ## set population size optimizer.size = 40 optimizer.max_generations = 50 optimizer.outfile = '%s_%s.xls' % (__file__[:-3], datetime.now().strftime("%Y%m%d_%H%M")) optimizer.tolerance = 0.01 #optimizer.reset_on_EOD = False ## parameter space to search over ## rsi = rsi length ## top/btm = rsi buy sell thresholds ## average(optional) trend filter ## duration = trade duration optimizer.add_parameter( dict(name='rsi', min_val=10, max_val=40, steps=16, converter=int)) optimizer.add_parameter( dict(name='top', min_val=60, max_val=80, steps=4, converter=int))
from Simulator import Simulator from RetraceStrategy import RetraceStrategy from DataFeed import DataFeedList if __name__ == '__main__': r = RetraceStrategy('retrace_mini_universe',strategy_params=dict(average=150,duration=20,momentum=65)) d = DataFeedList(['mini_data.csv'],data_type='D') s = Simulator() s.add_strategy(r) s.run(d) s.write('retrace_mini_universe')