# Path: alphaware/utils/date_utils.py
# @expect_types(start_date=(str, datetime), end_date=(str, datetime), freq=(str, FreqType))
# def get_tiaocang_date(start_date, end_date, freq=FreqType.EOM, calendar='China.SSE', date_format='%Y-%m-%d'):
#     """
#     :param start_date: str/datetime.datetime, 开始日期
#     :param end_date: str/datetime.datetime, 结束日期
#     :param freq: str enum, default=EOM, 月度
#     :param calendar: str, 日历名称
#     :param date_format: str, start_date/end_date 如果是str格式，其格式的日期形式
#     :return: list, datetime.datetime
#     返回在开始日至结束日之间的调仓日(交易日)
#     """
#     calendar = calendar
#     date_format = date_format
#     start_date = ensure_pyfin_date(start_date, date_format)
#     end_date = ensure_pyfin_date(end_date, date_format)
# 
#     cal = Calendar(calendar)
#     tiaocang_date = Schedule(start_date,
#                              end_date,
#                              Period('1' + freq),
#                              cal,
#                              BizDayConventions.Unadjusted)
# 
#     if freq.upper() == FreqType.EOW:
#         tiaocang_date = [Date.nextWeekday(date, Weekdays.Friday) for date in tiaocang_date]
#     elif freq.upper() == FreqType.EOM:
#         tiaocang_date = [cal.endOfMonth(date) for date in tiaocang_date]
#     elif freq.upper() == FreqType.EOY:
#         tiaocang_date = [Date(date.year(), 12, 31) for date in tiaocang_date]
# 
#     tiaocang_date = [cal.adjustDate(date, BizDayConventions.Preceding).toDateTime() for date in tiaocang_date if
#                      start_date <= date <= end_date]
# 
#     return sorted(set(tiaocang_date))
# 
# Path: alphaware/utils/input_validation.py
# def ensure_cumul_return(func, argname, arg):
#     if not isinstance(arg, RETURN):
#         return arg
#     if arg.type == ReturnType.Cumul:
#         return arg.data
#     else:
#         data_ = cum_returns(arg.data, starting_value=1.0)
#         return data_
# 
# def ensure_noncumul_return(func, argname, arg):
#     if not isinstance(arg, RETURN):
#         return arg
#     if arg.type == ReturnType.Non_Cumul:
#         return arg.data
#     else:
#         data_ = arg.data.pct_change()
#         data_.dropna(inplace=True)
#         return data_
# 
# Path: alphaware/enums.py
# class FreqType(StrEnum):
#     EOD = 'D'
#     EOW = 'W'
#     EOM = 'M'
#     EOQ = 'Q'
#     EOSY = 'S'
#     EOY = 'Y'
# 
# Path: alphaware/const.py
# RETURN = namedtuple('RETURN', ['data', 'type'])
# 
# Path: alphaware/utils/input_validation.py
# def ensure_cumul_return(func, argname, arg):
#     if not isinstance(arg, RETURN):
#         return arg
#     if arg.type == ReturnType.Cumul:
#         return arg.data
#     else:
#         data_ = cum_returns(arg.data, starting_value=1.0)
#         return data_
# 
# def ensure_noncumul_return(func, argname, arg):
#     if not isinstance(arg, RETURN):
#         return arg
#     if arg.type == ReturnType.Non_Cumul:
#         return arg.data
#     else:
#         data_ = arg.data.pct_change()
#         data_.dropna(inplace=True)
#         return data_
# 
# Path: alphaware/const.py
# RETURN = namedtuple('RETURN', ['data', 'type'])
# 
# Path: alphaware/enums.py
# class ReturnType(IntEnum):
#     Non_Cumul = 0
#     Cumul = 1


from alphaware.utils import (get_tiaocang_date,
                             ensure_noncumul_return,
                             ensure_cumul_return)
from alphaware.enums import FreqType
from alphaware.const import RETURN
from argcheck import preprocess
from alphaware.utils import (ensure_noncumul_return,
                             ensure_cumul_return)
from alphaware.const import RETURN
from alphaware.enums import ReturnType
import pandas as pd
# -*- coding: utf-8 -*-



print get_tiaocang_date(start_date='2016-01-01', end_date='2016-3-31', freq=FreqType.EOM)

# [datetime.datetime(2016, 1, 29, 0, 0), datetime.datetime(2016, 2, 29, 0, 0), datetime.datetime(2016, 3, 31, 0, 0)]

print get_tiaocang_date(start_date='2017/1/1', end_date='2017/2/1', freq=FreqType.EOW, date_format='%Y/%m/%d')

# [datetime.datetime(2017, 1, 6, 0, 0), datetime.datetime(2017, 1, 13, 0, 0), datetime.datetime(2017, 1, 20, 0, 0),
#  datetime.datetime(2017, 1, 26, 0, 0)]



# 定义一个累积收益率序列
ret = RETURN(data=pd.Series([1.0, 1.0, 1.05, 1.1],
                            index=['2010-01-02', '2010-01-03', '2010-01-04', '2010-01-05']), type=ReturnType.Cumul)


# 假如用使用日频收益序列，只要结合argcheck.preprocess和ensure_noncumul_return即可

# Path: alphaware/utils/date_utils.py
# @expect_types(start_date=(str, datetime), end_date=(str, datetime), freq=(str, FreqType))
# def get_tiaocang_date(start_date, end_date, freq=FreqType.EOM, calendar='China.SSE', date_format='%Y-%m-%d'):
#     """
#     :param start_date: str/datetime.datetime, 开始日期
#     :param end_date: str/datetime.datetime, 结束日期
#     :param freq: str enum, default=EOM, 月度
#     :param calendar: str, 日历名称
#     :param date_format: str, start_date/end_date 如果是str格式，其格式的日期形式
#     :return: list, datetime.datetime
#     返回在开始日至结束日之间的调仓日(交易日)
#     """
#     calendar = calendar
#     date_format = date_format
#     start_date = ensure_pyfin_date(start_date, date_format)
#     end_date = ensure_pyfin_date(end_date, date_format)
# 
#     cal = Calendar(calendar)
#     tiaocang_date = Schedule(start_date,
#                              end_date,
#                              Period('1' + freq),
#                              cal,
#                              BizDayConventions.Unadjusted)
# 
#     if freq.upper() == FreqType.EOW:
#         tiaocang_date = [Date.nextWeekday(date, Weekdays.Friday) for date in tiaocang_date]
#     elif freq.upper() == FreqType.EOM:
#         tiaocang_date = [cal.endOfMonth(date) for date in tiaocang_date]
#     elif freq.upper() == FreqType.EOY:
#         tiaocang_date = [Date(date.year(), 12, 31) for date in tiaocang_date]
# 
#     tiaocang_date = [cal.adjustDate(date, BizDayConventions.Preceding).toDateTime() for date in tiaocang_date if
#                      start_date <= date <= end_date]
# 
#     return sorted(set(tiaocang_date))
# 
# Path: alphaware/utils/input_validation.py
# def ensure_cumul_return(func, argname, arg):
#     if not isinstance(arg, RETURN):
#         return arg
#     if arg.type == ReturnType.Cumul:
#         return arg.data
#     else:
#         data_ = cum_returns(arg.data, starting_value=1.0)
#         return data_
# 
# def ensure_noncumul_return(func, argname, arg):
#     if not isinstance(arg, RETURN):
#         return arg
#     if arg.type == ReturnType.Non_Cumul:
#         return arg.data
#     else:
#         data_ = arg.data.pct_change()
#         data_.dropna(inplace=True)
#         return data_
# 
# Path: alphaware/enums.py
# class FreqType(StrEnum):
#     EOD = 'D'
#     EOW = 'W'
#     EOM = 'M'
#     EOQ = 'Q'
#     EOSY = 'S'
#     EOY = 'Y'
# 
# Path: alphaware/const.py
# RETURN = namedtuple('RETURN', ['data', 'type'])
# 
# Path: alphaware/utils/input_validation.py
# def ensure_cumul_return(func, argname, arg):
#     if not isinstance(arg, RETURN):
#         return arg
#     if arg.type == ReturnType.Cumul:
#         return arg.data
#     else:
#         data_ = cum_returns(arg.data, starting_value=1.0)
#         return data_
# 
# def ensure_noncumul_return(func, argname, arg):
#     if not isinstance(arg, RETURN):
#         return arg
#     if arg.type == ReturnType.Non_Cumul:
#         return arg.data
#     else:
#         data_ = arg.data.pct_change()
#         data_.dropna(inplace=True)
#         return data_
# 
# Path: alphaware/const.py
# RETURN = namedtuple('RETURN', ['data', 'type'])
# 
# Path: alphaware/enums.py
# class ReturnType(IntEnum):
#     Non_Cumul = 0
#     Cumul = 1


# Path: alphaware/examples/utils_funcs.py
from alphaware.utils import (get_tiaocang_date,
                             ensure_noncumul_return,
                             ensure_cumul_return)
from alphaware.enums import FreqType
from alphaware.const import RETURN
from argcheck import preprocess
from alphaware.utils import (ensure_noncumul_return,
                             ensure_cumul_return)
from alphaware.const import RETURN
from alphaware.enums import ReturnType
import pandas as pd

# -*- coding: utf-8 -*-



print get_tiaocang_date(start_date='2016-01-01', end_date='2016-3-31', freq=FreqType.EOM)

# [datetime.datetime(2016, 1, 29, 0, 0), datetime.datetime(2016, 2, 29, 0, 0), datetime.datetime(2016, 3, 31, 0, 0)]

print get_tiaocang_date(start_date='2017/1/1', end_date='2017/2/1', freq=FreqType.EOW, date_format='%Y/%m/%d')

# [datetime.datetime(2017, 1, 6, 0, 0), datetime.datetime(2017, 1, 13, 0, 0), datetime.datetime(2017, 1, 20, 0, 0),
#  datetime.datetime(2017, 1, 26, 0, 0)]



# 定义一个累积收益率序列
ret = RETURN(data=pd.Series([1.0, 1.0, 1.05, 1.1],
                            index=['2010-01-02', '2010-01-03', '2010-01-04', '2010-01-05']), type=ReturnType.Cumul)


# 假如用使用日频收益序列，只要结合argcheck.preprocess和ensure_noncumul_return即可

@preprocess(data=ensure_noncumul_return)