# Path: zipline/finance/slippage.py
# class Transaction(object):
# 
#     def __init__(self, sid, amount, dt, price, order_id, commission=None):
#         self.sid = sid
#         self.amount = amount
#         self.dt = dt
#         self.price = price
#         self.order_id = order_id
#         self.commission = commission
#         self.type = DATASOURCE_TYPE.TRANSACTION
# 
#     def __getitem__(self, name):
#         return self.__dict__[name]
# 
#     def to_dict(self):
#         py = copy(self.__dict__)
#         del py['type']
#         return py
# 
# def create_transaction(event, order, price, amount):
# 
#     # floor the amount to protect against non-whole number orders
#     # TODO: Investigate whether we can add a robust check in blotter
#     # and/or tradesimulation, as well.
#     amount_magnitude = int(abs(amount))
# 
#     if amount_magnitude < 1:
#         raise Exception("Transaction magnitude must be at least 1.")
# 
#     transaction = Transaction(
#         sid=event.sid,
#         amount=int(amount),
#         dt=event.dt,
#         price=price,
#         order_id=order.id
#     )
# 
#     return transaction


import collections
import heapq
import logging
import operator
import unittest
import datetime
import pytz
import itertools
import zipline.utils.factory as factory
import zipline.finance.performance as perf
import zipline.utils.math_utils as zp_math
import zipline.protocol
from nose_parameterized import parameterized
from zipline.finance.slippage import Transaction, create_transaction
from zipline.gens.composites import date_sorted_sources
from zipline.finance.trading import SimulationParameters
from zipline.finance.blotter import Order
from zipline.finance import trading
from zipline.protocol import DATASOURCE_TYPE
from zipline.utils.factory import create_random_simulation_parameters
from zipline.protocol import Event
                    amount=-25,
                    dt=event.dt,
                    price=10.0,
                    commission=0.50,
                    order_id=order.id
                )
                yield txn
            else:
                yield event

    def test_minute_tracker(self):
        """ Tests minute performance tracking."""
        with trading.TradingEnvironment():
            start_dt = trading.environment.exchange_dt_in_utc(
                datetime.datetime(2013, 3, 1, 9, 31))
            end_dt = trading.environment.exchange_dt_in_utc(
                datetime.datetime(2013, 3, 1, 16, 0))

            sim_params = SimulationParameters(
                period_start=start_dt,
                period_end=end_dt,
                emission_rate='minute'
            )
            tracker = perf.PerformanceTracker(sim_params)

            foo_event_1 = factory.create_trade('foo', 10.0, 20, start_dt)
            order_event_1 = Order(sid=foo_event_1.sid,
                                  amount=-25,
                                  dt=foo_event_1.dt)
            bar_event_1 = factory.create_trade('bar', 100.0, 200, start_dt)

# Path: zipline/finance/slippage.py
# class Transaction(object):
# 
#     def __init__(self, sid, amount, dt, price, order_id, commission=None):
#         self.sid = sid
#         self.amount = amount
#         self.dt = dt
#         self.price = price
#         self.order_id = order_id
#         self.commission = commission
#         self.type = DATASOURCE_TYPE.TRANSACTION
# 
#     def __getitem__(self, name):
#         return self.__dict__[name]
# 
#     def to_dict(self):
#         py = copy(self.__dict__)
#         del py['type']
#         return py
# 
# def create_transaction(event, order, price, amount):
# 
#     # floor the amount to protect against non-whole number orders
#     # TODO: Investigate whether we can add a robust check in blotter
#     # and/or tradesimulation, as well.
#     amount_magnitude = int(abs(amount))
# 
#     if amount_magnitude < 1:
#         raise Exception("Transaction magnitude must be at least 1.")
# 
#     transaction = Transaction(
#         sid=event.sid,
#         amount=int(amount),
#         dt=event.dt,
#         price=price,
#         order_id=order.id
#     )
# 
#     return transaction


# Path: tests/test_perf_tracking.py
import collections
import heapq
import logging
import operator
import unittest
import datetime
import pytz
import itertools
import zipline.utils.factory as factory
import zipline.finance.performance as perf
import zipline.utils.math_utils as zp_math
import zipline.protocol
from nose_parameterized import parameterized
from zipline.finance.slippage import Transaction, create_transaction
from zipline.gens.composites import date_sorted_sources
from zipline.finance.trading import SimulationParameters
from zipline.finance.blotter import Order
from zipline.finance import trading
from zipline.protocol import DATASOURCE_TYPE
from zipline.utils.factory import create_random_simulation_parameters
from zipline.protocol import Event

                    amount=-25,
                    dt=event.dt,
                    price=10.0,
                    commission=0.50,
                    order_id=order.id
                )
                yield txn
            else:
                yield event

    def test_minute_tracker(self):
        """ Tests minute performance tracking."""
        with trading.TradingEnvironment():
            start_dt = trading.environment.exchange_dt_in_utc(
                datetime.datetime(2013, 3, 1, 9, 31))
            end_dt = trading.environment.exchange_dt_in_utc(
                datetime.datetime(2013, 3, 1, 16, 0))

            sim_params = SimulationParameters(
                period_start=start_dt,
                period_end=end_dt,
                emission_rate='minute'
            )
            tracker = perf.PerformanceTracker(sim_params)

            foo_event_1 = factory.create_trade('foo', 10.0, 20, start_dt)
            order_event_1 = Order(sid=foo_event_1.sid,
                                  amount=-25,
                                  dt=foo_event_1.dt)
            bar_event_1 = factory.create_trade('bar', 100.0, 200, start_dt)

            txn_event_1 = Transaction(sid=foo_event_1.sid,