Pure python financial securities dataclasses, as foundation for other projects
Project description
financial-security-classes
Pure python financial securities dataclasses, as foundation for other projects
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.European(
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,
)
Run tests
To run tests:
$ python3.9 -m virtualenv venv
$ venv/bin/activate
$ make test
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
Close
Hashes for financial-security-classes-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 546c1766d0fb46bcc9f1dbcfae323c257deebe2222ccace500e55fe287ff5d90 |
|
MD5 | 247ad5db4499afaa2836356923ab085b |
|
BLAKE2b-256 | fa7759141fd46f80eb6ee68f13e4e2c42feea22f562a0c3d76f2f715dddc95ac |
Close
Hashes for financial_security_classes-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ed07f9cb6bcd56f248bae3758f03e75962e896b969e46e0a186ea054c4c0073 |
|
MD5 | 79a114d09e2a0c6cbba16210b3877aeb |
|
BLAKE2b-256 | 340961e075bb9c65d8463152e8a88112aa49b9b34ef7f19c8b0e1e8a8fe92ba8 |