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

Possible Error Root Finding #90

Open
wleyden opened this issue Oct 12, 2017 · 1 comment
Open

Possible Error Root Finding #90

wleyden opened this issue Oct 12, 2017 · 1 comment

Comments

@wleyden
Copy link

wleyden commented Oct 12, 2017

I am fairly new to Julia, and to coding in general so this may be more of an issue with my code than the package.

I was attempting to calculate an Equity Risk Premium for the US Markets, and to do so I was using this equation:

Price = (Earnings_1/(1+r)^1)+(Earnings_2/(1+r)^2)+(Earnings_3/(1+r)^3)+(Earnings_4/(1+r)^4)+(Earnings_5/(1+r)^5)+(((Earnings_5)(RiskFreeRate))/((1+r)^5)(r-RiskFreeRate))

I realized that I could solve for 0 by simply moving the price to the other side - making it a root solving program.

So, the code I wrote was:

f(x) =
((spyearnings1/((1+x)^1))+
(spyearnings2/((1+x)^2))+
(spyearnings3/((1+x)^3))+
(spyearnings4/((1+x)^4))+
(spyearnings5/((1+x)^5))+
(spyearnings6/((x-riskfreeUSA)*((1+x)^5)))-
spyprice)


x = (fzero(f, 0)) #Answer Given: ~-2.815,

x, f(x)

Answer Given :~-2.815, -2549.33 (Price of the S&P500 --> It is negative because it was subtracted in the equation) | Correct answer (or at least intended answer): 0.073, 0

I realized the function solves perfectly for the parts where there is an x; however, it does not make f(x) = 0 (once again this could be because I did not write the code properly). Moreover, I am not sure if it is the aim of this package to set f(x) = 0. If it is your goal to solve so that f(x) = 0 this may be due to an error in your program, and if it is not you can ignore this (although that would be a useful feature to have).

Thank you for taking the time to read this, I hope it is somewhat helpful in improving your package.

@jverzani
Copy link
Member

jverzani commented Nov 8, 2017

Sorry to be so tardy getting back. I don't know what values you used for spyearningsX to investigate. Setting all the unknown values to 1 works to find a zero. My suggestion would be to try with verbose=TRUE to get more information about the algorithm. Maybe that would lead to something we can address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants