Financial Instruments.
Project description
Finstruments: Financial Instruments
finstruments
is a Python library designed for modeling financial instruments. It comes with the core financial
instruments, such as forwards and options, out of the box, as well as position, trade, and portfolio models.
finstruments
comes with the basic building blocks, making it easy to extend and build new instruments for any asset
class. These building blocks also provide the functionality to serialize and deserialize to and from JSON, enabling the
ability to store a serialized format in a document database. This library is ideal for quantitative researchers,
traders, and developers who need a streamlined way to build and interact with financial instruments.
Key Features
- Support for various financial instruments, including options, forwards, and custom instrument extensions.
- Functions for date handling, business day calculations, and other financial operations.
- Serialization and deserialization capabilities for easy conversion between data formats.
- Automatically handles complex calculations like option payoffs and date conventions.
- Lightweight and dependency-minimized where possible.
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
# Auto-format code
black ./finstruments
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
-
Clone the repository:
git clone https://github.com/kyleloomis/finstruments.git
-
Install dependencies:
pip install .
-
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.
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
File details
Details for the file finstruments-1.0.1.tar.gz
.
File metadata
- Download URL: finstruments-1.0.1.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f203218e489f6f95abb127fc0696eb927bb25b14ba663741319ab2f6d0178dc2 |
|
MD5 | 101cfd55491725afe2fcb5a3689a5170 |
|
BLAKE2b-256 | 1671e8f5756d1b3a95029d0eee3dbe2e7e9b8a5b8ef37baeac580e4d54a6914a |
File details
Details for the file finstruments-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: finstruments-1.0.1-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95f36971ac21fea324a0f099d1404ea7d4fc59cdc3fc43fbe330a3562d66a743 |
|
MD5 | c2b20131ab9b2608f396f8546981e9c0 |
|
BLAKE2b-256 | c5935413942de7f59a12a526df7e9e064aa0478d79ae4071f5db81f1ec35f3e3 |