Skip to main content
A framework for financial applications.
Copyright (c) 2015-2018 Rafael da Silva Rocha

Build Windows Build Coverage Status Scrutinizer Python Versions Live Demo

Installation

$ pip install trade

trade

trade is a framework for the creation of financial applications.

It uses the concept of holders, subjects, occurrences and contexts

A subject is anything that can be traded.

A holder is someone who owns subjects.

A holder state is updated by occurrences.

Occurrences may occur alone or in contexts.

A subject is anything that can be traded

A subject may be the share of a corporation, livestock and so on.

A holder is a entity that owns subjects

A holder owns subjects. The holder state is updated by occurrences.

Occurrences happen with subjects and change the state of the holder

A occurrence may be caused by the holder, like the purchase of units of some subject. They can also represent third-party events, like a stock split. In both cases they should change the state of the holder.

A context may have its own rules

Contexts are groups of occurrences.

Contexts are used to pre-process occurrences before informing them to a holder.

A context may be a situation where daytrades should be identified, for example.

A context may also involve taxes and other costs altering the details of the occurrences.

Extending the framework

trade should be extended with new types of occurrences, subjects and context rules.

The holder state signature can be defined according to the needs of the application.

Live sample app

You can try it live.

This is a sample app built with trade. It runs as a service.

The input is a JSON containing occurrences and a initial state for the holder.

The sample app have context tasks to identify daytrades, apply costs to occurrences and more.

The service also calculates the profits and losses from the occurrences and groups the results by asset.

The output is the holder state as a JSON.

Use:

from trade.holder import Holder
from trade.occurrence import Occurrence
from trade.subject import Subject

# create a holder
holder = Holder()

# define some subject
some_asset = Subject('AST1')

# create an occurrence with that subject.
# In this example, a purchase of 100 units of the asset,
# for the value of $20.
some_occurrence = Occurrence(
                some_asset,
                '2018-01-02',
                {
                        "quantity": 100,
                        "value": 20
                }
        )

# pass it to the holder
holder.trade(some_occurrence)

# check the holder state:
for subject, state in holder.state.items():
        print(subject)
        print(state)
# AST1
# {'value': 20.0, 'quantity': 100}


# create some other occurrence with that subject.
# In this example, a sale of 20 units of the asset,
# for the value of $30.
holder.trade(Occurrence(
                some_asset,
                '2018-01-03',
                {
                        "quantity": -20,
                        "value": 30
                }
        ))

# check the holder state. It should show a change in quantity
# and some profit:
for subject, state in holder.state.items():
        print(subject)
        print(state)
# AST1
# {'value': 20.0, 'quantity': 80}


# create some other occurrence with that subject.
# Now a purchase of 10 units of the asset, for the
# value of $20.
holder.trade(Occurrence(
                some_asset,
                '2018-01-04',
                {
                        "quantity": 10,
                        "value": 25
                }
        ))

# check the holder state. It should show a change in quantity
# and in the value of the subject:
for subject, state in holder.state.items():
        print(subject)
        print(state)
# AST1
# {'value': 20.555555555555557, 'quantity': 90}

License

Copyright (c) 2015-2018 Rafael da Silva Rocha

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Download files

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

Source Distribution

trade-1.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

trade-1.1.0-py2.py3-none-any.whl (13.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file trade-1.1.0.tar.gz.

File metadata

  • Download URL: trade-1.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for trade-1.1.0.tar.gz
Algorithm Hash digest
SHA256 672f808da7d246ece9e8cc2b879d9e8facf06bf452d31342da808a2d0b00c5c6
MD5 750f7498bdb8594c40e051988f738769
BLAKE2b-256 035cb14282483283bfd0c192f2bea0cf3c215cf57185782cd8c3f804d125acf5

See more details on using hashes here.

File details

Details for the file trade-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for trade-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e1b2092a3488f939c1826b0f77a0b3d536045f10350f96c5c6460e5d457cfba0
MD5 b268ef29e62585541fd8e40f253b051e
BLAKE2b-256 9bbc6d0c1238cd6a08c10df60ccfdda250b0fe6587b9d767c55c5257b5419054

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

This release

1.1.0 This release

2 files

1.0.0

1 file

0.4.2

2 files

0.4.1

2 files

0.4

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

1 file

0.2.5

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

1 file

0.2

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 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