def calculate(self): period_cal = period_util.calc_period_info(self.period, self.period_type, self.interest_rate) self.period = period_cal['period'] self.interest_rate = period_cal['interest_rate'] if self.annuity is False: return self.par_value * self.discount_rate() else: return self.par_value * Decimal((1 - self.discount_rate()) / (self.interest_rate / 100))
def calculate(self): period_cal = period_util.calc_period_info(self.period, self.period_type, self.interest_rate) self.period = period_cal['period'] self.interest_rate = period_cal['interest_rate'] if self.annuity is False: return pow(1 + (self.interest_rate / 100), self.period) * self.par_value else: upper_value = pow(1 + self.interest_rate / 100, self.period) - 1 return Decimal(self.par_value) * ( Decimal(upper_value) / Decimal(self.interest_rate / 100))
def price_bond(self): ytm = self.interest_rate coupon_period_cal = calc_period_info(self.period, self.period_type, self.coupon / 100) periods = coupon_period_cal['period'] interest_rate = coupon_period_cal['interest_rate'] * 100 dt = [(i + 1) / self.period_type for i in range(int(periods))] if self.period_type == 6: freq = 2 elif self.period_type == 12: freq = 1 price = sum([interest_rate / (1 + ytm / freq)**periods for t in dt]) + self.par_value / (1 + ytm / freq)**periods return price
def calculate(self): if self.coupon != 0: coupon_period_cal = calc_period_info(self.period, self.period_type, self.coupon / 100) coupon_period = coupon_period_cal['interest_rate'] * self.par_value coupon_pv = PresentValue(coupon_period, self.interest_rate, self.period, self.period_type, True) par_pv = PresentValue(self.par_value, self.interest_rate, self.period, self.period_type, False) return round(coupon_pv.calculate()) + round(par_pv.calculate()) else: par_pv = PresentValue(self.par_value, self.interest_rate, self.period, self.period_type, False) return round(par_pv.calculate())
def cash_flow(coupon_rate, period, period_type=6, par_value=1000): result = [] future_value = par_value period_cal = calc_period_info(period, period_type, coupon_rate) period_count = period_cal['period'] payment = (period_cal['interest_rate'] * future_value) / 100 temp = 1 while temp <= period_count - 1: result.append(payment) temp += 1 result.append(par_value + payment) return result
def detail_calc_future_value(principal, interest_rate, period, period_type, annuity): detail = {'detailed_cash_flow': []} period_cal = calc_period_info(period, period_type, interest_rate) detail['period_count'] = period_cal['period'] detail['interest_rate'] = period_cal['interest_rate'] detail['present_value'] = principal detail['annuity'] = annuity temp = 1 while temp <= detail['period_count']: future_value = Decimal( FutureValue(principal, interest_rate, temp, period_type, annuity).calculate()) detail['detailed_cash_flow'].append({ 'period_count': temp, 'future_value': future_value }) temp += 1 return detail