Financial derivatives and portfolio analysis tools for python
Project description
derpy
Financial derivatives and portfolio analysis tools for python
Free software: MIT license
Documentation: https://derpy.readthedocs.io.
How to get up and running
to include the module in your project, you can simply use pip install derpy then in your python project
import derpy
print(derpy.__version__) # returns '0.0.1'
Example uses
Bonds
from derpy import bond as bd
px = 95.0428
face_val = 100.0
mat = 1.5
cpn_frq = 2
cpn_rate = 5.25
ytm = 5.5
print(' Price: {}'.format(bd.bond_price(face_val, mat, ytm, cpn_rate, cpn_frq)))
print(' Yield: {}'.format(bd.bond_ytm(px, face_val, mat, cpn_rate, cpn_frq)))
print(' ModDur: {}'.format(bd.bond_duration(px, face_val, mat, cpn_rate, cpn_frq)[0]))
print(' MacDur: {}'.format(bd.bond_duration(px, face_val, mat, cpn_rate, cpn_frq)[1]))
print('Convexity: {}'.format(bd.bond_convexity(px, face_val, mat, cpn_rate, cpn_frq)))
Options
from derpy.options import black_scholes_merton as bsm
# usage method 1: use function wrapper
input = ['call', 20, 21, 0.20, 0.1, 0.0002, 0]
call_price = bsm.option_pricing(bsm.euro_option, input)
call_gamma = bsm.option_pricing(bsm.gamma, input)
# usage method 2: call individual functions
put_price = bsm.euro_option('put', 20, 21, 0.2, 0.1, 0.0002) # div_yield is optional
put_gamma = bsm.gamma('put', 20, 21, 0.2, 0.1, 0.0002, 0.0001)
print(call_price) # return 0.16384395..
print(call_gamma) # return 0.23993880..
print(put_price) # return 1.16342..
print(put_gamma) # return 0.2399107..
Portfolio analysis
from derpy import portfolio as pt
securities = ['AAA', 'BBB']
positions = [[11, 10], [12, 10], [13, 10], [13, 11], [13, 12]]
prices = [[10, 10], [11, 10], [12, 10], [12, 10], [12, 10]]
dates = ['2018-07-01', '2018-08-01', '2018-09-01', '2018-10-01', '2018-11-01']
df_positions = pd.DataFrame(data=positions, columns=securities, index=dates)
df_prices = pd.DataFrame(data=prices, columns=securities, index=dates)
p = pt.Portfolio(names=securities, positions=df_positions, prices=df_prices)
print(p.sec_values())
print(p.sec_weights())
print(p.portfolio_value())
print(p.portfolio_returns())
History
0.1.0 (2018-09-19)
Released option pricing
Released portfolio analysis
Added testing for Options and Portfolios
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file derpy-0.1.1.tar.gz.
File metadata
- Download URL: derpy-0.1.1.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.10.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baacb62838cf7e1de41b1e289424373af8107b3f87ad101608b07dbedd47faf0
|
|
| MD5 |
d6245cc0b20dfe04ca1d19d5c16979cc
|
|
| BLAKE2b-256 |
880fba740f8495182413e5ec3ed81ed0c7ee8b7af38babfdfd6a19986d2022c6
|
File details
Details for the file derpy-0.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: derpy-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.10.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8bd325c49b2332247a9e0d345714eb44596bca4e7f3b8b847ae2f87be360658
|
|
| MD5 |
bd866dcb8547c362f8791b9a77732cc6
|
|
| BLAKE2b-256 |
2d0fcc6bf47c238e8428729273de05f01e4bdc24fbe746660132f67ecf93e3a9
|