mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-10 12:00:15 +08:00
STY: Prepend order_ to all target methods.
This commit is contained in:
@@ -469,7 +469,7 @@ class TradingAlgorithm(object):
|
||||
value = self.portfolio.portfolio_value * percent
|
||||
return self.order_value(sid, value, limit_price, stop_price)
|
||||
|
||||
def target(self, sid, target, limit_price=None, stop_price=None):
|
||||
def order_target(self, sid, target, limit_price=None, stop_price=None):
|
||||
"""
|
||||
Place an order to adjust a position to a target number of shares. If
|
||||
the position doesn't already exist, this is equivalent to placing a new
|
||||
@@ -484,7 +484,7 @@ class TradingAlgorithm(object):
|
||||
else:
|
||||
return self.order(sid, target, limit_price, stop_price)
|
||||
|
||||
def target_value(self, sid, target, limit_price=None, stop_price=None):
|
||||
def order_target_value(self, sid, target, limit_price=None, stop_price=None):
|
||||
"""
|
||||
Place an order to adjust a position to a target value. If
|
||||
the position doesn't already exist, this is equivalent to placing a new
|
||||
@@ -501,7 +501,7 @@ class TradingAlgorithm(object):
|
||||
else:
|
||||
return self.order_value(sid, target, limit_price, stop_price)
|
||||
|
||||
def target_percent(self, sid, target, limit_price=None, stop_price=None):
|
||||
def order_target_percent(self, sid, target, limit_price=None, stop_price=None):
|
||||
"""
|
||||
Place an order to adjust a position to a target percent of the
|
||||
current portfolio value. If the position doesn't already exist, this is
|
||||
|
||||
@@ -283,7 +283,7 @@ class TestTargetAlgorithm(TradingAlgorithm):
|
||||
assert self.portfolio.positions[0]['last_sale_price'] == \
|
||||
data[0].price, "Orders not filled at current price."
|
||||
self.target_shares = np.random.randint(1, 30)
|
||||
self.target(0, self.target_shares)
|
||||
self.order_target(0, self.target_shares)
|
||||
|
||||
|
||||
class TestOrderPercentAlgorithm(TradingAlgorithm):
|
||||
@@ -325,7 +325,7 @@ class TestTargetPercentAlgorithm(TradingAlgorithm):
|
||||
assert self.portfolio.positions[0]['last_sale_price'] == \
|
||||
data[0].price, "Orders not filled at current price."
|
||||
self.sale_price = data[0].price
|
||||
self.target_percent(0, .002)
|
||||
self.order_target_percent(0, .002)
|
||||
|
||||
|
||||
class TestTargetValueAlgorithm(TradingAlgorithm):
|
||||
@@ -346,7 +346,7 @@ class TestTargetValueAlgorithm(TradingAlgorithm):
|
||||
assert self.portfolio.positions[0]['last_sale_price'] == \
|
||||
data[0].price, "Orders not filled at current price."
|
||||
|
||||
self.target_value(0, 20)
|
||||
self.order_target_value(0, 20)
|
||||
self.target_shares = np.round(20 / data[0].price)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user