示例#1
0
  private ArrayList<String> getFinalEstimation() {
    class ResultSet {
      String method;
      double est;
      double low;
      double high;
      double gap;
    }

    ArrayList<String> texts = new ArrayList<String>();
    ResultSet[] rs = new ResultSet[7];
    for (int i = 0; i < 7; i++) {
      rs[i] = new ResultSet();
    }
    // result of distribution
    rs[0].method = "1 Month Simple";
    rs[0].est = marketAnalyzer.getAvg1MSPSqft();
    rs[0].low =
        rs[0].est
            - marketAnalyzer.getStd1MSPSqft() * 1.96 / Math.sqrt(marketAnalyzer.getCounter1M());
    rs[0].high =
        rs[0].est
            + marketAnalyzer.getStd1MSPSqft() * 1.96 / Math.sqrt(marketAnalyzer.getCounter1M());
    rs[0].gap = rs[0].high - rs[0].low;

    rs[1].method = "6 Months Simple";
    rs[1].est = marketAnalyzer.getAvg6MSPSqft();
    rs[1].low =
        rs[1].est
            - marketAnalyzer.getStd6MSPSqft() * 1.96 / Math.sqrt(marketAnalyzer.getCounter6M());
    rs[1].high =
        rs[1].est
            + marketAnalyzer.getStd6MSPSqft() * 1.96 / Math.sqrt(marketAnalyzer.getCounter6M());
    rs[1].gap = rs[1].high - rs[1].low;

    rs[2].method = "1 Year Simple";
    rs[2].est = marketAnalyzer.getAvg1YSPSqft();
    rs[2].low =
        rs[2].est
            - marketAnalyzer.getStd1YSPSqft() * 1.96 / Math.sqrt(marketAnalyzer.getCounter1Y());
    rs[2].high =
        rs[2].est
            + marketAnalyzer.getStd1YSPSqft() * 1.96 / Math.sqrt(marketAnalyzer.getCounter1Y());
    rs[2].gap = rs[2].high - rs[2].low;

    // result of regression
    if (reg6M.count > 2) {
      rs[3].method = "6 Months Regression";
      rs[3].est = reg6M.getY0();
      rs[3].low = rs[3].est - reg6M.getCi(reg6M.getX0());
      rs[3].high = rs[3].est + reg6M.getCi(reg6M.getX0());
      rs[3].gap = rs[3].high - rs[3].low;
    } else {
      rs[3].method = "";
      rs[3].est = 0;
      rs[3].low = 0;
      rs[3].high = 0;
      rs[3].gap = 999999999;
    }

    if (reg1Y.count > 2) {
      rs[4].method = "1 Year Regression";
      rs[4].est = reg1Y.getY0();
      rs[4].low = rs[4].est - reg1Y.getCi(reg1Y.getX0());
      rs[4].high = rs[4].est + reg1Y.getCi(reg1Y.getX0());
      rs[4].gap = rs[4].high - rs[4].low;
    } else {
      rs[4].method = "";
      rs[4].est = 0;
      rs[4].low = 0;
      rs[4].high = 0;
      rs[4].gap = 999999999;
    }

    rs[5].method = "6 Months Extrapolation";
    rs[5].est = marketAnalyzer.getExtpoResultPrice6M();
    rs[5].low =
        rs[5].est
            - marketAnalyzer.getExtpoResultStd6M()
                * 1.96
                / Math.sqrt(marketAnalyzer.getCounter6M());
    rs[5].high =
        rs[5].est
            + marketAnalyzer.getExtpoResultStd6M()
                * 1.96
                / Math.sqrt(marketAnalyzer.getCounter6M());
    rs[5].gap = rs[5].high - rs[5].low;

    rs[6].method = "1 Year Extrapolation";
    rs[6].est = marketAnalyzer.getExtpoResultPrice1Y();
    rs[6].low =
        rs[6].est
            - marketAnalyzer.getExtpoResultStd1Y()
                * 1.96
                / Math.sqrt(marketAnalyzer.getCounter1Y());
    rs[6].high =
        rs[6].est
            + marketAnalyzer.getExtpoResultStd1Y()
                * 1.96
                / Math.sqrt(marketAnalyzer.getCounter1Y());
    rs[6].gap = rs[6].high - rs[6].low;

    for (int i = 0; i < 7; i++) {
      for (int j = 0; j < 7; j++) {
        if (rs[i].gap < rs[j].gap) {
          ResultSet rsTemp = rs[i];
          rs[i] = rs[j];
          rs[j] = rsTemp;
        }
      }
    }

    for (int i = 0; i < 7; i++) {
      if (Double.isNaN(rs[i].est)) {
      } else {
        texts.add(rs[i].method);
        texts.add(Formater.toCurrency(rs[i].est));
        texts.add(Formater.toCurrency(rs[i].low));
        texts.add(Formater.toCurrency(rs[i].high));
      }
    }
    // If more than 10 data points in the recent time interval
    //		if (marketAnalyzer.getCounter1M() >= 10) {
    //			textFinalEst1M.setText(Formater.toCurrency(marketAnalyzer.getAvg1MSPSqft()));
    //			lblEstReason.setText("Enough data recently\nand average the result");
    //		}
    //		else if (marketAnalyzer.getCounter6M() >= 30) {
    //			textFinalEst1M.setText(Formater.toCurrency(marketAnalyzer.getReg6MSPSqft().getY0()));
    //			lblEstReason.setText("Use 6-month regression");
    //		}
    //		else if (marketAnalyzer.getCounter1Y() >= 50) {
    //			textFinalEst1M.setText(Formater.toCurrency(marketAnalyzer.getReg1YSPSqft().getY0()));
    //			lblEstReason.setText("Use 1-year regression");
    //		}
    //		else {
    //			textFinalEst1M.setText(Formater.toCurrency(marketAnalyzer.getExtpoResultPrice6M()));
    //			lblEstReason.setText("Not enough data.\nUse extrapolation");
    //		}

    return texts;
  }
示例#2
0
  /**
   * @param status status 0 means search button is clicked status 1 menas redo button is clicked
   * @throws Exception The event when the search button or redo button is clicked
   */
  private void searchClickEvent(int status) throws Exception {
    if (status == 0) { // If search button is clicked
      String str = new String();
      str = getSqlStmtForMLX(); // New SQL statement according to search criteria defined
      System.out.println(str);

      // Search from database and generate CSV result
      marketAnalyzer = new MarketAnalyzer(str);
      // Initialize the MarketAnalyzer with the SQL statement defined
      // A new ResultSet will be generated
    } else if (status == 1) { // If redo button is clicked
      // do nothing, use the old marketAnalyzer
    }

    Addition addition = new Addition();
    int bchmkIndex = comboBchmkIndex.getSelectionIndex();
    if (bchmkIndex == 0 || bchmkIndex == -1) {
      addition.indexName = "caseshiller";
    } else if (bchmkIndex == 1) {
      addition.indexName = "zillow";
    }

    // Calculate average prices
    marketAnalyzer.doAnalysis(addition);
    text1MAvg.setText(Formater.toCurrency(marketAnalyzer.getAvg1MSPSqft()));
    text6MAvg.setText(Formater.toCurrency(marketAnalyzer.getAvg6MSPSqft()));
    text1YAvg.setText(Formater.toCurrency(marketAnalyzer.getAvg1YSPSqft()));

    text1MStd.setText(Formater.toCurrency(marketAnalyzer.getStd1MSPSqft()));
    text6MStd.setText(Formater.toCurrency(marketAnalyzer.getStd6MSPSqft()));
    text1YStd.setText(Formater.toCurrency(marketAnalyzer.getStd1YSPSqft()));

    text1MCounter.setText(new Integer(marketAnalyzer.getCounter1M()).toString());
    text6MCounter.setText(new Integer(marketAnalyzer.getCounter6M()).toString());
    text1YCounter.setText(new Integer(marketAnalyzer.getCounter1Y()).toString());

    // Calculate Price-Index regression
    reg1M = marketAnalyzer.getReg1MSPSqft();
    reg6M = marketAnalyzer.getReg6MSPSqft();
    reg1Y = marketAnalyzer.getReg1YSPSqft();

    text1MRegA.setText(Formater.toShortDouble(reg1M.getA(), 3));
    text1MRegB.setText(Formater.toShortDouble(reg1M.getB(), 3));
    text1MRegR.setText(Formater.toShortDouble(reg1M.getR2(), 3));

    textRegPrice1M.setText(Formater.toCurrency(reg1M.getY0()));

    text6MRegA.setText(Formater.toShortDouble(reg6M.getA(), 3));
    text6MRegB.setText(Formater.toShortDouble(reg6M.getB(), 3));
    text6MRegR.setText(Formater.toShortDouble(reg6M.getR2(), 3));

    textRegPrice6M.setText(Formater.toCurrency(reg6M.getY0()));
    System.out.println(reg6M.getR2());
    text1YRegA.setText(Formater.toShortDouble(reg1Y.getA(), 3));
    text1YRegB.setText(Formater.toShortDouble(reg1Y.getB(), 3));
    text1YRegR.setText(Formater.toShortDouble(reg1Y.getR2(), 3));
    System.out.println(reg1Y.getR2());
    textRegPrice1Y.setText(Formater.toCurrency(reg1Y.getY0()));

    text1MExtpoPrice.setText(Formater.toCurrency(marketAnalyzer.getExtpoResultPrice1M()));
    text6MExtpoPrice.setText(Formater.toCurrency(marketAnalyzer.getExtpoResultPrice6M()));
    text1YExtpoPrice.setText(Formater.toCurrency(marketAnalyzer.getExtpoResultPrice1Y()));

    ArrayList<String> finalEstText = new ArrayList<String>();
    finalEstText = getFinalEstimation();
    updateMiddlePanel(finalEstText);
  }