# Path: alephnull/finance/performance/position.py
# class positiondict(dict):
# 
#     def __missing__(self, key):
#         if type(key) is tuple:
#             pos = Position(key[0], contract=key[1])
#         else:
#             pos = Position(key)
#         self[key] = pos
#         return pos


import math
import logbook
import numpy as np
import pandas as pd
import alephnull.protocol as zp
from collections import OrderedDict, defaultdict
from .position import positiondict
    from alephtools.connection import get_multiplier
        self.period_open = period_open
        self.period_close = period_close

        # sid => position object
        self.positions = positiondict()
        # rollover initializes a number of self's attributes:
        self.rollover()
        self.keep_transactions = keep_transactions
        self.keep_orders = keep_orders

        # Arrays for quick calculations of positions value
        self._position_amounts = pd.Series()
        self._position_last_sale_prices = pd.Series()

        self.calculate_performance()

        # An object to recycle via assigning new values
        # when returning portfolio information.
        # So as not to avoid creating a new object for each event
        self._portfolio_store = zp.Portfolio()
        self._positions_store = zp.Positions()
        self.serialize_positions = serialize_positions

    def rollover(self):
        # * #
        self.starting_mav = self.ending_mav
        self.cash_adjustment = 0
        self.pnl = 0.0
        # ** #


# Path: alephnull/finance/performance/position.py
# class positiondict(dict):
# 
#     def __missing__(self, key):
#         if type(key) is tuple:
#             pos = Position(key[0], contract=key[1])
#         else:
#             pos = Position(key)
#         self[key] = pos
#         return pos


# Path: alephnull/finance/performance/futures_period.py
import math
import logbook
import numpy as np
import pandas as pd
import alephnull.protocol as zp
from collections import OrderedDict, defaultdict
from .position import positiondict
    from alephtools.connection import get_multiplier

        self.period_open = period_open
        self.period_close = period_close

        # sid => position object
        self.positions = positiondict()
        # rollover initializes a number of self's attributes:
        self.rollover()
        self.keep_transactions = keep_transactions
        self.keep_orders = keep_orders

        # Arrays for quick calculations of positions value
        self._position_amounts = pd.Series()
        self._position_last_sale_prices = pd.Series()

        self.calculate_performance()

        # An object to recycle via assigning new values
        # when returning portfolio information.
        # So as not to avoid creating a new object for each event
        self._portfolio_store = zp.Portfolio()
        self._positions_store = zp.Positions()
        self.serialize_positions = serialize_positions

    def rollover(self):
        # * #
        self.starting_mav = self.ending_mav
        self.cash_adjustment = 0
        self.pnl = 0.0
        # ** #


        self.processed_transactions = defaultdict(list)