Commits

stevejb  committed 5b033ae

Making good progress

  • Participants
  • Parent commits 4dd9a0b

Comments (0)

Files changed (2)

File ootest/BellmanEquation.py

 
 # IMPORT THIS WITH:
 #
-# import BellmanEquation
+# 
+import numpy as np
 
 class BellmanEq:
-    "Hold the Bellman equation, a dynamic function"
+    "Hold the Bellman equation, a dynamic function" 
     def __init__(self):
         pass
 
     def __repr__(self):
-        mystr = "profit = z * inv * (1-tx) - p*tx + p_prime"
+        mystr = "profit = z * k^theta - (k_prime - (1-delta)*k)"
         return(mystr)
 
-    def bellmanFn(self, r, tx, p, p_prime, k, k_prime, z ):
-        """ it is assumed all arguments are same sized ndarray or scalar"""
-        inv = k_prime - 0.8 * k
-        profit = z * inv * (1-tx) - p*tx + p_prime
-        return(profit)
+    def bellmanFn(self, theta, rho, sigma_v, s, r, delta, tau_c, lambda_a, lambda_r, shock_mag, k, k_prime, p, p_prime, z, tshock, tsign ):
+        """ it is assumed all arguments are same sized ndarray or scalar
 
-    def discount(self, r):
+        The argument list must include all keys in the controlDict, parameter dict
+        and the shocks
+
+        In this particular parameterization, shock_mag is simply a magnitude of a shock
+
+        """
+
+        print("Vars: ")
+        print("\t k:" + str(k.shape))
+        print("\t k_prime:" + str(k_prime.shape))
+        print("\t p:" + str(p.shape))
+        print("\t p_prime:" + str(p_prime.shape))
+        print("\t delta:" + str(np.array(delta)))
+        print("\t theta:" + str(np.array(theta)))
+        print("\t tau_c:" + str(np.array(tau_c)))
+        print("\t z:" + str(np.array(z)))
+        print("\t tshock:" + str(np.array(tshock)))
+        print("\t tsign:" + str(np.array(tsign)))
+
+
+        # net profit is profit minus taxes. 
+        # profit is adjusted for firesale and
+        inv = k_prime - (1-delta) * k
+        net_profit = ((z + ((tshock * tsign)*shock_mag)) * k ** theta)*(1-tau_c)
+
+
+        # firesale is when the firm has a financing gap
+        zero_mat = np.zeros(inv.shape)
+        n_firesale_units = np.maximum(zero_mat, (p_prime - net_profit)*(1/s) )
+
+        # first step - make the indicator matrices (HW 2005 p. 1140)
+        # FIRE SALE MATRICES OF EQ. 13
+
+        phi_s = zero_mat.copy()
+        phi_s[n_firesale_units > 0] = 1
+        phi_n = np.ones((phi_s.shape)) - phi_s
+
+        profit = (net_profit + p)/(phi_n + s* phi_s)
+
+
+        equity = profit - inv + p_prime/(1+r)
+        return(equity)
+
+    def discount(self, theta, rho, sigma_v, s, r, delta, tau_c, lambda_a, lambda_r, shock_mag):
         return(1/(1+r))
 
+
     def description(self):
         mystr = "This is a simple investment model"
         return(mystr)
         pass
 
 
+

File ootest/setup.py

+from distutils.core import setup
+from distutils.extension import Extension
+from Cython.Distutils import build_ext
+
+ext_modules = [Extension("dpclient", ["dpclient.pyx"])]
+
+setup(
+  name = 'Cython DP Solver',
+  cmdclass = {'build_ext': build_ext},
+  ext_modules = ext_modules
+)