I am trying to calculate the total probability of an investment returning positive after a given number of periods. It's been a while since I've done probability, so I don't really remember it all that well. Am I doing it right? I am getting fairly low numbers.
我试图计算一定数量的期后投资回报为正的总概率。我已经有一段时间了,因为我已经完成了概率,所以我真的不记得这一切。我做得对吗?我的数字相当低。
double totalProbPos = 1;
for (int i = 0; i < maxPeriods; i++) {
totalProbPos *= (probPos / 100);
}
totalProbPos = round(totalProbPos);
System.out.println("\nThe probability that your investment will return positive after " + maxPeriods + " periods is: \n " + totalProbPos + "%.");
Where:maxPeriods, probPos
are given by the user.
其中:maxPeriods,probPos由用户给出。
2 个解决方案
#1
0
totalProbPos *= (probPos / 100);
It is better to cast one of the operands to double to avoid integer divison issue (assuming you care about decimal points)
最好将其中一个操作数强制转换为两倍以避免整数除法问题(假设您关心小数点)
totalProbPos *= ((double)probPos / 100);
#2
0
I guess (with the emphasis on "guess") that the way to approach this problem is to try to derive a probability distribution for the return on investment at the end time. Then you just find the probability that the return is greater than zero (i.e., integral from 0 to infinity of the probability density). The probability distribution for return at the end time might be something like a Gaussian (normal) distribution, or it might be a distribution over discrete states, as given by a Markov chain. Maybe the original problem statement has some info which would help one figure out what to do.
我猜(强调“猜测”),解决这个问题的方法是尝试在结束时得出投资回报的概率分布。然后,您只需找到返回值大于零的概率(即,概率密度从0到无穷大的积分)。结束时返回的概率分布可能类似于高斯(正态)分布,或者它可能是离散状态的分布,如马尔可夫链所给出的。也许最初的问题陈述有一些信息可以帮助我们弄清楚该怎么做。
#1
0
totalProbPos *= (probPos / 100);
It is better to cast one of the operands to double to avoid integer divison issue (assuming you care about decimal points)
最好将其中一个操作数强制转换为两倍以避免整数除法问题(假设您关心小数点)
totalProbPos *= ((double)probPos / 100);
#2
0
I guess (with the emphasis on "guess") that the way to approach this problem is to try to derive a probability distribution for the return on investment at the end time. Then you just find the probability that the return is greater than zero (i.e., integral from 0 to infinity of the probability density). The probability distribution for return at the end time might be something like a Gaussian (normal) distribution, or it might be a distribution over discrete states, as given by a Markov chain. Maybe the original problem statement has some info which would help one figure out what to do.
我猜(强调“猜测”),解决这个问题的方法是尝试在结束时得出投资回报的概率分布。然后,您只需找到返回值大于零的概率(即,概率密度从0到无穷大的积分)。结束时返回的概率分布可能类似于高斯(正态)分布,或者它可能是离散状态的分布,如马尔可夫链所给出的。也许最初的问题陈述有一些信息可以帮助我们弄清楚该怎么做。