예제 #1
0
 def __init__(self, object_name_str=''):
     super(FxCurve, self).__init__(object_name_str)
     self._calendar_ = TAR()
     self._b_days_to_settle_ = 2  # fixme do better
     self._spot_ = FxSpot(1.0)
     self._dom_curr_curve_ = YieldCurveInterface()
     self._for_curr_curve_ = YieldCurveInterface()
예제 #2
0
class FxCurve(FxCurveInterface):
    """ _fx_curve_ object """
    def __init__(self, object_name_str=''):
        super(FxCurve, self).__init__(object_name_str)
        self._calendar_ = TAR()
        self._b_days_to_settle_ = 2  # fixme do better
        self._spot_ = FxSpot(1.0)
        self._dom_curr_curve_ = YieldCurveInterface()
        self._for_curr_curve_ = YieldCurveInterface()

    def get_value(self, reset_date):
        """
        :param reset_date:
        :param base_date:
        :return float:
        """
        settle_date = self._origin_.add_business_days(self._b_days_to_settle_,
                                                      self._calendar_)
        reset_modified = reset_date.add_business_days(self._b_days_to_settle_,
                                                      self._calendar_)
        df_foreign = self._for_curr_curve_.get_discount_factor(
            settle_date, reset_modified)
        df_domestic = self._dom_curr_curve_.get_discount_factor(
            settle_date, reset_modified)
        ret = self._spot_ * df_foreign / df_domestic
        return ret
예제 #3
0
class ScenarioYieldCurve(ScenarioFactor, YieldCurveInterface):
    """ scenarios for YieldCurveInterface """

    def __init__(self, object_name_str=''):
        super(ScenarioYieldCurve, self).__init__(object_name_str)
        self._inner_factor_ = YieldCurveInterface()
        self._driving_factor_ = YieldCurveInterface()

    def _rebuild_object(self):
        super(ScenarioYieldCurve, self)._rebuild_object()
        self._spread = self._inner_factor_.curve
        self._spread -= self._driving_factor_.curve.curve

    def get_zero_rate(self, start_date, end_date):
        """
        calculates zero rate

        :param BusinessDate end_date:
        :param BusinessDate start_date:
        :return float:
        """
        start_date, end_date = self._cast_to_dates(start_date, end_date)

        zero_rate = self._driving_factor_.get_zero_rate(start_date, end_date)
        zero_rate += self._spread.get_zero_rate(start_date, end_date)
        return zero_rate

    def get_discount_factor(self, start_date, end_date):
        """
        calculates discount factor

        :param BusinessDate start_date: date to discount to
        :param BusinessDate end_date: date to discount from
        :return float: discount factor
        """
        start_date, end_date = self._cast_to_dates(start_date, end_date)

        discount_factor = self._driving_factor_.get_discount_factor(start_date, end_date)
        discount_factor *= self._spread.get_discount_factor(start_date, end_date)
        return discount_factor
예제 #4
0
class HullWhiteCurve(RiskFactor, YieldCurveInterface):
    """ HullWhiteCurve """
    @property
    def curve(self):
        """ inner curve """
        return self._curve_

    @property
    def domain(self):
        """ list of grid date of curve """
        return list(self.curve.domain)

    def __init__(self, object_name_str=''):
        super(HullWhiteCurve, self).__init__(object_name_str)
        self._curve_ = YieldCurveInterface()
        self._mean_reversion_ = 0.01
        self._volatility_ = 0.02
        self._hull_white_curve = _HullWhiteCurve([0.0], [0.0])

    def _rebuild_object(self):
        super(HullWhiteCurve, self)._rebuild_object()
        hw = _HullWhiteCurve.cast(self._curve_.curve, self._mean_reversion_,
                                  self._volatility_)
        self._hull_white_curve = hw

    def _day_count(self, start_date, end_date):
        return self._curve_._day_count(start_date, end_date)

    def set_risk_factor(self, factor_date, factor_value):
        """ set risk factor

        :param factor_date:
        :param factor_value:
        """
        self._risk_factor_state = factor_value
        self._risk_factor_date = factor_date
        self._hull_white_curve.set_risk_factor(factor_date, factor_value)

    def get_discount_factor(self, start_date, end_date):
        """ get discount factor

        :param start_date:
        :param end_date:
        :return:
        """
        return self._hull_white_curve.get_discount_factor(start_date, end_date)
예제 #5
0
 def __init__(self, object_name_str=''):
     super(DependentYieldCurve, self).__init__(object_name_str)
     self._inner_factor_ = YieldCurveInterface()
     self._driving_factor_ = YieldCurveInterface()
     self._domain = list()
     self._spread = DateCurve([20151231, 20660101], [0, 0])
예제 #6
0
class DependentYieldCurve(DependentFactor, YieldCurveInterface):
    """ Yieldcurves that depend on a driving force"""
    @property
    def domain(self):
        return self._domain

    def _day_count(self, start_date, end_date):
        return self._inner_factor_._day_count(start_date, end_date)

    def __init__(self, object_name_str=''):
        super(DependentYieldCurve, self).__init__(object_name_str)
        self._inner_factor_ = YieldCurveInterface()
        self._driving_factor_ = YieldCurveInterface()
        self._domain = list()
        self._spread = DateCurve([20151231, 20660101], [0, 0])

    def _rebuild_object(self):
        super(DependentYieldCurve, self)._rebuild_object()
        self._domain = sorted(
            list(
                set(self._inner_factor_.domain).union(
                    set(self._driving_factor_.domain))))
        self._origin_ = self._driving_factor_.origin

        spread_values_on_domain = [
            self._inner_factor_.get_zero_rate(self._inner_factor_.origin, d) -
            self._driving_factor_.get_zero_rate(self._driving_factor_.origin,
                                                d) for d in self.domain
        ]

        self._spread = DateCurve(self.domain,
                                 spread_values_on_domain,
                                 day_count=self._day_count)

    def get_zero_rate(self, start_date, end_date):
        """
        calculates zero rate

        :param BusinessDate end_date:
        :param BusinessDate start_date:
        :return float:
        """
        start_date, end_date = self._inner_factor_._cast_to_dates(
            start_date, end_date)

        origin = self._inner_factor_.origin
        daycount = self._day_count(start_date, end_date)
        'tZ = daycount(0,t)*(driving_Zerorate(t)+Zero_spread(t))'
        eZ = self._day_count(origin, end_date)*\
             (self._driving_factor_.get_zero_rate(origin, end_date)+self._spread(end_date))
        if start_date != origin:
            sZ = self._day_count(origin, start_date)*\
                (self._driving_factor_.get_zero_rate(origin, start_date)+ self._spread(start_date))
        else:
            sZ = 0

        return 1 / daycount * (eZ - sZ) if daycount != 0 else 0

    def get_discount_factor(self, start_date, end_date):
        """
        calculates discount factor

        :param BusinessDate start_date: date to discount to
        :param BusinessDate end_date: date to discount from
        :return float: discount factor
        """
        start_date, end_date = self._inner_factor_._cast_to_dates(
            start_date, end_date)
        return exp(-1 * self._day_count(start_date, end_date) *
                   self.get_zero_rate(start_date, end_date))
예제 #7
0
 def __init__(self, object_name_str=''):
     super(InterestRateIndexModel, self).__init__(object_name_str)
     self._curve_ = YieldCurveInterface()
     self._option_pricer = OptionValuatorN()
예제 #8
0
 def __init__(self, object_name_str=''):
     super(HullWhiteCurve, self).__init__(object_name_str)
     self._curve_ = YieldCurveInterface()
     self._mean_reversion_ = 0.01
     self._volatility_ = 0.02
     self._hull_white_curve = _HullWhiteCurve([0.0], [0.0])
예제 #9
0
 def __init__(self, object_name_str=''):
     super(ScenarioYieldCurve, self).__init__(object_name_str)
     self._inner_factor_ = YieldCurveInterface()
     self._driving_factor_ = YieldCurveInterface()