Skip to content

Commit

Permalink
Merge 5b3e2de into 64af3d3
Browse files Browse the repository at this point in the history
  • Loading branch information
samklonaris committed Sep 25, 2017
2 parents 64af3d3 + 5b3e2de commit 309410e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 9 deletions.
11 changes: 6 additions & 5 deletions tests/test_algorithm.py
Expand Up @@ -1488,11 +1488,12 @@ def handle_data(context, data):

# Starting portfolio value is 10000. Order for the asset fills on the
# second bar of 1/06, where the price is 391, and costs the default
# commission of 1. On 1/07, the price is 780, and the increase in
# portfolio value is 780-392-1
# commission of 0. On 1/07, the price is 780, and the increase in
# portfolio value is 780-392-0
self.assertEqual(results.port_value.iloc[0], 10000)
self.assertAlmostEqual(results.port_value.iloc[1],
10000 + 780 - 392 - 1)
10000 + 780 - 392 - 0,
places=2)

def test_portfolio_bts_with_overnight_split(self):
algo_code = dedent("""
Expand Down Expand Up @@ -1572,7 +1573,7 @@ def handle_data(context, data):
# On 1/07, portfolio value is the same as without split
self.assertEqual(results.port_value.iloc[0], 10000)
self.assertAlmostEqual(results.port_value.iloc[1],
10000 + 780 - 392 - 1)
10000 + 780 - 392 - 0, places=2)


class TestAlgoScript(WithLogger,
Expand Down Expand Up @@ -1762,7 +1763,7 @@ def handle_data(context, data):
@parameterized.expand(
[
('no_minimum_commission', 0,),
('default_minimum_commission', 1,),
('default_minimum_commission', 0,),
('alternate_minimum_commission', 2,),
]
)
Expand Down
7 changes: 7 additions & 0 deletions zipline/examples/buy_and_hold.py
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from zipline.api import order, symbol
from zipline.finance import commission

stocks = ['AAPL', 'MSFT']

Expand All @@ -22,6 +23,12 @@ def initialize(context):
context.has_ordered = False
context.stocks = stocks

# Explicitly set the commission to the "old" value until we can
# rebuild example data.
# github.com/quantopian/zipline/blob/master/tests/resources/
# rebuild_example_data#L105
context.set_commission(commission.PerShare(cost=.0075, min_trade_cost=1.0))


def handle_data(context, data):
if not context.has_ordered:
Expand Down
7 changes: 7 additions & 0 deletions zipline/examples/buyapple.py
Expand Up @@ -15,11 +15,18 @@
# limitations under the License.

from zipline.api import order, record, symbol
from zipline.finance import commission


def initialize(context):
context.asset = symbol('AAPL')

# Explicitly set the commission to the "old" value until we can
# rebuild example data.
# github.com/quantopian/zipline/blob/master/tests/resources/
# rebuild_example_data#L105
context.set_commission(commission.PerShare(cost=.0075, min_trade_cost=1.0))


def handle_data(context, data):
order(context.asset, 10)
Expand Down
7 changes: 7 additions & 0 deletions zipline/examples/dual_ema_talib.py
Expand Up @@ -25,6 +25,7 @@
"""

from zipline.api import order, record, symbol
from zipline.finance import commission
# Import exponential moving average from talib wrapper
from talib import EMA

Expand All @@ -35,6 +36,12 @@ def initialize(context):
# To keep track of whether we invested in the stock or not
context.invested = False

# Explicitly set the commission to the "old" value until we can
# rebuild example data.
# github.com/quantopian/zipline/blob/master/tests/resources/
# rebuild_example_data#L105
context.set_commission(commission.PerShare(cost=.0075, min_trade_cost=1.0))


def handle_data(context, data):
trailing_window = data.history(context.asset, 'price', 40, '1d')
Expand Down
7 changes: 7 additions & 0 deletions zipline/examples/dual_moving_average.py
Expand Up @@ -23,12 +23,19 @@
"""

from zipline.api import order_target, record, symbol
from zipline.finance import commission


def initialize(context):
context.sym = symbol('AAPL')
context.i = 0

# Explicitly set the commission to the "old" value until we can
# rebuild example data.
# github.com/quantopian/zipline/blob/master/tests/resources/
# rebuild_example_data#L105
context.set_commission(commission.PerShare(cost=.0075, min_trade_cost=1.0))


def handle_data(context, data):
# Skip first 300 days to get full windows
Expand Down
7 changes: 7 additions & 0 deletions zipline/examples/momentum_pipeline.py
Expand Up @@ -11,6 +11,7 @@
record,
schedule_function,
)
from zipline.finance import commission
from zipline.pipeline import Pipeline
from zipline.pipeline.factors import RSI

Expand Down Expand Up @@ -63,6 +64,12 @@ def initialize(context):
# running at the start of the day each day.
schedule_function(rebalance, date_rules.every_day())

# Explicitly set the commission to the "old" value until we can
# rebuild example data.
# github.com/quantopian/zipline/blob/master/tests/resources/
# rebuild_example_data#L105
context.set_commission(commission.PerShare(cost=.0075, min_trade_cost=1.0))


def before_trading_start(context, data):
context.pipeline_data = pipeline_output('my_pipeline')
Expand Down
2 changes: 1 addition & 1 deletion zipline/examples/olmar.py
Expand Up @@ -30,7 +30,7 @@ def initialize(algo, eps=1, window_length=5):
algo.days = 0
algo.window_length = window_length

algo.set_commission(commission.PerShare(cost=0))
algo.set_commission(commission.PerShare(cost=0, min_trade_cost=1.0))


def handle_data(algo, data):
Expand Down
6 changes: 3 additions & 3 deletions zipline/finance/commission.py
Expand Up @@ -23,11 +23,11 @@
from zipline.finance.shared import AllowedAssetMarker, FinancialModelMeta
from zipline.utils.dummy import DummyMapping

DEFAULT_PER_SHARE_COST = 0.0075 # 0.75 cents per share
DEFAULT_PER_SHARE_COST = 0.001 # 0.1 cents per share
DEFAULT_PER_CONTRACT_COST = 0.85 # $0.85 per future contract
DEFAULT_PER_DOLLAR_COST = 0.0015 # 0.15 cents per dollar
DEFAULT_MINIMUM_COST_PER_EQUITY_TRADE = 1.0 # $1 per trade
DEFAULT_MINIMUM_COST_PER_FUTURE_TRADE = 1.0 # $1 per trade
DEFAULT_MINIMUM_COST_PER_EQUITY_TRADE = 0.0 # $0 per trade
DEFAULT_MINIMUM_COST_PER_FUTURE_TRADE = 0.0 # $0 per trade


class CommissionModel(with_metaclass(FinancialModelMeta)):
Expand Down

0 comments on commit 309410e

Please sign in to comment.