# 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
try:
except:
    #Replace this with source to multiplier
    get_multiplier = lambda x: 25

log = logbook.Logger('Performance')


class FuturesPerformancePeriod(object):
    def __init__(
            self,
            starting_cash,
            period_open=None,
            period_close=None,
            keep_transactions=True,
            keep_orders=False,
            serialize_positions=True):

        # * #
        self.starting_mav = starting_cash
        self.ending_mav = starting_cash
        self.cash_adjustment = 0
        self.ending_total_value = 0.0
        self.pnl = 0.0
        # ** #

        self.period_open = period_open
        self.period_close = period_close

        # sid => position object

# 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

try:
except:
    #Replace this with source to multiplier
    get_multiplier = lambda x: 25

log = logbook.Logger('Performance')


class FuturesPerformancePeriod(object):
    def __init__(
            self,
            starting_cash,
            period_open=None,
            period_close=None,
            keep_transactions=True,
            keep_orders=False,
            serialize_positions=True):

        # * #
        self.starting_mav = starting_cash
        self.ending_mav = starting_cash
        self.cash_adjustment = 0
        self.ending_total_value = 0.0
        self.pnl = 0.0
        # ** #

        self.period_open = period_open
        self.period_close = period_close

        # sid => position object

        self.positions = positiondict()