示例#1
0
    def calc_multiple_wing_models(option_data_list, spots, observed_date,
                                  contract_type, days_in_year, holidays,
                                  bounds_dict):
        try:
            underlyer_expire_dict = {}
            # TODO Q(分红)值默认为0
            q_value = 0
            for item in spots:
                underlyer_expire_dict[item.underlyer] = {
                    **underlyer_expire_dict.get(item.underlyer, {}),
                    **({
                        item.effectiveDays: item.spot
                    })
                }
            # underlyer_expire_dict = sorted(underlier_expire_dict.items(), key=lambda x:x[1].keys())
            # x : strikePrice y : expiredate z :implied vol
            # option_data : 标的物为key的dict
            # expire_days: 出现过的失效日期
            # spot: 失效日期为key的value
            # 计算R-Q
            bound_dict = WingModelDataAlgo.bound_gen(
                bounds_dict[contract_type])

            wing_model_list = []
            for underlyer, expire_days in underlyer_expire_dict.items():
                for expiry in expire_days.keys():
                    effective_days_num = DateTimeUtils.get_effective_days_num(
                        observed_date, expiry, holidays)
                    tau = effective_days_num / days_in_year
                    dto_wing_model = WingModelAlgo.calc_one_wing_model(
                        tau, underlyer, option_data_list, expire_days[expiry],
                        q_value, bound_dict)
                    dto_wing_model.underlyer = underlyer
                    dto_wing_model.tenor = str(effective_days_num) + 'D'
                    dto_wing_model.daysInYear = days_in_year
                    dto_wing_model.expiry = expiry
                    wing_model_list.append(dto_wing_model)
            return wing_model_list
        except Exception as ex:
            logging.error(ex)
示例#2
0
 def get_effective_days_num(db_session, start_date, end_date):
     holidays = TradingDayService.get_holiday_list(db_session)
     return DateTimeUtils.get_effective_days_num(start_date, end_date,
                                                 holidays)