curvepy
A mathematical and financial function curve utility library for Python.
Installation
With poetry:
poetry add curvepy
Or with pip:
pip3 install curvepy
Usage
Have a look at the documentation.
Basic usage:
# Create a line
from curvepy import Line
line = Line(const=1, slope=2)
assert line.y(0) == 1
assert line.y(1) == 3
# Function arithmetic
line2 = Line(const=-1, slope=-2)
line_sum = line1 + line2
assert line_sum.y(0) == 0
assert line_sum.y(1) == 0
JSON Format
Function values:
Functions are denoted by $, for example, $add. Available functions:
$add: Adds values. Example:{ "$add": [1, 2] }, which results in1 + 2.$line: Adds values. Example:{ "$line": { "points": [[1, 2], [2, 3]] } }which results in a line joining the points(1, 2)and(2, 3).
For other functions, refer to Curve documentation.
Decorators modify applicable values and functions inside of them as well as deeply nested values. Available decorators:
@date: Converts all string values to seconds from Unix epoch. If no GMT offset is given, uses the local time zone at the time of parsing.@log: Converts all number literals to log space. On exit from the decorator, the result is raised bacj by the base into linear space. Available varaints:@log2,@log10.@args: Allows using both named and unamed arguments in a function. For example:{ '$raised': { '@args': [4], 'base': 2 } }, which will result inpow(2, 4).
A full example:
The following price will be in the form of a line (on a log chart) joining the prices 10080.2 and 8975.0 on dates 8 May 2020 11:01 am and 13 May 2020 5 am respectively.
{
"price": {
"@log": {
"$line": {
"points": [
[{"@date": "2020-05-08 11:01"}, 10080.2],
[{"@date": "2020-05-13 05:00"}, 8975.0]
]
}
}
}
}
Development
Setup
Clone repository and run:
poetry install
Running Unit Tests
poetry run test
Updating Documentation
The module pdoc3 is used to automatically generate documentation. To update the documentation:
- Install
pdoc3if needed withpip3 install pdoc3. - Navigate to project root and install dependencies:
poetry install. - Generate documetation files with:
pdoc3 -o docs --html curvepy. - The new files will be in
docs/curvepy. Move them todocs/and replace existing files.
If you get errors about missing modules, make sure you have activated the python enviroment (in .venv) and that there are no python version mismatches. If so, use poetry env use <python version>; poetry install to fix.
Metadata
Release files for curvepy 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| curvepy-0.2.0.tar.gz | 34.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| curvepy-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 77.6 kB
Release files / curvepy-0.2.0.tar.gz
| Download URL | curvepy-0.2.0.tar.gz |
|---|---|
| Size | 34.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f4a1e20edff5b23043714ea1000f08fb66b3118dbe9668eb386d961b8d310a1
|
|
BLAKE2b-256 checksum How to use checksums |
210ddeb5f34cf72bf5b4680da738936b05a74a656addb9b0ddc381868e9b3ad8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.3 Darwin/19.6.0
|
Release files / curvepy-0.2.0-py3-none-any.whl
| Download URL | curvepy-0.2.0-py3-none-any.whl |
|---|---|
| Size | 42.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1929d716bfa8f691f7b834a85c5b675b2e83c8cc16f5492d442e9f4210b2091c
|
|
BLAKE2b-256 checksum How to use checksums |
62682ecc1e196c412ccd3df3037824fd367a1f1bba07ae5ed2d3557bbc9ddeec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.3 Darwin/19.6.0
|