Skip to content

Commit

Permalink
Support Cython
Browse files Browse the repository at this point in the history
  • Loading branch information
roniemartinez committed May 15, 2019
1 parent 3b541fb commit b889157
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -33,7 +33,7 @@ deploy:
user: $TEST_PYPI_USER
password: $TEST_PYPI_PASS
server: https://test.pypi.org/legacy/
distributions: "sdist bdist_wheel"
distributions: "sdist"
on:
branch: staging
branch: develop
condition: $TRAVIS_PYTHON_VERSION = "3.6"
11 changes: 9 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,7 +2,14 @@

## Unreleased

## 0.2.0
## 0.3.0 - 2019-05-15
### Added
- Support Cython

### Changed
- Use develop instead of staging

## 0.2.0 - 2019-05-07
### Added
- Support PyPy
- AppVeyor integration
Expand All @@ -11,7 +18,7 @@
- Convert amortization to package
- Move definitions to setup.cfg

## 0.1.0
## 0.1.0 - 2019-05-05
### Added
- PyPI package

1 change: 0 additions & 1 deletion Pipfile
Expand Up @@ -8,7 +8,6 @@ codecov = "==2.0.15"
pytest = "==4.4.1"
pytest-cov = "==2.7.1"
twine = "==1.13.0"
wheel = "==0.33.1"

[packages]
tabulate = "==0.8.3"
15 changes: 11 additions & 4 deletions README.md
Expand Up @@ -10,13 +10,13 @@ Python library for calculating amortizations and generating amortization schedul
</tr>
<tr>
<td>Travis CI</td>
<td><img src='https://travis-ci.org/roniemartinez/amortization.svg?branch=staging'></td>
<td><img src='https://travis-ci.org/roniemartinez/amortization.svg?branch=develop'></td>
<td>AppVeyor</td>
<td><img src='https://ci.appveyor.com/api/projects/status/qy2j7qutbx1fymuq/branch/staging?svg=true'></td>
<td><img src='https://ci.appveyor.com/api/projects/status/qy2j7qutbx1fymuq/branch/develop?svg=true'></td>
</tr>
<tr>
<td>Coverage</td>
<td><img src='https://codecov.io/gh/roniemartinez/amortization/branch/staging/graph/badge.svg'></td>
<td><img src='https://codecov.io/gh/roniemartinez/amortization/branch/develop/graph/badge.svg'></td>
<td>Wheel</td>
<td><img src='https://img.shields.io/pypi/wheel/amortization.svg'></td>
</tr>
Expand Down Expand Up @@ -44,14 +44,21 @@ Python library for calculating amortizations and generating amortization schedul
pip install amortization
```

### To build using Cython

```bash
pip install cython
pip install amortization
```

## Usage

### Python

#### Amortization Amount

```python
from amortization import calculate_amortization_amount
from amortization.amount import calculate_amortization_amount

amount = calculate_amortization_amount(150000, 0.1, 36)
```
Expand Down
19 changes: 0 additions & 19 deletions amortization/__init__.py
@@ -1,19 +0,0 @@
#!/usr/bin/env python
# __author__ = "Ronie Martinez"
# __copyright__ = "Copyright 2019, Ronie Martinez"
# __credits__ = ["Ronie Martinez"]
# __maintainer__ = "Ronie Martinez"
# __email__ = "ronmarti18@gmail.com"


def calculate_amortization_amount(principal, interest_rate, period):
"""
Calculates Amortization Amount per period
:param principal: Principal amount
:param interest_rate: Interest rate per period
:param period: Total number of periods
:return: Amortization amount per period
"""
x = (1 + interest_rate) ** period
return principal * (interest_rate * x) / (x - 1)
2 changes: 1 addition & 1 deletion amortization/amortize.py
Expand Up @@ -4,7 +4,7 @@
# __credits__ = ["Ronie Martinez"]
# __maintainer__ = "Ronie Martinez"
# __email__ = "ronmarti18@gmail.com"
from amortization import calculate_amortization_amount
from amortization.amount import calculate_amortization_amount
from amortization.schedule import amortization_schedule


Expand Down
19 changes: 19 additions & 0 deletions amortization/amount.py
@@ -0,0 +1,19 @@
#!/usr/bin/env python
# __author__ = "Ronie Martinez"
# __copyright__ = "Copyright 2019, Ronie Martinez"
# __credits__ = ["Ronie Martinez"]
# __maintainer__ = "Ronie Martinez"
# __email__ = "ronmarti18@gmail.com"


def calculate_amortization_amount(principal, interest_rate, period):
"""
Calculates Amortization Amount per period
:param principal: Principal amount
:param interest_rate: Interest rate per period
:param period: Total number of periods
:return: Amortization amount per period
"""
x = (1 + interest_rate) ** period
return principal * (interest_rate * x) / (x - 1)
2 changes: 1 addition & 1 deletion amortization/schedule.py
Expand Up @@ -4,7 +4,7 @@
# __credits__ = ["Ronie Martinez"]
# __maintainer__ = "Ronie Martinez"
# __email__ = "ronmarti18@gmail.com"
from amortization import calculate_amortization_amount
from amortization.amount import calculate_amortization_amount


def amortization_schedule(principal, interest_rate, period):
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
@@ -1,7 +1,7 @@
[metadata]
name=amortization
version=0.2.1-rc1
download_url=https://github.com/roniemartinez/amortization/tarball/0.2.1-rc1
version=0.3.0-rc1
download_url=https://github.com/roniemartinez/amortization/tarball/0.3.0-rc1
description=Python library for calculating amortizations and generating amortization schedules
long_description=file:README.md
description-file=README.md
Expand Down
17 changes: 15 additions & 2 deletions setup.py
Expand Up @@ -4,6 +4,19 @@
# __credits__ = ["Ronie Martinez"]
# __maintainer__ = "Ronie Martinez"
# __email__ = "ronmarti18@gmail.com"
from setuptools import setup
from setuptools import setup, Extension

setup()
try:
from Cython.Build import cythonize

ext_modules = cythonize([
Extension("amortization.amount", ["amortization/amount.py"]),
Extension("amortization.schedule", ["amortization/schedule.py"]),
Extension("amortization.amortize", ["amortization/amortize.py"]),
])
except ImportError:
ext_modules = None

setup(
ext_modules=ext_modules
)
2 changes: 1 addition & 1 deletion tests/test_amortization.py
Expand Up @@ -4,7 +4,7 @@
# __credits__ = ["Ronie Martinez"]
# __maintainer__ = "Ronie Martinez"
# __email__ = "ronmarti18@gmail.com"
from amortization import calculate_amortization_amount
from amortization.amount import calculate_amortization_amount
from amortization.schedule import amortization_schedule


Expand Down

0 comments on commit b889157

Please sign in to comment.