如何在R中表示这个几何级数?

时间:2019-07-18 10:27:29

标签: r probability

我正在阅读有关创建做市商的论文,并正在尝试实施某些构想。如何用R表示这个系列?我知道第一个方程应该输出一个概率,而第二个方程应该输出一个接近买入价的数字。

A priori for a sell order

To calculate the bid price

我刚刚使用了多个seq()函数来尝试解决此问题,尽管错误可能来自于我的分配公式。

Psell <- seq(from = v0 - 4*sd(ba$Price, na.rm = T), to = ba$Bid.Price[1] - 1, 
    by = (I + (1 - I)*.2)*dnorm(72.62, v0, sd(ba$Price, na.rm = T))) + 
  seq(from = ba$Bid.Price[1], to = v0 + 4*sd(ba$Price, na.rm = T) - 1,
      by = (I + (1 - I)*.2)*dnorm(72.62, v0, sd(ba$Price, na.rm = T)))

Psell <- tail(Psell, 1)

Pb <- (1/Psell) * (seq(from = v0 - 4*sd(ba$Price, na.rm = T), to = ba$Bid.Price[1] - 1, 
                       by = (I + (1 - I)*.2)*72.62*dnorm(72.62, v0, sd(ba$Price, na.rm = T))) + 
                     seq(from = ba$Bid.Price[1], to = v0 + 4*sd(ba$Price, na.rm = T) - 1,
                         by = (I + (1 - I)*.2)*72.62*dnorm(72.62, v0, sd(ba$Price, na.rm = T))))
Pb

Psell返回144.2665, Pb返回0.9908123

期望Psell的概率,而Pb接近72的数字

如果需要解释使用的变量或其他内容,请告诉我!

谢谢!

1 个答案:

答案 0 :(得分:0)

已解决:

使用序列生成系列所需的数字范围,然后使用for循环将我的运算应用于每个元素。

lst <- seq(from = v0 - 4*sd(ba$Price, na.rm = T), to = v0 + 4*sd(ba$Price, na.rm = T), by = 1)

count <- 0
for(i in 1:length(lst)){
  temp <- (I + (1 - I)*.2)*dnorm(lst[i], v0, sd(ba$Price, na.rm = T))
  count <- count + temp
}
count

count2 <- 0
for(i in 1:length(lst)){
  temp2 <- (I + (1 - I)*.2)*lst[i]*dnorm(lst[i], v0, sd(ba$Price, na.rm = T))
  count2 <- temp2 + count2
}

count2 * 1/count