mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-30 12:01:00 +08:00
Merge pull request #54 from quantopian/optimize_qexec
Small fixes to optimize tests to work with refactored zipline.
This commit is contained in:
@@ -39,7 +39,6 @@ class TestUpDown(TestCase):
|
||||
'sid':133
|
||||
}
|
||||
|
||||
@skip
|
||||
@timed(DEFAULT_TIMEOUT)
|
||||
def test_source_and_orders(self):
|
||||
"""verify that UpDownSource is having the correct
|
||||
@@ -108,10 +107,10 @@ class TestUpDown(TestCase):
|
||||
self.assertTrue(np.all(min_order_idx == min_price_idx),
|
||||
"Algorithm did not sell when price was going to increase."
|
||||
)
|
||||
|
||||
@skip
|
||||
|
||||
|
||||
def test_concavity_of_returns(self):
|
||||
"""verify concave relationship between of free parameter and
|
||||
"""verify concave relationship between free parameter and
|
||||
returns in certain region around the max. Moreover,
|
||||
establishes that the max returns is at the correct value
|
||||
(i.e. 0).
|
||||
@@ -170,7 +169,7 @@ class TestUpDown(TestCase):
|
||||
idx[0] -= 1
|
||||
idx[1] += 1
|
||||
|
||||
@skip
|
||||
#@skip
|
||||
def test_optimize(self):
|
||||
"""verify that gradient descent (Powell's method) can find
|
||||
the optimal free parameter under which the BuySellAlgorithm produces
|
||||
@@ -201,7 +200,6 @@ class TestUpDown(TestCase):
|
||||
self.zipline_test_config['environment'] = trading_environment
|
||||
zipline = SimulatedTrading.create_test_zipline(**self.zipline_test_config)
|
||||
zipline.simulate(blocking=True)
|
||||
zipline.shutdown()
|
||||
#function is getting minimized, so have to return negative cum returns.
|
||||
return -zipline.get_cumulative_performance()['returns']
|
||||
|
||||
|
||||
@@ -7,13 +7,14 @@ from datetime import datetime, timedelta
|
||||
|
||||
import zipline.protocol as zp
|
||||
|
||||
from zipline.utils.factory import get_next_trading_dt
|
||||
from zipline.utils.factory import get_next_trading_dt, create_trading_environment
|
||||
from zipline.finance.sources import SpecificEquityTrades
|
||||
from zipline.optimize.algorithms import BuySellAlgorithm
|
||||
from zipline.lines import SimulatedTrading
|
||||
from copy import deepcopy
|
||||
from itertools import cycle
|
||||
|
||||
def create_updown_trade_source(sid, trade_count, trading_environment, start_price, amplitude):
|
||||
from itertools import cycle
|
||||
volume = 1000
|
||||
events = []
|
||||
price = start_price-amplitude/2.
|
||||
@@ -41,7 +42,7 @@ def create_updown_trade_source(sid, trade_count, trading_environment, start_pric
|
||||
|
||||
trading_environment.period_end = cur
|
||||
|
||||
source = SpecificEquityTrades(sid, events)
|
||||
source = SpecificEquityTrades("updown_" + str(sid), events)
|
||||
|
||||
return source
|
||||
|
||||
@@ -55,7 +56,7 @@ def create_predictable_zipline(config, sid=133, amplitude=10, base_price=50, off
|
||||
base_price,
|
||||
amplitude)
|
||||
|
||||
algo = RegularIntervalBuySellAlgorithm(sid, 100, offset)
|
||||
algo = BuySellAlgorithm(sid, 100, offset)
|
||||
config['algorithm'] = algo
|
||||
config['trade_source'] = source
|
||||
config['environment'] = trading_environment
|
||||
|
||||
Reference in New Issue
Block a user