# 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 logbook
import numpy as np
import alephnull.utils.math_utils as zp_math
from alephnull.finance import trading
            beta value for the same period as all other values

    Returns:
        float. The alpha of the algorithm.
    """
    return algorithm_period_return - \
        (treasury_period_return + beta *
         (benchmark_period_returns - treasury_period_return))

###########################
# End Risk Metric Section #
###########################


def get_treasury_rate(treasury_curves, treasury_duration, day):
    rate = None

    curve = treasury_curves.ix[day]
    # 1month note data begins in 8/2001,
    # so we can use 3month instead.
    idx = TREASURY_DURATIONS.index(treasury_duration)
    for duration in TREASURY_DURATIONS[idx:]:
        rate = curve[duration]
        if rate is not None:
            break

    return rate


def search_day_distance(end_date, dt):

# 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/risk.py
import logbook
import numpy as np
import alephnull.utils.math_utils as zp_math
from alephnull.finance import trading

            beta value for the same period as all other values

    Returns:
        float. The alpha of the algorithm.
    """
    return algorithm_period_return - \
        (treasury_period_return + beta *
         (benchmark_period_returns - treasury_period_return))

###########################
# End Risk Metric Section #
###########################


def get_treasury_rate(treasury_curves, treasury_duration, day):
    rate = None

    curve = treasury_curves.ix[day]
    # 1month note data begins in 8/2001,
    # so we can use 3month instead.
    idx = TREASURY_DURATIONS.index(treasury_duration)
    for duration in TREASURY_DURATIONS[idx:]:
        rate = curve[duration]
        if rate is not None:
            break

    return rate


def search_day_distance(end_date, dt):

    tdd = trading.environment.trading_day_distance(dt, end_date)