Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model tools: Add various utility functions #179

Merged
merged 8 commits into from
Oct 21, 2017
Merged

Model tools: Add various utility functions #179

merged 8 commits into from
Oct 21, 2017

Conversation

cc7768
Copy link
Member

@cc7768 cc7768 commented Oct 13, 2017

In this pull request, I introduce an abstract type AbstractUtility. I also include 4 concrete utility functions and their derivatives: LogUtility, CRRAUtility, CFEUtility, and EllipticalUtility -- The first two are typically used in modeling consumption utility and second two for labor utility.

Additionally, the folder modeltools can be a placeholder for adding things like production functions etc... in the future.

Example

using QuantEcon

u = LogUtility()

# Evaluate log utility at c=1
@show u(1.0)

# Evaluate derivative of log utility at c=1
@show derivative(u, 1.0)

@sglyon

@codecov-io
Copy link

codecov-io commented Oct 13, 2017

Codecov Report

Merging #179 into master will decrease coverage by 0.1%.
The diff coverage is 77.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
- Coverage    90.5%   90.39%   -0.11%     
==========================================
  Files          23       24       +1     
  Lines        1590     1624      +34     
==========================================
+ Hits         1439     1468      +29     
- Misses        151      156       +5
Impacted Files Coverage Δ
src/modeltools/utility.jl 77.77% <77.77%> (ø)
src/optimization.jl 95.38% <0%> (-0.54%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e1b8e0...8a5f3b7. Read the comment docs.

@natashawatkins
Copy link
Member

This is a cool idea that could be used to replace some of the code in the optimal taxation lectures!

I guess you prefer CRRAUtility over CRRAutility. I should change the lecture if so...

@sglyon
Copy link
Member

sglyon commented Oct 16, 2017

Hey @cc7768 let me know when you want a re view on this one.

I've seen a few changes come in since the PR opened os I've been waiting for your word to look closer

@cc7768
Copy link
Member Author

cc7768 commented Oct 16, 2017

I think this version is ready to review. There are 4 utility functions and their first derivative. There are also tests for each of them.

I will likely add some additional features (production function, aggregation functions, wage processes, etc...) in future PRs, but it is easier for me to do this in pieces than all at once.

Copy link
Member

@sglyon sglyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It will be nice to have these building blocks.

I saw a few places where coverage claims things aren't tested. These are mostly in the error checking and methods with Default values.

Also, We should add some docstrings that at a minimum write the functional form of the utility function. I think this belongs as a docstring on each type.

ξ::Float64
end

LogUtility() = LogUtility(1.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should get tested now.


function CRRAUtility(γ, ξ=1.0)
if abs(γ - 1.0) < 1e-8
error("Your value for γ is very close to 1... Consider using LogUtility")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get tested now.


function CFEUtility(ϕ, ξ=1.0)
if abs(ϕ - 1.0) < 1e-8
error("Your value for ϕ is very close to 1... Consider using LogUtility")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get tested now.

end

# These defaults are pulled straight from Evans Phillips 2017
EllipticalUtility(;b=0.5223, μ=2.2926) = EllipticalUtility(b, μ)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get tested now.

@sglyon
Copy link
Member

sglyon commented Oct 20, 2017

Can you rebase off master to get the fixes @Shunsuke-Hori made to the calls to Optim?

That will get tests outside of this PR passing

@sglyon
Copy link
Member

sglyon commented Oct 20, 2017

Actually, scratch that.

I can see that these test pass b/c travis said the pr portion of the CI passed. When this is ready for another look let me know and we'll get it merged.

@cc7768
Copy link
Member Author

cc7768 commented Oct 21, 2017

I think this is ready for review.

Did you want me to rebase or is it ok?

@sglyon sglyon merged commit 7394e23 into master Oct 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants