# Path: alephnull/finance/trading.py
# class TradingEnvironment(object):
# class SimulationParameters(object):
#     def __init__(
#         self,
#         load=None,
#         bm_symbol='^GSPC',
#         exchange_tz="US/Eastern",
#         max_date=None,
#         extra_dates=None
#     ):
#     def __enter__(self, *args, **kwargs):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def normalize_date(self, test_date):
#     def utc_dt_in_exchange(self, dt):
#     def exchange_dt_in_utc(self, dt):
#     def is_market_hours(self, test_date):
#     def is_trading_day(self, test_date):
#     def next_trading_day(self, test_date):
#     def days_in_range(self, start, end):
#     def next_open_and_close(self, start_date):
#     def get_open_and_close(self, day):
#     def market_minutes_for_day(self, midnight):
#     def trading_day_distance(self, first_date, second_date):
#     def get_index(self, dt):
#     def __init__(self, period_start, period_end,
#                  capital_base=10e3,
#                  emission_rate='daily',
#                  data_frequency='daily'):
#     def calculate_first_open(self):
#     def calculate_last_close(self):
#     def days_in_period(self):
#     def __repr__(self):


import functools
import logbook
import math
import numpy as np
import alephnull.utils.math_utils as zp_math
import pandas as pd
from alephnull.finance import trading
from pandas.tseries.tools import normalize_date
from . risk import (
    alpha,
    check_entry,
    choose_treasury,
)
        # The returns at a given time are read and reset from the respective
        # returns container.
        self.algorithm_returns = None
        self.benchmark_returns = None
        self.mean_returns = None
        self.annualized_mean_returns = None
        self.mean_benchmark_returns = None
        self.annualized_benchmark_returns = None

        self.compounded_log_returns = pd.Series(index=cont_index)
        self.algorithm_period_returns = pd.Series(index=cont_index)
        self.benchmark_period_returns = pd.Series(index=cont_index)
        self.excess_returns = pd.Series(index=cont_index)

        self.latest_dt = cont_index[0]

        self.metrics = pd.DataFrame(index=cont_index,
                                    columns=self.METRIC_NAMES)

        self.max_drawdown = 0
        self.current_max = -np.inf
        self.daily_treasury = pd.Series(index=self.trading_days)

    def get_minute_index(self, sim_params):
        """
        Stitches together multiple days worth of business minutes into
        one continous index.
        """
        trading_minutes = None
        for day in self.trading_days:

# Path: alephnull/finance/trading.py
# class TradingEnvironment(object):
# class SimulationParameters(object):
#     def __init__(
#         self,
#         load=None,
#         bm_symbol='^GSPC',
#         exchange_tz="US/Eastern",
#         max_date=None,
#         extra_dates=None
#     ):
#     def __enter__(self, *args, **kwargs):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def normalize_date(self, test_date):
#     def utc_dt_in_exchange(self, dt):
#     def exchange_dt_in_utc(self, dt):
#     def is_market_hours(self, test_date):
#     def is_trading_day(self, test_date):
#     def next_trading_day(self, test_date):
#     def days_in_range(self, start, end):
#     def next_open_and_close(self, start_date):
#     def get_open_and_close(self, day):
#     def market_minutes_for_day(self, midnight):
#     def trading_day_distance(self, first_date, second_date):
#     def get_index(self, dt):
#     def __init__(self, period_start, period_end,
#                  capital_base=10e3,
#                  emission_rate='daily',
#                  data_frequency='daily'):
#     def calculate_first_open(self):
#     def calculate_last_close(self):
#     def days_in_period(self):
#     def __repr__(self):


# Path: alephnull/finance/risk/cumulative.py
import functools
import logbook
import math
import numpy as np
import alephnull.utils.math_utils as zp_math
import pandas as pd
from alephnull.finance import trading
from pandas.tseries.tools import normalize_date
from . risk import (
    alpha,
    check_entry,
    choose_treasury,
)

        # The returns at a given time are read and reset from the respective
        # returns container.
        self.algorithm_returns = None
        self.benchmark_returns = None
        self.mean_returns = None
        self.annualized_mean_returns = None
        self.mean_benchmark_returns = None
        self.annualized_benchmark_returns = None

        self.compounded_log_returns = pd.Series(index=cont_index)
        self.algorithm_period_returns = pd.Series(index=cont_index)
        self.benchmark_period_returns = pd.Series(index=cont_index)
        self.excess_returns = pd.Series(index=cont_index)

        self.latest_dt = cont_index[0]

        self.metrics = pd.DataFrame(index=cont_index,
                                    columns=self.METRIC_NAMES)

        self.max_drawdown = 0
        self.current_max = -np.inf
        self.daily_treasury = pd.Series(index=self.trading_days)

    def get_minute_index(self, sim_params):
        """
        Stitches together multiple days worth of business minutes into
        one continous index.
        """
        trading_minutes = None
        for day in self.trading_days:

            minutes_for_day = trading.environment.market_minutes_for_day(day)