Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2846 views
Kernel: Python 2 (system-wide)

Задачи к лекции "Восстановление кривой доходности"

Чтобы определить валюты, для которых Вы будете строить кривые и дату завершения форвардного контракта, запустить функцию ниже с Вашим почтовым ящиком

def getVariant(email): ccy = ['NOK', 'SEK', 'DKK', 'EUR'] h = hash(email) ccy1 = ccy[h % 4] date = 365 + h%365 print 'Task 1: 5Y curve for ' + ccy1 print 'Task 2: FX Forward for USD' + ccy1 + ' with maturity date ' + str(date) getVariant('[email protected]')
Task 1: 5Y curve for SEK Task 2: FX Forward for USDSEK with maturity date 524

Задачa 1

Взять значения базовых ставок https://sebgroup.com/large-corporates-and-institutions/prospectuses-and-downloads/rates/base-rates и цену процентных свопов https://sebgroup.com/large-corporates-and-institutions/prospectuses-and-downloads/rates/swap-rates Восстановить кривую для Вашей валюты

s0=0 s1= 0.03 #s2= #s3= r0 = s0 import numpy as np import scipy.optimize import scipy.interpolate import matplotlib.pyplot as pt # Дискаунт фактор из процентной ставки # для простоты капитализация процентов не учитывается def DF(L,m): return 1.0 / (1.0 + L*m/12) def S1(r12, r0, s1): r6 = 0.5* (r0 + r12) df6 = DF(r6, 6) df12 = DF(r12, 12) price = 2*(1 - df12) / (df6 + df12) return price - s1 r12 = scipy.optimize.broyden1(lambda x: S1(x, s0, s1), 0.0) print(r12) pt.plot([0, 12, 24, 36], [r0, r12])
0.030335048250253894
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-19-ed5648b6cbe0> in <module>() 28 print(r12) 29 ---> 30 pt.plot([0, 12, 24, 36], [r0, r12]) /usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in plot(*args, **kwargs) 3259 mplDeprecation) 3260 try: -> 3261 ret = ax.plot(*args, **kwargs) 3262 finally: 3263 ax._hold = washold /usr/lib/python2.7/dist-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs) 1716 warnings.warn(msg % (label_namer, func.__name__), 1717 RuntimeWarning, stacklevel=2) -> 1718 return func(ax, *args, **kwargs) 1719 pre_doc = inner.__doc__ 1720 if pre_doc is None: /usr/lib/python2.7/dist-packages/matplotlib/axes/_axes.pyc in plot(self, *args, **kwargs) 1370 kwargs = cbook.normalize_kwargs(kwargs, _alias_map) 1371 -> 1372 for line in self._get_lines(*args, **kwargs): 1373 self.add_line(line) 1374 lines.append(line) /usr/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in _grab_next_args(self, *args, **kwargs) 402 this += args[0], 403 args = args[1:] --> 404 for seg in self._plot_args(this, kwargs): 405 yield seg 406 /usr/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in _plot_args(self, tup, kwargs) 382 x, y = index_of(tup[-1]) 383 --> 384 x, y = self._xy_from_xy(x, y) 385 386 if self.command == 'plot': /usr/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in _xy_from_xy(self, x, y) 241 if x.shape[0] != y.shape[0]: 242 raise ValueError("x and y must have same first dimension, but " --> 243 "have shapes {} and {}".format(x.shape, y.shape)) 244 if x.ndim > 2 or y.ndim > 2: 245 raise ValueError("x and y can be no greater than 2-D, but have " ValueError: x and y must have same first dimension, but have shapes (4,) and (2,)
Image in a Jupyter notebook
S1(x, s0, s1)