-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
ENH: Add capm to financial.py #11058
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -759,3 +759,51 @@ def mirr(values, finance_rate, reinvest_rate): | |
numer = np.abs(npv(reinvest_rate, values*pos)) | ||
denom = np.abs(npv(finance_rate, values*neg)) | ||
return (numer/denom)**(1/(n - 1))*(1 + reinvest_rate) - 1 | ||
|
||
def capm(rf, beta, rm): | ||
""" | ||
calculate the minimum rate of return using CAPM | ||
(Capital Asset Pricing Model). | ||
|
||
parameters: | ||
----------- | ||
rf: The risk free rate of retun. | ||
beta: The company's beta factor which measures the sensitivity | ||
of an investment return to market movement | ||
rm: market rate of return | ||
|
||
Notes. | ||
------ | ||
The CAPM is an alternative method of calculating cost of equity | ||
capital for an investment. it is made up of two sides; Risk free | ||
rate i.e. the basic rate which all projects must earn if | ||
it is completely free from risk. and the Risk Premium which | ||
is gotten after applying the project | ||
beta to the difference between market return and risk rate of return. | ||
|
||
Example: | ||
-------- | ||
XYZ limited wants to determine its minimum required rate of return if | ||
the risk free rate is 7%, market rate of return is 10% and the company | ||
has a beta factor of 12. | ||
|
||
Solution | ||
-------- | ||
rf = 0.07, beta = 12, rm = 0.10 | ||
|
||
min.required rate of return = 0.07 + 1.2(0.10 - 0.07) | ||
=0.106 | ||
=10.6% | ||
|
||
""" | ||
try: | ||
rf >= 1 or rm >= 1: | ||
return "values cannot be greater than or equals 1" | ||
else: | ||
ke = rf + beta * (rm - rf) | ||
return ke | ||
except Exception as e: | ||
raise e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyntaxError here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops! I missed out the if statement there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"I think there's a general reluctance to add new financial functions to numpy: #2880."
Does it mean contributing to the finance library is void for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olamilekan000 indeed. I've added a comment to gh-2880 to that effect.