FinSec
Pure python financial securities dataclasses, as foundation for other projects
Install
## Install from pypi
pip install financial-security-classes
## or from the repo directly
git clone https://github.com/alienbrett/financial-security-classes
cd financial-security-classes
pip install -e .
Examples
First set up and import the library
import datetime
import finsec as fs
Create a currency
usd = fs.FiatCurrency(
ticker = 'USD',
nation = 'United States Dollar',
gsid = fs.GSID(20),
identifiers = [
fs.ISIN('abcdefg'),
],
)
Create an index, denominated in USD
spx = fs.DerivedIndex(
ticker = 'SPX',
issuer = 'Standard & Poor',
gsid = fs.GSID(100),
identifiers = [
fs.FIGI('12345'),
],
currency = usd,
)
Create a few stocks
hyg = fs.ETP(
ticker = 'HYG',
gsid = fs.GSID(124),
description = 'ISHARES IBOXX HIGH YLD CORP',
primary_exc = fs.Exchange.NYSE,
issuer = 'ishares',
)
tsla = fs.Stock(
## Ticker will be auto-capitalized
ticker = 'tSla',
gsid = fs.GSID(125),
description = 'Tesla corp',
primary_exc = fs.Exchange.NYSE,
)
Create a SPX future
esu22 = fs.NewFuture(
gsid = fs.GSID(120),
ticker = 'ESU22',
underlying_security = spx,
expiry_date = datetime.date(2022,9,16),
primary_exc = fs.Exchange.CME,
expiry_time_of_day = fs.ExpiryTimeOfDay.OPEN,
tick_size = 0.25,
multiplier = 50.0,
identifiers = [
fs.FIGI('234567'),
],
#### This should be implied, since underlyer doesn't permit physical delivery
# settlement_type = fs.SettlementType.CASH,
#### Without this argument, this should be set to UNKNOWN
# expiry_series_type = fs.ExpirySeriesType.MONTHLY,
)
Options
The package supports americans and europeans:
amer_call = fs.American(
gsid = fs.GSID(1_234_567),
underlying_security = tsla,
callput = 'call',
strike = 300.,
expiry_date = datetime.date(2022,12,16),
expiry_time_of_day = fs.ExpiryTimeOfDay.CLOSE,
primary_exc = fs.Exchange.CBOE,
multiplier = 100.0,
identifiers = [
fs.FIGI('blahblahblah123'),
],
settlement_type = fs.SettlementType.PHYSICAL,
# Without this argument, this set to fs.ExpirySeriesType.UNKNOWN
expiry_series_type = fs.ExpirySeriesType.MONTHLY,
)
And the european:
euro_put = fs.European(
gsid = fs.GSID(1_234_890),
underlying_security = spx,
callput = 'put',
strike = 3_500,
expiry_date = '2022-12-30', # string expiries like this also supported
expiry_time_of_day = fs.ExpiryTimeOfDay.CLOSE,
primary_exc = fs.Exchange.CBOE,
expiry_series_type = fs.ExpirySeriesType.QUARTERLY,
multiplier = 100.0,
# Isn't strictly necessary, since this will be inferred from index underlying without physical delivery available
settlement_type = fs.SettlementType.CASH,
)
Serialization support
Objects can be safely converted to json or dict format:
obj_json = fs.json_encode(euro_put)
obj_new = fs.json_decode(obj_json)
assert( obj_new == euro_put )
obj_dict = fs.dict_encode(euro_put)
obj_new = fs.dict_decode(obj_dict)
assert( obj_new == euro_put )
Run tests
To run tests:
$ python3.9 -m virtualenv venv
$ venv/bin/activate
$ make test
Metadata
Release files for financial-security-classes 0.4.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 | Provenance | Actions |
|---|---|---|---|---|
| financial-security-classes-0.4.0.tar.gz | 18.8 kB | Without provenance | Details for financial-security-classes-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| financial_security_classes-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for financial_security_classes-0.4.0-py3-none-any.whl |
Total release size: 40.2 kB
Release files / financial-security-classes-0.4.0.tar.gz
| Download URL | financial-security-classes-0.4.0.tar.gz |
|---|---|
| Size | 18.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c41de2358ea4bb1ae88b563ae0f7a91db77db79c3d78e7262650427eac29b94e
|
|
BLAKE2b-256 checksum How to use checksums |
3efcfca3691c2206955820d18313a054fc27029fd75be015e59950a0c7ca7c0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Release files / financial_security_classes-0.4.0-py3-none-any.whl
| Download URL | financial_security_classes-0.4.0-py3-none-any.whl |
|---|---|
| Size | 21.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4decdaef9d96c971aeb87f3a9c15a68589d277ed021a250af9c042ba2cac55fd
|
|
BLAKE2b-256 checksum How to use checksums |
003b535bf2cc9fe61e1165eb28f5b8bbec4fb4d3908918638f35e0a1e9847700
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Security for financial-security-classes 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.