Example usage¶
Through these examples, we are intending to show you how to use forxpy in a project.
Imports¶
from forxpy.forxpy import retrieve_data
from forxpy.forxpy import fastest_slowest_currency
from forxpy.forxpy import currency_convert
from forxpy.forxpy import plot_historical
import forxpy
forxpy.__version__
'2.0.0'
Retrive the data¶
The function retrieve_data generated the data from the source and by setting export_csv = TRUE, you’ll be able to save the data locally too.
data = retrieve_data(export_csv = False)
data.head()
| date | AUD | BRL | CNY | EUR | HKD | INR | IDR | JPY | MXN | ... | SGD | ZAR | KRW | SEK | CHF | TWD | TRY | GBP | USD | CAD | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2017-01-03 | 0.9702 | 0.4121 | 0.1930 | 1.3973 | 0.1732 | 0.01965 | 0.000100 | 0.01140 | 0.06439 | ... | 0.9264 | 0.09740 | 0.001112 | 0.1465 | 1.3064 | 0.04150 | 0.3744 | 1.6459 | 1.3435 | 1.0 |
| 2 | 2017-01-04 | 0.9678 | 0.4129 | 0.1920 | 1.3930 | 0.1717 | 0.01959 | 0.000099 | 0.01134 | 0.06242 | ... | 0.9240 | 0.09767 | 0.001111 | 0.1460 | 1.3005 | 0.04141 | 0.3722 | 1.6377 | 1.3315 | 1.0 |
| 3 | 2017-01-05 | 0.9708 | 0.4133 | 0.1922 | 1.4008 | 0.1708 | 0.01954 | 0.000099 | 0.01145 | 0.06195 | ... | 0.9260 | 0.09743 | 0.001118 | 0.1468 | 1.3083 | 0.04161 | 0.3674 | 1.6400 | 1.3244 | 1.0 |
| 4 | 2017-01-06 | 0.9668 | 0.4116 | 0.1911 | 1.3953 | 0.1706 | 0.01942 | 0.000099 | 0.01133 | 0.06213 | ... | 0.9202 | 0.09647 | 0.001103 | 0.1461 | 1.3020 | 0.04131 | 0.3640 | 1.6275 | 1.3214 | 1.0 |
| 5 | 2017-01-09 | 0.9728 | 0.4135 | 0.1907 | 1.3967 | 0.1706 | 0.01942 | 0.000099 | 0.01138 | 0.06202 | ... | 0.9214 | 0.09681 | 0.001100 | 0.1460 | 1.3020 | 0.04129 | 0.3557 | 1.6084 | 1.3240 | 1.0 |
5 rows × 25 columns
Fastest and Slowest growing currency¶
The function fastest_slowest_currency takes currency exchange rates data as input and returns a list of two strings containing the fastest and slowest growing currency exchange rate in relation to Canadian Dollar. The data provided contains currency code in the format FX—CAD, the average exchange rate and the date.
fastest_slowest_currency('2019-05-23', '2022-05-30')
[['TRY', 0.0708], ['IDR', 8.9e-05]]
Currency Convertor¶
The function currency_convert takes a currency value and the currency type to be converted to as input and returns the converted currency value as per the current conversion rate.
currency_convert(23, 'USD', 'CAD')
30.622
Plotting Historically¶
The function plot_historical plots the historical rate of the entered currencies within a specific period of time.
plot_historical('2020-05-23', '2022-05-30', 'USD', 'CAD')