Esempio n. 1
0
 def convert(self, money_source, code_target):
     """ 'source' is a Money instance and
     'target' a money code (CHF, EUR).
     """
     xrates.base = 'USD'
     xrates.setrate(money_source.currency,
                    Decimal(self.rates[money_source.currency]))
     xrates.setrate(code_target, Decimal(self.rates[code_target]))
     return money_source.to(code_target)
Esempio n. 2
0
    def test_multiple_xrates(self):
        xrates.install('money.exchange.SimpleBackend')
        self.assertTrue(xrates)
        xrates.base = 'XXX'
        xrates.setrate('AAA', Decimal('2'))

        from money.exchange import ExchangeRates
        another = ExchangeRates()
        another.install('money.exchange.SimpleBackend')
        self.assertTrue(another)
        another.base = 'XXX'
        another.setrate('AAA', Decimal('100'))

        self.assertEqual(xrates.rate('AAA'), Decimal('2'))
        self.assertEqual(another.rate('AAA'), Decimal('100'))
Esempio n. 3
0
 def test_multiple_xrates(self):
     xrates.install('money.exchange.SimpleBackend')
     self.assertTrue(xrates)
     xrates.base = 'XXX'
     xrates.setrate('AAA', Decimal('2'))
     
     from money.exchange import ExchangeRates
     another = ExchangeRates()
     another.install('money.exchange.SimpleBackend')
     self.assertTrue(another)
     another.base = 'XXX'
     another.setrate('AAA', Decimal('100'))
     
     self.assertEqual(xrates.rate('AAA'), Decimal('2'))
     self.assertEqual(another.rate('AAA'), Decimal('100'))
Esempio n. 4
0
    def test_multiple_xrates(self):
        xrates.install("money.exchange.SimpleBackend")
        self.assertTrue(xrates)
        xrates.base = "XXX"
        xrates.setrate("AAA", Decimal("2"))

        from money.exchange import ExchangeRates

        another = ExchangeRates()
        another.install("money.exchange.SimpleBackend")
        self.assertTrue(another)
        another.base = "XXX"
        another.setrate("AAA", Decimal("100"))

        self.assertEqual(xrates.rate("AAA"), Decimal("2"))
        self.assertEqual(another.rate("AAA"), Decimal("100"))
Esempio n. 5
0
    def __init__(self):

        self.currencies = ["JPY", "EUR", "CAD", "CNY", "GBP"]

        self.rates = [
            Decimal("122.690"),
            Decimal("0.92823"),
            Decimal("1.32925"),
            Decimal("6.37419"),
            Decimal("0.65742"),
        ]

        xrates.install("money.exchange.SimpleBackend")
        xrates.base = "USD"

        for i in range(len(self.currencies)):
            xrates.setrate(self.currencies[i], self.rates[i])
Esempio n. 6
0
def setup_xrates(base, rates):
    """
    If using the Python money package, this will set up the xrates exchange
    rate data.

    :param base:
        The string currency code to use as the base

    :param rates:
        A dict with keys that are string currency codes and values that are
        a Decimal of the exchange rate for that currency.
    """

    xrates.install('money.exchange.SimpleBackend')
    xrates.base = base
    for code, value in rates.items():
        xrates.setrate(code, value)
Esempio n. 7
0
def setup_xrates(base, rates):
    """
    If using the Python money package, this will set up the xrates exchange
    rate data.

    :param base:
        The string currency code to use as the base

    :param rates:
        A dict with keys that are string currency codes and values that are
        a Decimal of the exchange rate for that currency.
    """

    xrates.install('money.exchange.SimpleBackend')
    xrates.base = base
    for code, value in rates.items():
        xrates.setrate(code, value)
Esempio n. 8
0
 def setUpClass(cls):
     xrates.install('money.exchange.SimpleBackend')
     xrates.base = 'XXX'
     xrates.setrate('AAA', Decimal('2'))
     xrates.setrate('BBB', Decimal('8'))
Esempio n. 9
0
 def test_base_not_set_warning(self):
     with self.assertRaises(Warning):
         xrates.setrate("AAA", Decimal("2"))
Esempio n. 10
0
 def load_testing_data(self):
     xrates.base = 'XXX'
     xrates.setrate('AAA', Decimal('2'))
     xrates.setrate('BBB', Decimal('8'))
Esempio n. 11
0
 def setup_class(cls):
     xrates.backend = 'money.exchange.SimpleBackend'
     xrates.base = 'USD'
     xrates.setrate('EUR', Decimal(2))
     xrates.setrate('JPY', Decimal(8))
Esempio n. 12
0
 def load_testing_data(self):
     xrates.base = "XXX"
     xrates.setrate("AAA", Decimal("2"))
     xrates.setrate("BBB", Decimal("8"))
Esempio n. 13
0
 def test_base_not_set_warning(self):
     with self.assertRaises(Warning):
         xrates.setrate('AAA', Decimal('2'))
Esempio n. 14
0
from money import XMoney
from money import xrates
import decimal
import pandas as pd

# install abstract base class
xrates.install('money.exchange.SimpleBackend')
#set US Dollar as the currency the others will be converted to
xrates.base = 'USD'
# set the exchange rate for EUR to USD
xrates.setrate('EUR', decimal.Decimal('0.9'))
# set the exchange rate for GBP to USD
xrates.setrate('GBP', decimal.Decimal('0.8'))

# data frame - uses Pandas' Extension Array Interface
df = pd.DataFrame({"money": MoneyArray(['GBP 100', 'EUR 300'], 'USD')})
print("The table with the currencies:\n", df)
# the data frame table is accessed via the row, ie 0 is row 1 & 1 is row 2.
# the subtraction method needs accessed through XMoney, a money subclass. Then it's converted to USD
difference = (df['money'][0].__sub__(df['money'][1])).to('USD')
print("\nDifference between GBP 100 & EUR 300, in USD:\n", difference)


Esempio n. 15
0
from decimal import Decimal
from money import Money, xrates

xrates.install('money.exchange.SimpleBackend')
xrates.base = 'USD'
xrates.setrate('USD', Decimal('1'))
xrates.setrate('KRW', Decimal('1165.95'))

a = Money(100, 'USD')
b = Money(1, 'KRW')

print(a.to('KRW'))
print(b.to('USD'))
print(a.to('KRW') + b)
Esempio n. 16
0
 def setUpClass(cls):
     xrates.install('money.exchange.SimpleBackend')
     xrates.base = 'XXX'
     xrates.setrate('AAA', Decimal('2'))
     xrates.setrate('BBB', Decimal('8'))
Esempio n. 17
0
def setup_module():
    xrates.backend = 'money.exchange.SimpleBackend'
    xrates.base = 'USD'
    xrates.setrate('EUR', Decimal(2))
Esempio n. 18
0
 def load_testing_data(self):
     xrates.base = 'XXX'
     xrates.setrate('AAA', Decimal('2'))
     xrates.setrate('BBB', Decimal('8'))
Esempio n. 19
0
 def test_base_not_set_warning(self):
     with self.assertRaises(Warning):
         xrates.setrate('AAA', Decimal('2'))
Esempio n. 20
0
from money import XMoney, xrates, Money
from decimal import Decimal

#Exchange rates current as of June 8th, 2016
xrates.install('money.exchange.SimpleBackend')
xrates.base = 'USD'
rates = {'EUR': 0.88}
for k, v in rates.iteritems():
    xrates.setrate(k, Decimal(v))

def money_converter(amount):
    """Returns value in USD
    """
    if amount == None:
        return None
    if amount[0] == '$':
        return int(round(float(amount[1:].replace(',', ''))))
    if amount[0] == '\xe2': #Euro
        return int(round(float(str(Money(amount[3:].replace(',', ''), 'EUR').to('USD')).replace(',', '')[4:])))
    return None
Esempio n. 21
0
from decimal import Decimal
import numpy as np
import math

xrates.install('money.exchange.SimpleBackend')
xrates.base = 'USD'

COOLING_FACTOR = 0.99
MAX_ITER = 1000
MAX_EVENTS = 10
MOVES_PER_TEMPERATURE = 5  #TKTK - find out how to decide on best number for this...
MAX_CHANGE_NUMBER = 8  #what's an appropriate number?

# TKTK Later make this so that it will pull exchange rates from API to get most updated rate
# {'', 'EUR', 'HKS', 'CAD', 'MYR', 'CLP', 'US', 'USD', 'CAN', 'CHF', 'GBP', 'SEK', 'AUD'}
xrates.setrate('HKS', Decimal('7.76'))
xrates.setrate('EUR', Decimal('0.92'))
xrates.setrate('MYR', Decimal('4.15'))
xrates.setrate('CAD', Decimal('1.34'))
xrates.setrate('CAN', Decimal('1.34'))
xrates.setrate('CLP', Decimal('653.35'))
xrates.setrate('CHF', Decimal('0.99'))
xrates.setrate('GBP', Decimal('0.82'))
xrates.setrate('SEK', Decimal('8.93'))
xrates.setrate('AUD', Decimal('1.31'))

# Set up gspread
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    '/Users/mollie/Dropbox (Datascope Analytics)/dancing_data/drive_key.json',
    scope)
Esempio n. 22
0
 def test_base_not_set_warning(self):
     xrates.uninstall()
     xrates.install('money.exchange.SimpleBackend')
     with self.assertRaises(Warning):
         xrates.setrate('AAA', Decimal('2'))
Esempio n. 23
0
# Attempt to extract the relevant exchange rates
# For simplicity, average the available guesses
exchange_rates = pd.DataFrame({
	'P': col4_por_ccy,
	'Q': col21_pos_ccy,
	'P2Q': col22_value_qc / col24_value_pc,
}).dropna().groupby(['P', 'Q']).mean()

# Allow the Money class to auto-convert
# See https://pypi.org/project/money/#currency-exchange
money_rates.install('money.exchange.SimpleBackend')
money_rates.base = portfolio_ccy
for ((p, q), c) in exchange_rates['P2Q'].items():
	assert (p == portfolio_ccy)
	money_rates.setrate(q, 1 / Decimal(c))

# Sanity check, specific to the current task
assert (Money(1, 'CHF').to('USD') < Money(1, 'USD'))

"""
	Task 1a (and 1b)
	Compute the total net assets and total number of shares
	
	Assume that the value of an asset is
		its position market value (in portfolio currency)
			24_Position-Valuation-MarketValuePC
	
	Assume that 
		total net assets = (share price) x (total number of shares)
	[This doesn't give an integer number, but I don't know that it should]