# Path: zipline/finance/slippage.py
# class VolumeShareSlippage(SlippageModel):
# 
#     def __init__(self,
#                  volume_limit=.25,
#                  price_impact=0.1):
# 
#         self.volume_limit = volume_limit
#         self.price_impact = price_impact
# 
#     def __repr__(self):
#         return """
# {class_name}(
#     volume_limit={volume_limit},
#     price_impact={price_impact})
# """.strip().format(class_name=self.__class__.__name__,
#                    volume_limit=self.volume_limit,
#                    price_impact=self.price_impact)
# 
#     def process_order(self, event, order):
# 
#         max_volume = self.volume_limit * event.volume
# 
#         # price impact accounts for the total volume of transactions
#         # created against the current minute bar
#         remaining_volume = max_volume - self.volume_for_bar
#         if remaining_volume < 1:
#             # we can't fill any more transactions
#             return
# 
#         # the current order amount will be the min of the
#         # volume available in the bar or the open amount.
#         cur_volume = int(min(remaining_volume, abs(order.open_amount)))
# 
#         if cur_volume < 1:
#             return
# 
#         # tally the current amount into our total amount ordered.
#         # total amount will be used to calculate price impact
#         total_volume = self.volume_for_bar + cur_volume
# 
#         volume_share = min(total_volume / event.volume,
#                            self.volume_limit)
# 
#         simulated_impact = (volume_share) ** 2 \
#             * math.copysign(self.price_impact, order.direction) \
#             * event.price
# 
#         return create_transaction(
#             event,
#             order,
#             # In the future, we may want to change the next line
#             # for limit pricing
#             event.price + simulated_impact,
#             math.copysign(cur_volume, order.direction)
#         )


import datetime
import pytz
import pandas as pd
from unittest import TestCase
from nose_parameterized import parameterized
from zipline.finance.slippage import VolumeShareSlippage
from zipline.protocol import Event, DATASOURCE_TYPE
from zipline.finance.blotter import Order
            },
            'event': {
                'dt': pd.Timestamp('2006-01-05 14:31', tz='UTC'),
                'volume': 2000,
                'price': 3.0,
                'high': 3.15,
                'low': 2.85,
                'sid': 133,
                'close': 3.0,
                'open': 3.0
            },
            'expected': {
                'transaction': {
                    'price': 2.99925,
                    'dt': pd.Timestamp('2006-01-05 14:31', tz='UTC'),
                    'amount': -100,
                    'sid': 133,
                }
            }
        },
    }

    @parameterized.expand([
        (name, case['order'], case['event'], case['expected'])
        for name, case in STOP_ORDER_CASES.items()
    ])
    def test_orders_stop(self, name, order_data, event_data, expected):
        order = Order(**order_data)
        event = Event(initial_values=event_data)


# Path: zipline/finance/slippage.py
# class VolumeShareSlippage(SlippageModel):
# 
#     def __init__(self,
#                  volume_limit=.25,
#                  price_impact=0.1):
# 
#         self.volume_limit = volume_limit
#         self.price_impact = price_impact
# 
#     def __repr__(self):
#         return """
# {class_name}(
#     volume_limit={volume_limit},
#     price_impact={price_impact})
# """.strip().format(class_name=self.__class__.__name__,
#                    volume_limit=self.volume_limit,
#                    price_impact=self.price_impact)
# 
#     def process_order(self, event, order):
# 
#         max_volume = self.volume_limit * event.volume
# 
#         # price impact accounts for the total volume of transactions
#         # created against the current minute bar
#         remaining_volume = max_volume - self.volume_for_bar
#         if remaining_volume < 1:
#             # we can't fill any more transactions
#             return
# 
#         # the current order amount will be the min of the
#         # volume available in the bar or the open amount.
#         cur_volume = int(min(remaining_volume, abs(order.open_amount)))
# 
#         if cur_volume < 1:
#             return
# 
#         # tally the current amount into our total amount ordered.
#         # total amount will be used to calculate price impact
#         total_volume = self.volume_for_bar + cur_volume
# 
#         volume_share = min(total_volume / event.volume,
#                            self.volume_limit)
# 
#         simulated_impact = (volume_share) ** 2 \
#             * math.copysign(self.price_impact, order.direction) \
#             * event.price
# 
#         return create_transaction(
#             event,
#             order,
#             # In the future, we may want to change the next line
#             # for limit pricing
#             event.price + simulated_impact,
#             math.copysign(cur_volume, order.direction)
#         )


# Path: tests/finance/test_slippage.py
import datetime
import pytz
import pandas as pd
from unittest import TestCase
from nose_parameterized import parameterized
from zipline.finance.slippage import VolumeShareSlippage
from zipline.protocol import Event, DATASOURCE_TYPE
from zipline.finance.blotter import Order

            },
            'event': {
                'dt': pd.Timestamp('2006-01-05 14:31', tz='UTC'),
                'volume': 2000,
                'price': 3.0,
                'high': 3.15,
                'low': 2.85,
                'sid': 133,
                'close': 3.0,
                'open': 3.0
            },
            'expected': {
                'transaction': {
                    'price': 2.99925,
                    'dt': pd.Timestamp('2006-01-05 14:31', tz='UTC'),
                    'amount': -100,
                    'sid': 133,
                }
            }
        },
    }

    @parameterized.expand([
        (name, case['order'], case['event'], case['expected'])
        for name, case in STOP_ORDER_CASES.items()
    ])
    def test_orders_stop(self, name, order_data, event_data, expected):
        order = Order(**order_data)
        event = Event(initial_values=event_data)


        slippage_model = VolumeShareSlippage()