为什么我不能将天然对数函数与数据集使用?

发布于 2025-01-17 22:05:20 字数 422 浏览 3 评论 0 原文

我有一个与数据集一起使用的代码。我发现它不想使用LN(x)功能。可以找到数据集在这里

LY <- ln(Apple$Close - Apple$Open)

log(x)中的警告:nans产生

Could you please help me to fix this problem?

I've got a code that works with the Data Set. I found out that it doesn't want to work with the ln(x) function. The data set can be found here.

LY <- ln(Apple$Close - Apple$Open)

Warning in log(x) : NaNs produced

Could you please help me to fix this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

死开点丶别碍眼 2025-01-24 22:05:20

由于股票可能上涨也可能下跌(不幸的是),收盘价可能小于开盘价,并且收盘价 - 开盘价可能为负值。取负数的自然对数是没有意义的;这就像除以零,或者更准确地说,就像取负数的平方根。

实际上,您可以取具有负实部的复数的对数

log(as.complex(-1))
## [1] 0+3.141593i

...但是“i乘以pi”对于进一步的数据可能不是一个非常有用的结果分析...

(在 R 中,log() 取自然对数。虽然 SciViews 包提供 ln() 作为同义词,但您可以不妨习惯使用log() - 这是大多数编程语言的约定...)

根据您想要执行的操作,关闭/打开比率的对数可以是有用的值 (log(Close/Open)):当 Close Close 时,此值为负。开盘收盘>时为正打开)。正如 @jpiversen 指出的,这称为对数回报;正如 @KarelZe 指出的, log(Close/Open) 在数学上相当于 log(Close) - log(Open) (这可能是你的教授想要的...... ???)

Since stocks can go down as well as up (unfortunately), Close can be less than Open and Close - Open can be negative. It just doesn't make sense to take the natural log of a negative number; it's like dividing by zero, or more precisely like taking the square root of a negative number.

Actually, you can take the logarithm of a complex number with a negative real part:

log(as.complex(-1))
## [1] 0+3.141593i

... but "i times pi" is probably not a very useful result for further data analysis ...

(in R, log() takes the natural logarithm. While the SciViews package provides ln() as a synonym, you might as well just get used to using log() - this is a convention across most programming languages ...)

Depending on what you're trying to do, the logarithm of the close/open ratio can be a useful value (log(Close/Open)): this is negative when Close < Open, positive when Close > Open). As @jpiversen points out, this is called the logarithmic return; as @KarelZe points out, log(Close/Open) is mathematically equivalent to log(Close) - log(Open) (which might be what your professor wanted ... ???)

花想c 2025-01-24 22:05:20

您在寻找对数回报吗?在这种情况下,公式为:

log(Apple$Close / Apple$Open)

由于两个正值的 A / B 始终为正,因此不会创建 NaN

Are you looking for logarithmic return? In that case the formula would be:

log(Apple$Close / Apple$Open)

Since A / B for two positive values is always positive, this will not create NaNs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文