title: Binomial iterated expectation in Cython
body: <p>I am brand new to Cython. How to convert the Python function called Values below to Cython? With factors=2 and i=60 this takes 2.8 secs on my big Linux box. The goal is sub 1 sec with factors=2 and i=360.</p>
  
  <p>Here's the code. Thanks!</p>
  
  <pre><code>import numpy as np
  import itertools
  
  class Numeraire:
      def __init__(self, rate):
          self.rate = rate
      def __call__(self, timenext, time, state):
          return np.exp(-self.rate*(timenext - time))
  
  def Values(values, i1, i0=0, numeraire=Numeraire(0.)):
      factors=len(values.shape)
      norm=0.5**factors
      for i in np.arange(i1-1, i0-1, -1):
          for j in itertools.product(np.arange(i+1), repeat=factors):
              value = 0.
              for k in itertools.product(np.arange(2), repeat=factors):
                  value += values[tuple(np.array(j) + np.array(k))]
              values[j] = value*norm*numeraire(i+1, i, j)
      return values
  
  factors = 2
  i = 60
  values = np.ones([i+1]*factors)
  Values(values, i, numeraire=Numeraire(0.05/12))
  print values[(0,)*factors], np.exp(-0.05/12*i)
  </code></pre>