class FxRate {
string Base { get; set; }
string Target { get; set; }
double Rate { get; set; }
}
private IList<FxRate> rates = new List<FxRate> {
new FxRate {Base = "EUR", Target = "USD", Rate = 1.3668},
new FxRate {Base = "GBP", Target = "USD", Rate = 1.5039},
new FxRate {Base = "USD", Target = "CHF", Rate = 1.0694},
new FxRate {Base = "CHF", Target = "SEK", Rate = 8.12}
};
Given a large but incomplete list of exchange rates, where all currencies appear at least once (either as the target or base currency): Which algorithm would I use to be able to receive bets for exchanges that are not directly indicated?
I am looking for a general-purpose form algorithm:
public double Rate(string baseCode, string targetCode, double currency)
{
return ...
}
In the above example, the derivative rate will be GBP-> CHF or EUR-> SEK (which will require the use of conversions for EUR-> USD, USD-> CHF, CHF-> SEK)
While I know how to do conversions manually, I am looking for a neat way (possibly using LINQ) to perform these derivative conversions, possibly involving several changes in the currency, what is the best way to do this?