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

MIT License
0 stars 1 forks source link

Exercise CES utility function #5

Open tpemartin opened 1 year ago

tricer963 commented 1 year ago
def CESex(v,a):
    def CESen(x,y):
        u = ((a*x)**(-v)+((1-a)*y)**(-v))**(-1/v)
        return u
    return CESen
CESen=CESex(0.5,0.7)
CESen(5, 25)
chengpeter88 commented 1 year ago
def ces_para(sigma,alpha):
    def ces(x, y):
        return (alpha*x**(-sigma)+(1-alpha)*y**(-sigma))**(-1/sigma)
    return ces

ces=ces_para(0.5,0.7)
ces(1,2)
aryhsg commented 1 year ago
def CES(sigma, alpha):
    def ces(x, y):
        return (alpha * x ** (-sigma) + (1-alpha) * y ** (-sigma)) ** (-1/ sigma)
    return ces

ces = CES(0.2, 0.8)
ces(10,20)
12Maggie11 commented 1 year ago
class CES:
    def __init__(self, sigma, alpha):
        self.sigma=sigma
        self.alpha=alpha
    def utility(self, x, y):
        return (self.alpha*x**(-self.sigma)+(1-self.alpha)*y**(-self.sigma))**(-1/self.sigma)

ces=CES(0.5, 0.7)
ces.utility(10, 20)