Code Monkey home page Code Monkey logo

ccy's Introduction

A python module for currencies. The module compiles a dictionary of currency objects containing information useful in financial analysis. Not all currencies in the world are supported yet. You are welcome to join and add more.

Master CI

master-build_

Dev CI

dev-build_

Dowloads

http://pypi.python.org/pypi/ccy

Source

https://github.com/lsbardel/ccy

Currency object

To use it:

>>> import ccy
>>> c = ccy.currency('aud')
>>> c.printinfo()
code: AUD
twolettercode: AD
roundoff: 4
default_country: AU
isonumber: 036
order: 3
name: Australian Dollar
>>> c.as_cross()
'AUDUSD'
>>> c.as_cross('/')
'AUD/USD'

a currency object has the following properties:

  • code: the ISO 4217 code.
  • twolettercode: two letter code (can't remeber the ISO number). Very useful for financial data providers such as Bloomberg.
  • default_country: the default ISO 3166-1 alpha-2 country code for the currency.
  • isonumber: the ISO 4217 number.
  • name: the name of the currency.
  • order: default ordering in currency pairs (more of this below).
  • roundoff: number of decimal places

Currency Crosses

You can create currency pairs by using the currency_pair function:

>>> import ccy
>>> p = ccy.currency_pair('eurusd')
>>> p
ccy_pair: EURUSD
>>> p.mkt()  # market convention pair
ccy_pair: EURUSD
>>> p = ccy.currency_pair('chfusd')
>>> p
ccy_pair: CHFUSD
>>> p.mkt()  # market convention pair
ccy_pair: USDCHF

Some shortcuts:

>>> import ccy
>>> ccy.cross('aud')
'AUDUSD'
>>> ccy.crossover('eur')
'EUR/USD'
>>> ccy.crossover('chf')
'USD/CHF'

Note, the Swiss franc cross is represented as 'USD/CHF', while the Aussie Dollar and Euro crosses are represented with the USD as denominator. This is the market convention which is handled by the order property of a currency object.

Country information

To use it:

>>> import ccy
>>> c = ccy.country('us')
>>> c
'United States'
>>> ccy.countryccy('us')
'USD'

Not all the country codes are standard ISO 3166-1 alpha-2. There is a function for adding extra pseudo-countries:

import ccy
ccy.set_new_country('EU','EUR','Eurozone')

Set a new country with code 'EU', currency 'EUR' named 'Eurozone'. This pseudo country is set in the library already.

Date and Periods

The module is shipped with a date module for manipulating time periods and converting dates between different formats. The period function can be used to create Period instances:

>>> from ccy import period
>>> p = period('1m')
>>> p
1M
>>> p += '2w'
>>> p
1M2W
>>> P += '3m'
>>> p
4M2W

Requirements

  • Python 2.6 or above, including Python 3
  • pytz for Countries information.

Installation

This library works for Python 2.6 and higher, including Python 3.

Using `easy_install`:

easy_install ccy

Using `pip`:

pip install ccy

From source:

python setup.py install

It requires the pytz package.

Runnung tests

From within the package directory:

python runtests.py

ccy's People

Contributors

lsbardel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.