# Path: kquant_data/option/info.py
# def get_opt_info_filtered_by_date(df_info, date):
#     # date = '2018-03-04'  # 指定日期
#     # call_or_put = 'C'  # 指定类别
#     # limit_month = 1806  # 指定月份
#     # limit_month_m = 'A'  # 指定月份2
#     df_filtered = df_info[(df_info['listed_date'] <= date)
#                           & (df_info['expire_date'] >= date)]
#     return df_filtered
# 
# def get_opt_info_filtered_by_month(df_info, limit_month):
#     df_filtered = df_info[
#         (df_info['limit_month'] == limit_month)]
#     return df_filtered
# 
# def get_opt_info_filtered_by_call_or_put(df_info, call_or_put):
#     df_filtered = df_info[
#         (df_info['call_or_put'] == call_or_put)]
#     return df_filtered


import numpy as np
from .info import get_opt_info_filtered_by_date, get_opt_info_filtered_by_month, \
    get_opt_info_filtered_by_call_or_put
"""



def func_select_instrument_by_signal(row, field, _open, df_info, month_index, atm_index):
    """
    # 用开盘价来选要交易的合约代码
    long_short_opt = long_short_enter.apply(func_select_instrument_by_signal, axis=1,
                                            args=('SZ50', Open, df_info, 3, 1))
    long_short_opt.set_index(['index_datetime'], inplace=True)

    由于比较特别，还是需要用户自己选才行
    :param row: 每行信号
    :param field: 信号在当前数据中的字段名
    :param _open: 交易当天的开盘价
    :param df_info: 期权合约信息表，将通过etf行情和执行价选出实虚合约
    :param month_index: 选出当月、次月、当季、次季
    :param atm_index: 选出虚几
    :return:
    """
    signal = row[field]
    if np.isnan(signal):
        return row
    if signal == 0:
        row[field] = np.nan
        return row
    # 取指定日期的数据
    date = row['index_datetime'].strftime("%Y-%m-%d")  # 指定日期

    # 2015-05-29号，5月份的合约已经结束，应当切换成6月才行

# Path: kquant_data/option/info.py
# def get_opt_info_filtered_by_date(df_info, date):
#     # date = '2018-03-04'  # 指定日期
#     # call_or_put = 'C'  # 指定类别
#     # limit_month = 1806  # 指定月份
#     # limit_month_m = 'A'  # 指定月份2
#     df_filtered = df_info[(df_info['listed_date'] <= date)
#                           & (df_info['expire_date'] >= date)]
#     return df_filtered
# 
# def get_opt_info_filtered_by_month(df_info, limit_month):
#     df_filtered = df_info[
#         (df_info['limit_month'] == limit_month)]
#     return df_filtered
# 
# def get_opt_info_filtered_by_call_or_put(df_info, call_or_put):
#     df_filtered = df_info[
#         (df_info['call_or_put'] == call_or_put)]
#     return df_filtered


# Path: kquant_data/option/strategy.py
import numpy as np
from .info import get_opt_info_filtered_by_date, get_opt_info_filtered_by_month, \
    get_opt_info_filtered_by_call_or_put

"""



def func_select_instrument_by_signal(row, field, _open, df_info, month_index, atm_index):
    """
    # 用开盘价来选要交易的合约代码
    long_short_opt = long_short_enter.apply(func_select_instrument_by_signal, axis=1,
                                            args=('SZ50', Open, df_info, 3, 1))
    long_short_opt.set_index(['index_datetime'], inplace=True)

    由于比较特别，还是需要用户自己选才行
    :param row: 每行信号
    :param field: 信号在当前数据中的字段名
    :param _open: 交易当天的开盘价
    :param df_info: 期权合约信息表，将通过etf行情和执行价选出实虚合约
    :param month_index: 选出当月、次月、当季、次季
    :param atm_index: 选出虚几
    :return:
    """
    signal = row[field]
    if np.isnan(signal):
        return row
    if signal == 0:
        row[field] = np.nan
        return row
    # 取指定日期的数据
    date = row['index_datetime'].strftime("%Y-%m-%d")  # 指定日期

    # 2015-05-29号，5月份的合约已经结束，应当切换成6月才行

    df_filtered = get_opt_info_filtered_by_date(df_info, date)