title: How best to calculate derived currency rate conversions using C#/LINQ?
body: <pre><code> class FxRate {
       string Base { get; set; }
       string Target  { get; set; }
       double Rate { get; set; }
   }
  
   private IList&lt;FxRate&gt; rates = new List&lt;FxRate&gt; {
            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}
            // ...
   };
  </code></pre>
  
  <p>Given a large yet incomplete list of exchange rates where all currencies appear at least once (either as a target or base currency): What algorithm would I use to be able to derive rates for exchanges that aren't directly listed?</p>
  
  <p>I'm looking for a general purpose algorithm of the form: </p>
  
  <pre><code> public double Rate(string baseCode, string targetCode, double currency)
   {
        return ...
   }
  </code></pre>
  
  <p>In the example above a derived rate would be GBP->CHF or EUR->SEK (which would require using the conversions for EUR->USD, USD->CHF, CHF->SEK)</p>
  
  <p>Whilst I know how to do the conversions by hand I'm looking for a tidy way (perhaps using LINQ) to perform these derived conversions perhaps involving multiple currency hops, what's the nicest way to go about this?</p>