Reputation: 2710
How can I obtain the current exchange rate for two given currencies in matlab?
I tried this one, however it seems that the web service is no longer available.
Is there another easy way of obtaining the up-to-date currency exchange rates through a web service in matlab?
Upvotes: 3
Views: 3630
Reputation: 998
This is an old question, but thought I would update the answer. I made this currency converter function in MATLAB (exchangerate.m) that utilizes the openexchangerates.org API, which is better supported and also includes historical data. Here's a description how it works (it's very simple):
This function returns exchange rates obtained from openexchangerates.org using their API. To work correctly, one must be connected to the Internet. The default app_id is from a free account to openexchangerates.org, which has a limit of 1000 API requests/month. For more flexibility, sign up for your own free or paid account and replace the app_id value with your own id number.
Inputs:
1) base: a string denoting the base currency, which is set to have a value of 1. If an empty string '' is provided, the default 'USD' is used. See list of valid currency abbreviations below.
2) curr: a string or cell array of strings denoting the currency abbreviation to compare with the base currency. If 'all' or '' is provided as input, then all available currencies are returned. See list of valid currency abbreviations below.
3) date: an optional string containing the date desired for the exchange rate (historical data may not always be available). The input should be in the form 'YYYY-MM-DD'. To get the latest exchange rate data, use date = 'latest' or '', which is the default value. Historical data from 1999 and onward
Outputs:
1) rates: a number or vector indicating the exchange rate(s) between the desired currency (currencies), curr, and the base currency, base.
2) currencies: a cell array of the corresponding currency abbreviations in rates.
3) rate_struct: a structure with field names equal to the currency abbreviations and associated values being the rates. This output just combines rates and currencies for convenience.
Examples:
1) Get the latest exchange rate between Bitcoin and the US Dollar (Note: All country abbreviations are listed in the m-file)
[rates,currencies,rates_struct] = exchangerate('USD','BTC');
>> rates = 1.614e-3
>> currencies = 'BTC'
>> rates_struct =
BTC: 1.614e-3
2) Get latest exchange rates for all available currencies
[rates,currencies,rates_struct] = exchangerate();
3) Obtain exchange rates for Bitcoin, Indian rupee, and Euro using the US Dollar as base currency on June 5, 2013
[rates,currencies,rates_struct] = exchangerate('USD',{'BTC','INR','EUR'},'2013-06-05');
>> rates = [8.246e-3; 5.672e1; 7.642e-1]
>> currencies = {'BTC';'INR';'EUR'}
>> rates_struct =
BTC: 8.246e-3
INR: 5.672e1
EUR: 7.642e-1
Upvotes: 0
Reputation: 7175
Build a local class from a currency conversion web service using CREATECLASSFROMWSDL. You can then use the web service's operations to do the conversion using the class methods. One currency conversion web service (there are many) is available at http://www.webservicex.net/CurrencyConvertor.asmx?WSDL. Here's an example of its use:
>> converter = createClassFromWsdl('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'); Retrieving document at 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL' >> converter = CurrencyConvertor endpoint: 'http://www.webservicex.net/CurrencyConvertor.asmx' wsdl: 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL' >> ConversionRate(converter, 'CAD', 'EUR') ans = 0.7059 >> ConversionRate(converter, 'USD', 'CAD') ans = 0.953
Note that ConversionRate returns a char array, i.e. you still have to convert the result with str2double if you want to do calculations with the exchange rate.
A list of the currency abbreviations is available at http://www.webservicex.net/ws/wsdetails.aspx?wsid=10.
Upvotes: 3