在R中绘制一个困难的功能,并通过一分解找到根
eq <- function(x){ sum(exp(-Ln.M_Return[,1]/x)) / 168 - 1 }
# Ln.M_Return[,1] is a vector of stock return, and its length is 168.
我的第一个目标是绘制此功能的情节。但是,这里总是有一个错误。 当我使用“曲线”函数时,
curve(eq(x))
它将显示一个错误消息:
Error in curve(eq(x)) : 'expr'
In addition: Warning message:
In -Ln.M_Return[, 1]/x :
longer object length is not a multiple of shorter object length
我尝试了其他一些方法,例如plot()和xyplot(),但没有任何更改。
我的主要目的实际上是使用二次方法来找到该函数的根,这是Aumann-Serlano风险指数的公式。 因此,我选择首先绘制图并近似根的位置。 然后,我将使用一些分分码来找到根。 感谢您耐心地阅读我的问题!
eq <- function(x){ sum(exp(-Ln.M_Return[,1]/x)) / 168 - 1 }
# Ln.M_Return[,1] is a vector of stock return, and its length is 168.
My first goal is to draw the plot for this function. However, there is always an error here.
When I use "curve" function,
curve(eq(x))
it will appear an error message:
Error in curve(eq(x)) : 'expr'
In addition: Warning message:
In -Ln.M_Return[, 1]/x :
longer object length is not a multiple of shorter object length
I have tried some other methods, like plot() and xyplot(), but nothing changed.
My main purpose is actually using bisection method to find the root of the function, which is the formula of Aumann-Serrano riskiness index.
Thus, I choose to draw the plot first and approximate the location of the root.
Then I will use some codes of bisection to find the root.
Thanks for reading my question patiently!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有您的
ln.m_return
,我创建了一些随机数据。您应该在curve
函数中vectorize
您的方程式如下:output:
Without having your
Ln.M_Return
, I created some random data. You shouldVectorize
your equation in thecurve
function like this:Output: