public void run() { // 初始化历史交易数据 StockInstance si = new StockInstance(stockCode); si.initializeData(); System.out.println("股票" + si.getStockCode() + "历史交易数据初始化完成"); // 生成回归分析文件和结果 if (GlobalVar.doAnalyze.equals("on")) { LRGenerator lrg = new LRGenerator(si); lrg.executeLRegression(); } }
private void generateFile() throws Exception { // 准备文件写入 File stockFolder = new File(GlobalVar.csvDirectory + "/" + si.getStockCode()); if (!stockFolder.exists()) { stockFolder.mkdirs(); } String generatedFilePath = GlobalVar.csvDirectory + "/" + si.getStockCode() + "/" + type + "-" + simDays + ".csv"; File csvFile = new File(generatedFilePath); // 清理旧文件,生成新文件 if (!csvFile.exists()) { csvFile.createNewFile(); } else { csvFile.delete(); csvFile.createNewFile(); } PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(generatedFilePath))); // 写入表头 StringBuffer titleBuffer = new StringBuffer(); titleBuffer.append("Result").append(","); for (int i = 0; i < 8; i++) { // 个股数据 titleBuffer.append("B-Lag").append(i + 1).append(","); titleBuffer.append("H-Lag").append(i + 1).append(","); titleBuffer.append("L-Lag").append(i + 1).append(","); titleBuffer.append("E-Lag").append(i + 1).append(","); // 大盘数据 // titleBuffer.append("DB-Lag").append(i + 1).append(","); // titleBuffer.append("DH-Lag").append(i + 1).append(","); // titleBuffer.append("DL-Lag").append(i + 1).append(","); // titleBuffer.append("DE-Lag").append(i + 1).append(","); if (i < 7) { titleBuffer.append("Q-Lag").append(i + 1).append(","); } else { titleBuffer.append("Q-Lag").append(i + 1); } } pw.println(titleBuffer.toString()); // 写入数据 for (int j = 8; j < si.getHistoryDataList().size() - simDays; j++) { StringBuffer lineBuffer = new StringBuffer(); if (type.equals("BEGIN")) { lineBuffer.append(si.getHistoryDataList().get(j).get("BEGIN")).append(","); } else if (type.equals("HIGH")) { lineBuffer.append(si.getHistoryDataList().get(j).get("HIGH")).append(","); } else if (type.equals("LOW")) { lineBuffer.append(si.getHistoryDataList().get(j).get("LOW")).append(","); } else if (type.equals("END")) { lineBuffer.append(si.getHistoryDataList().get(j).get("END")).append(","); } for (int k = 1; k < 9; k++) { lineBuffer.append(si.getHistoryDataList().get(j - k).get("BEGIN")).append(","); lineBuffer.append(si.getHistoryDataList().get(j - k).get("HIGH")).append(","); lineBuffer.append(si.getHistoryDataList().get(j - k).get("LOW")).append(","); lineBuffer.append(si.getHistoryDataList().get(j - k).get("END")).append(","); // lineBuffer.append(stockList.get(j - k).getBeginDapan()).append(","); // lineBuffer.append(stockList.get(j - k).getHighestDapan()).append(","); // lineBuffer.append(stockList.get(j - k).getLowestDapan()).append(","); // lineBuffer.append(stockList.get(j - k).getEndDapan()).append(","); if (k < 8) { lineBuffer .append( Math.log(GlobalVar.str2int((si.getHistoryDataList().get(j - k).get("QUANTITY"))))) .append(","); } else { lineBuffer.append( Math.log(GlobalVar.str2int((si.getHistoryDataList().get(j - k).get("QUANTITY"))))); } } pw.println(lineBuffer.toString()); } // 结束 pw.close(); }