我正在编写一个程序来识别股票市场数据中的模式,并且我正在尝试识别以下短期模式:
如果最低价比开盘价至少小 3 且收盘价在开盘价的 2 以内。
我正在读取以下格式的 CSV 文件中的值,但没有标题:
Open High Low Close
353.4 359.2 347.7 349
351.4 354.08 349.1 353.1
350.1 354 349.3 350.2
352.4 353.28 348.7 349.8
345.7 352.3 345.7 351.5
这些值存储在名为 closePrice、openPrice、lowPrice 的 float 组列表中。我正在计算 这是我编写的代码,用于尝试识别数据中的模式。
for(int i = 0; i < closePrice.size(); i ++)
{
//Difference between opening price and the price low
float priceDrop = Math.abs(openPrice.get(i) - lowPrice.get(i));
//Difference between opening price and close price (regardless of positive or negative)
float closingDiff = Math.abs(openPrice.get(i) - closePrice.get(i));
float dropTolerance = 3.0f;
float closingTolerance = 2.0f;
if( (priceDrop > dropTolerance) || (closingDiff < closingTolerance) )
{
System.out.println("price drop = " + priceDrop + " closing diff = " + closingDiff);
System.out.println("Hangman pattern" + "\n");
}
}
所以它应该做的是测试价格是否下跌超过 3,然后收盘价是否在开盘价的 2 以内,但是当我运行程序时,它似乎让一切都绕过了 if 语句。我的输出是:
price drop = 5.6999817 closing diff = 4.399994
Hangman pattern
price drop = 2.2999878 closing diff = 1.7000122
Hangman pattern
price drop = 0.8000183 closing diff = 0.1000061
Hangman pattern
是不是因为我在比较花车?任何帮助将不胜感激。
最佳答案
看来您混淆了 AND 运算符和 OR 运算符。
你说你只想在两个条件都满足时输出,但你的代码说如果满足其中一个条件你就会输出。
关于java - java中的 float 比较以识别模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14733781/