tpemartin / 112-2-programming-for-economic-modeling

MIT License
0 stars 1 forks source link

Exercise CES and packing #13

Open tpemartin opened 1 year ago

tricer963 commented 1 year ago
import numpy as np

def CESUtility(*alpha, rho):
    def ces(*x):
        x = np.array(x)
        return sum(x**(rho) * alpha)**(1/rho)

    return ces

u = CESUtility(0.3, 0.3, 0.4, rho=2)
print(u(2,4,5))
u2 = CESUtility(0.2, 0.2, 0.3, 0.3, rho=2)
print(u2(1, 2, 2, 1))
chengpeter88 commented 1 year ago
import numpy as np

def CESUtility(*alpha, rho):
    def ces(*X):
        X = np.array(X)
        X = X.astype(float)
        X = X.reshape(-1)
        return sum(X ** (rho) * alpha)**(1/rho)

    return ces
u = CESUtility(0.3, 0.3, 0.4, rho=2)
u(2, 4, 5)