@Override public GridProductRecord deserialize(JsonParser jp, DeserializationContext context) throws IOException, JsonProcessingException { GridProductRecord gridProductRecord = new GridProductRecord(); while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); switch (fieldname) { case "id": jp.nextToken(); gridProductRecord.setId(Integer.parseInt(jp.getText())); break; case "pid": jp.nextToken(); gridProductRecord.setParentId(Integer.parseInt(jp.getText())); break; case "name": jp.nextToken(); gridProductRecord.setName(jp.getText()); break; case "activated": jp.nextToken(); gridProductRecord.setActivated(Formater.deserializeDate(jp.getText())); break; } } return gridProductRecord; }
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; }
private void createRightPanel() { npvAnalyzer = new NpvAnalyzer(); Double d; Label lblHistoFinInfo = new Label(shell, SWT.NONE); lblHistoFinInfo.setBounds(848, 10, 198, 14); lblHistoFinInfo.setText("Historical Financial Information"); Label lblIRR = new Label(shell, SWT.NONE); lblIRR.setBounds(861, 70, 90, 14); lblIRR.setText("IRR"); Label lblRentalIncomeIncrease = new Label(shell, SWT.NONE); lblRentalIncomeIncrease.setBounds(861, 134, 198, 14); lblRentalIncomeIncrease.setText("Rental Income Increase / Year"); Label lblChangeInValue = new Label(shell, SWT.NONE); lblChangeInValue.setBounds(861, 194, 198, 14); lblChangeInValue.setText("Change In Value over the period"); Label lblHorizonPeriod = new Label(shell, SWT.NONE); lblHorizonPeriod.setBounds(861, 224, 183, 14); lblHorizonPeriod.setText("Horizion Period"); Label lblMaintenanceCosts = new Label(shell, SWT.NONE); lblMaintenanceCosts.setBounds(861, 254, 183, 14); lblMaintenanceCosts.setText("Maintenance Costs"); Label lblInflationRate = new Label(shell, SWT.NONE); lblInflationRate.setBounds(861, 164, 183, 14); lblInflationRate.setText("Inflation rate"); textIRR = new Text(shell, SWT.BORDER); textIRR.setBounds(1065, 70, 64, 19); d = npvAnalyzer.getIrr() * 100; textIRR.setText(Formater.toShortDouble(d, 2)); textRentalIncomeIncrease = new Text(shell, SWT.BORDER); textRentalIncomeIncrease.setBounds(1065, 134, 64, 19); d = npvAnalyzer.getRentalIncomeIncrementInPercentage() * 100; textRentalIncomeIncrease.setText(Formater.toShortDouble(d, 2)); textInflationRate = new Text(shell, SWT.BORDER); textInflationRate.setBounds(1065, 164, 64, 19); d = npvAnalyzer.getInflationRate() * 100; textInflationRate.setText(Formater.toShortDouble(d, 2)); textChangeInValue = new Text(shell, SWT.BORDER); textChangeInValue.setBounds(1065, 194, 64, 19); d = npvAnalyzer.getChangeInValue() * 100; textChangeInValue.setText(Formater.toShortDouble(d, 2)); textHorizon = new Text(shell, SWT.BORDER); textHorizon.setBounds(1065, 224, 64, 19); d = npvAnalyzer.getHorizon(); textHorizon.setText(Formater.toShortDouble(d)); textMaintenanceCosts = new Text(shell, SWT.BORDER); textMaintenanceCosts.setBounds(1065, 254, 64, 19); d = npvAnalyzer.getMaintenaceCostInPercentage() * 100; textMaintenanceCosts.setText(Formater.toShortDouble(d, 2)); Label lblAccountNo = new Label(shell, SWT.NONE); lblAccountNo.setBounds(861, 40, 138, 14); lblAccountNo.setText("Loan Account"); textAccountNo = new Text(shell, SWT.BORDER); textAccountNo.setBounds(1065, 40, 64, 19); Label lblNpv = new Label(shell, SWT.NONE); lblNpv.setBounds(861, 365, 59, 14); lblNpv.setText("NPV"); textNPV = new Text(shell, SWT.BORDER); textNPV.setEditable(false); textNPV.setBounds(1065, 365, 90, 19); Label lblNetIncome = new Label(shell, SWT.NONE); lblNetIncome.setBounds(861, 394, 138, 14); lblNetIncome.setText("Net Income"); textNetIncome = new Text(shell, SWT.BORDER); textNetIncome.setBounds(1065, 394, 90, 19); Label lblTransactionCosts = new Label(shell, SWT.NONE); lblTransactionCosts.setBounds(861, 284, 120, 14); lblTransactionCosts.setText("Transaction Costs"); textTransactionCosts = new Text(shell, SWT.BORDER); textTransactionCosts.setBounds(1065, 284, 64, 19); d = npvAnalyzer.getTransactionCostInPercentage() * 100; textTransactionCosts.setText(Formater.toShortDouble(d, 2)); Label lblRentalIncome = new Label(shell, SWT.NONE); lblRentalIncome.setBounds(861, 100, 183, 14); lblRentalIncome.setText("Rental Income"); textRentalIncomeInPercentage = new Text(shell, SWT.BORDER); textRentalIncomeInPercentage.setBounds(1065, 103, 64, 19); d = npvAnalyzer.getRentalIncomePercentage() * 100; textRentalIncomeInPercentage.setText(Formater.toShortDouble(d, 2)); Label label = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); label.setBounds(846, 345, 339, 2); Label[] labelPercentSym = new Label[7]; for (int i = 0; i < 7; i++) { int xCord = 1130; labelPercentSym[i] = new Label(shell, SWT.NONE); if (i != 1) { if (i >= 5) { labelPercentSym[i].setBounds(xCord, 72 + (i + 1) * 30, 15, 14); labelPercentSym[i].setText("%"); } else { labelPercentSym[i].setBounds(xCord, 72 + i * 30, 15, 14); labelPercentSym[i].setText("%"); } } else { labelPercentSym[i].setBounds(xCord, 72 + i * 30, 100, 14); labelPercentSym[i].setText("% of Value"); } } btnCalculate = new Button(shell, SWT.NONE); btnCalculate.addMouseListener( new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { try { // get the account number String accountNo = textAccountNo.getText(); npvAnalyzer.doQuery(accountNo); // get IRR String irrStr = textIRR.getText(); double irr = Double.valueOf(irrStr).doubleValue() / 100; npvAnalyzer.setIrr(irr); // get rental income String rentalIncomeStr = textRentalIncomeInPercentage.getText(); double rentalIncome = Double.valueOf(rentalIncomeStr).doubleValue() / 100; npvAnalyzer.setRentalIncomePercentage(rentalIncome); // get rental income increase String rentalIncomeIncreaseStr = textRentalIncomeIncrease.getText(); double rentalIncomeIncrease = Double.valueOf(rentalIncomeIncreaseStr).doubleValue() / 100; npvAnalyzer.setRentalIncomeIncrementInPercentage(rentalIncomeIncrease); // get inflation rate String inflationRateStr = textInflationRate.getText(); double inflationRate = Double.valueOf(inflationRateStr).doubleValue() / 100; npvAnalyzer.setInflationRate(inflationRate); // get the change in value String changeInValueStr = textChangeInValue.getText(); double changeInValue = Double.valueOf(changeInValueStr).doubleValue() / 100; npvAnalyzer.setChangeInValue(changeInValue); // get the horizon String horizonStr = textHorizon.getText(); double horizon = Double.valueOf(horizonStr).doubleValue(); npvAnalyzer.setHorizon(horizon); // get the maintenance costs String maintenanceCostsStr = textMaintenanceCosts.getText(); double maintenanceCosts = Double.valueOf(maintenanceCostsStr).doubleValue() / 100; npvAnalyzer.setMaintenaceCostInPercentage(maintenanceCosts); // get the transaction costs String transactionCostsStr = textTransactionCosts.getText(); double transactionCosts = Double.valueOf(transactionCostsStr).doubleValue() / 100; npvAnalyzer.setTransactionCostInPercentage(transactionCosts); npvAnalyzer.doCalculation(); // Set result textNPV.setText(Formater.toCurrency(npvAnalyzer.getNpv())); textNetIncome.setText(Formater.toCurrency(npvAnalyzer.getNetIncome())); } catch (Exception e1) { e1.printStackTrace(); } } }); btnCalculate.setBounds(960, 311, 94, 28); btnCalculate.setText("Calculate"); btnSensitivityAnalysis = new Button(shell, SWT.NONE); btnSensitivityAnalysis.addMouseListener( new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { SensitivityAnalyzer sa = new SensitivityAnalyzer(); sa.setNpvAnalyzer(npvAnalyzer); sa.open(); } }); btnSensitivityAnalysis.setBounds(952, 454, 177, 28); btnSensitivityAnalysis.setText("Sensitivity Analysis"); }
/** * @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); }