Skip to main content

Finstruments: Financial Instrument Definitions

finstruments is a financial instrument definition library built with Python and Pydantic. Out of the box, it comes with the most common financial instruments, including equity forwards and options, as well as position, trade, and portfolio models. If an instrument doesn't already exist, you can leverage the building blocks to easily create a new instrument for any asset class. These building blocks also provide the functionality to serialize and deserialize to and from JSON, enabling API integration and storage in a document database.

Key Features

  • Support for common financial instruments, including equity forwards and options
  • Ability to extend and create custom instruments
  • JSON serialization and deserialization capabilities
  • Functions for date handling, business day calculations, payoffs, and other financial operations
  • Lightweight with minimal dependencies

Serialization and Deserialization

finstruments includes built-in support for serialization and deserialization of financial instruments, making it easy to save and load objects in formats like JSON. This feature allows users to easily store the state of financial instruments, share data between systems, or integrate with other applications.

Installation

Install finstruments using pip:

pip install finstruments

Usage

An equity option requires a BaseEquity instrument object (e.g. CommonStock) as input for the underlying field. The payoff (VanillaPayoff, DigitalPayoff) and exercise_type (EuropeanExerciseStyle, AmericanExerciseStyle, BermudanExerciseStyle) fields need to be populated with objects as well.

from datetime import date

from finstruments.common.enum import Currency
from finstruments.instrument.common.cut import NysePMCut
from finstruments.instrument.common.exercise_style import AmericanExerciseStyle
from finstruments.instrument.common.option.enum import OptionType
from finstruments.instrument.common.option.payoff import VanillaPayoff
from finstruments.instrument.equity import EquityOption, CommonStock

equity_option = EquityOption(
    underlying=CommonStock(ticker='AAPL'),
    payoff=VanillaPayoff(
        option_type=OptionType.PUT,
        strike_price=100
    ),
    exercise_type=AmericanExerciseStyle(
        minimum_exercise_date=date(2022, 1, 3),
        expiration_date=date(2025, 1, 3),
        cut=NysePMCut()
    ),
    denomination_currency=Currency.USD,
    contract_size=100
)

Linting and Code Formatting

This project uses black for code linting and auto-formatting. If the CI pipeline fails at the linting stage, you can auto-format the code by running:

# Install black if not already installed
pip install black==22.12.0

# Auto-format code
black ./finstruments
black ./tests

Documentation

We use pdoc3 to automatically generate documentation. All Python code must follow the Google docstring format for compatibility with pdoc3.

Generating HTML Documentation

To generate the documentation in HTML format, run:

pdoc3 --html ./finstruments/ --output-dir ./docs/generated --force

Generating Markdown Documentation

To generate the documentation in Markdown format, run:

pdoc3 ./finstruments/ --template-dir ./docs/templates --output-dir ./docs/md --force --config='docformat="google"'

Contributing

We welcome contributions! If you have suggestions, find bugs, or want to add features, feel free to open an issue or submit a pull request.

Setting Up a Development Environment

  1. Clone the repository:

    git clone https://github.com/kyleloomis/finstruments.git
    
  2. Install dependencies:

    pip install .
    
  3. Run the tests to ensure everything is set up correctly:

    pytest
    

Help and Support

For help or feedback, please reach out via email at kyle@spotlight.dev.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for finstruments 1.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for finstruments 1.0.10
File Size Uploaded
finstruments-1.0.10.tar.gz 24.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for finstruments 1.0.10
File Interpreter ABI Platform
finstruments-1.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 50.8 kB

Release files / finstruments-1.0.10.tar.gz

Download URL finstruments-1.0.10.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aa8b8e114a1bce4e31b45de54c732ec461aba9a46f23a2b5b3d5c57f7544782a
BLAKE2b-256 checksum
How to use checksums
2354036964977d0d5e360cc632a31438293a5de49c12d33e44e5a14c5386fd38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release files / finstruments-1.0.10-py3-none-any.whl

Download URL finstruments-1.0.10-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f4fb37844b83960b8faa022ca3c2041ed645dd8d3879ffeb965547931e5b174
BLAKE2b-256 checksum
How to use checksums
1526e1bbe622f55c9cbfbcd6446186c3f14c88e6672e409681ac93f3c7c12428
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release history Release notifications | RSS feed

This release

1.0.10 This release

2 release files

1.0.9

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page