Skip to main content

Build Coverage Status Code Climate Downloads License Python Versions

What is it?

trade is Python framework to ease the creation of investment management applications. It is focused in, but not limited to, stock exchange markets.

The trade module provides notions of assets, purchases, sales, day trades, cost deduction, options, option exercises, asset accumulation and more.

Installation

The trade module can be installed with pip:

pip install trade

To check if everything went OK, open the Python console and import the module:

import trade
asset = trade.Asset(symbol='ATVI')

Example

A basic example of the trade module in action:

import trade

# create the asset that we are going to trade
asset = trade.Asset(name='Google Inc', symbol='GOOGL')

# create the accumulator to accumulate trades with the asset
accumulator = trade.Accumulator(asset)


print(accumulator.subject.name)
#>> Google Inc

print(accumulator.state['quantity'])
#>> 0

print(accumulator.state['price'])
#>> 0

print(accumulator.state['results'])
#>> {}


# create a trade operation buying the asset
purchase = trade.Operation(
    subject=asset,
    quantity=10,
    price=650.73,
    date='2015-09-23'
)

# accumulate the trade
accumulator.accumulate(purchase)


print(accumulator.state['quantity'])
#>> 10

print(accumulator.state['price'])
#>> 650.73

print(accumulator.state['results'])
#>> {}


# create a new trade operation selling the asset
sale = trade.Operation(
    subject=asset,
    quantity=-5,
    price=656.77,
    date='2015-09-24'
)

# accumulate the new trade
accumulator.accumulate(sale)


print(accumulator.state['quantity'])
#>> 5

print(accumulator.state['price'])
#>> 650.73

print(accumulator.state['results'])
#>> {'trades': 30.199999999999818}

Check the documentation for all the available features.

JSON Interface

import trade
interface = trade.TradeJSON()

json_input = '''{
    "subjects": {
        "GOOG": {
            "type": "Asset",
            "name": "Google Inc",
            "expiration_date": "2019-01-01"
        },
        "AAPL": {
            "type": "Asset",
            "name": "Apple Inc.",
            "expiration_date": ""
        }
    },
    "occurrences": [
        {
            "type": "Operation",
            "subject": "GOOG",
            "date": "2015-01-01",
            "quantity": 10,
            "price": 650.11,
            "commissions": {},
            "raw_results": {},
            "operations": []
        }
    ],
    "initial state": {
        "AAPL": {
            "date": "2015-11-09",
            "quantity": 92,
            "price": 31.21,
            "results": {"trades": 5000.72}
        }
    }
}'''

json_output = interface.get_trade_results(json_input)

print(json_output)
#>> {
#    "GOOG": {
#        "2015-01-01": {
#            "quantity": 10,
#            "price": 650.11,
#            "results": {}
#        }
#    },
#    "AAPL": {
#        "2015-11-09": {
#            "quantity": 92,
#            "price": 31.21,
#            "results": {"trades": 5000.72}
#        }
#    }
#}

Compatibility

trade is compatible with Python 2.7, 3.3, 3.4 and 3.5.

Version

The current version is 0.2.1 alpha.

License

Copyright (c) 2015 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

trade-0.2.1-py2.py3-none-any.whl (25.8 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for trade-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 aa9d7aa09ddc5452fd0c3a91014c9cd884f774c70c73a4904083037ae590c2ae
MD5 dadf97c372c49e651ed2287d8b2ba14a
BLAKE2b-256 29af422cff0aa7cc319fd37e30e6038ee88ac6ca8fb8116fec2aca5a448357f1

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

1.1.0

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

This release

0.2.1 This release

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