JuliaMath / JuliaMath/Roots.jl
Possible Error Root Finding
- Dominant language
- Julia
- Stars
- 413
- Forks
- 61
- Avg merge
- 57m
- Merged PRs (30d)
- 5
Description
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:
```julia
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.