Skip to main content

A mathematical and financial function curve utility library.

Project description

curvepy

Tests

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 in 1 + 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 in pow(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:

  1. Install pdoc3 if needed with pip3 install pdoc3.
  2. Navigate to project root and install dependencies: poetry install.
  3. Generate documetation files with: pdoc3 -o docs --html curvepy.
  4. The new files will be in docs/curvepy. Move them to docs/ 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.

Project details


Download files

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

Source Distribution

curvepy-0.2.0.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curvepy-0.2.0-py3-none-any.whl (42.8 kB view details)

Uploaded Python 3

File details

Details for the file curvepy-0.2.0.tar.gz.

File metadata

  • Download URL: curvepy-0.2.0.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.3 Darwin/19.6.0

File hashes

Hashes for curvepy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3f4a1e20edff5b23043714ea1000f08fb66b3118dbe9668eb386d961b8d310a1
MD5 cb8f7f6422ba385f6195a8c0a633e733
BLAKE2b-256 210ddeb5f34cf72bf5b4680da738936b05a74a656addb9b0ddc381868e9b3ad8

See more details on using hashes here.

File details

Details for the file curvepy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: curvepy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 42.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.3 Darwin/19.6.0

File hashes

Hashes for curvepy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1929d716bfa8f691f7b834a85c5b675b2e83c8cc16f5492d442e9f4210b2091c
MD5 8e11f5242100c2c2af846bb2f2259acb
BLAKE2b-256 62682ecc1e196c412ccd3df3037824fd367a1f1bba07ae5ed2d3557bbc9ddeec

See more details on using hashes here.

Supported by

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