Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
3.50/5 (4 votes)
See more:
Hi,
We are designing a java based application for currency conversion where the currency name and currency decode values are stored in Currency Table,The foreign exchange rates are stored in Foreign_exchange rates table.I have to go ahead and implement this,can you please suggest me some ideas as to how should i go about implementing this.This scenario is in Trading based real time application where the foreign exchange rates are changing every now and then,so my question is how will i get the latest value which will be in sync and calculate the "correct conversion rate".Please advice..What datastructure should i use for implementing this.


Currency Table
Currency name| Decode
Indian Rupee | INR



Foreign Exchange Rate(Example) table
CurrencyName| F_E_Name| F_E_Value
INR         | USD     | 46
INR         | EUR     | 56
INR         | GBP     | 80 
INR         | Dinar   | 120 
... so on

The above values will be got from a foreign exchange feeder system,how will i ensure the values are in sync always?Hope my question is understood now.

i have also implemented the below classes.

class currency{
   private int currencyPk;
   private String primaryCurrencyName;
   private String decode;
   //getter and setters for the same
   }


class foreignExchangeRate{
   private int currencyFk;
   private String primaryCurrencyName;
   private String foreignExchangeCurrencyName;
   private int foreignExchangeCurrencyValue;
   //getter and setters for the same
   }

Please advice on the implementation part

[edit]Code block moved to cover only the code - OriginalGriff[/edit]
Posted
Updated 17-Oct-10 0:58am
v2
Comments
OriginalGriff 17-Oct-10 7:21am    
Reason for my vote of 4: Why did you get univoted for this? Balanced.

1 solution

If you want to deal with unknown upates then you'll have to impliment some form of subscriber/publisher pattern. The publisher will be responsible for the base rates and the subscribers can calculate the values.

A word of advice about FX rates - they are not complicated but they do need to be handled with care. Rates can be applied straight or as a reciprical - multiply or divide.
If you are combining two rates, say GBP-USD and USD-EUR, to get a third, in this case GBP-EUR, you need to take into account the direction and decide if the rate should be straight or reciprical. You can't just hold everything as staright rates because the values will become corrupted by rounding.

Work out how you intend to combine rates and then you should see the pattern for storing them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900