2013-02-06 34 views
1

我写标识股市数据模式的程序,我试图找出以下的短期格局:浮在java中比较识别模式

如果低值低于开盘值由至少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浮动的ArrayList。我正在计算 这是我写的代码,用于尝试识别数据中的模式。

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 

是因为我比较花车吗?任何帮助,将不胜感激。

回答

4

它看起来像你混淆了AND运算符和OR运算符。

您声明只有在满足两个条件的情况下您才希望输出,但是您的代码表示如果满足任一条件就会输出。

+1

argh这样一个愚蠢的错误!我花了这么长时间才写出这个问题:谢谢 – James