Skip to main content

risk factor model library python style.

Project description

Python library shortrate

CodeShip Travis ci Read the Docs CodeFactor Grade Code Climate maintainability Codecov lgtm grade total lgtm alerts GitHub GitHub release PyPI Version PyPI - Python Version PyPI Downloads

Risk factor model library python style.

Example Usage

from businessdate import BusinessDate, BusinessRange
from dcf import ZeroRateCurve, FxCurve
from timewave import Consumer, Engine

from shortrate import RiskFactorProducer, GBMFxCurve, HullWhiteCurve, HullWhiteFxCurve, HullWhiteMultiCurrencyCurve

s = BusinessDate()
t = s + '10y'
g = BusinessRange(s, t, '6M')
d = ZeroRateCurve([s], [0.05])
f = ZeroRateCurve([s], [0.04])
x = FxCurve([s], [.8], domestic_curve=d, foreign_curve=f)
r = GBMFxCurve.build(x, volatility=0.2)

print r.evolve(1., s, s + '1y', 0.01)
print r.get_fx_rate(s + '3y'), r._factor_date
print r.evolve(1., s + '1y', s + '5y', 0.1)
print r.get_fx_rate(s + '7y'), r._factor_date

hwd = HullWhiteCurve.build(d, mean_reversion=0.01, volatility=0.03, terminal_date=t)
hwf = HullWhiteCurve.build(f, mean_reversion=0.01, volatility=0.03, terminal_date=t)
hwx = HullWhiteFxCurve.build(r, hwd, hwf)
hwxf = HullWhiteMultiCurrencyCurve.build(hwf, hwd, hwx)

print hwd.evolve(1., s, s + '1y', 0.01)
print hwf.evolve(1., s, s + '1y', 0.02)
print hwx.evolve(1., s, s + '1y', (0.01, 0.02, 0.01))
print hwxf.evolve(1., s, s + '1y', 0.02)

func = (lambda x: hwd.get_cash_rate(t - '1y'))
c = Consumer(lambda x: func(x.date))
res = Engine(RiskFactorProducer(hwd), c).run(g, 100)

print res

Install

The latest stable version can always be installed or updated via pip:

$ pip install shortrate

If the above fails, please try easy_install instead:

$ easy_install shortrate

Development Version

The latest development version can be installed directly from GitHub:

$ pip install --upgrade git+https://github.com/pbrisk/shortrate.git

Contributions

Issues and Pull Requests are always welcome.

License

Code and documentation are available according to the Apache Software License (see LICENSE).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shortrate-0.3.tar.gz (18.4 kB view hashes)

Uploaded Source

Built Distribution

shortrate-0.3-py3-none-any.whl (18.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page