Example #1
0
  public boolean startBacktest() {

    // backtest結果ファイルのpathをセット
    setFilePath();

    // set parameter
    btResult = new BacktestResultFx();
    btParam = new BacktestParamFx();
    btParamCoe = new BacktestParamFxCoe();
    setBacktestParam5();
    setSpread();
    initializeEntryControl();
    initializePosition();
    initializeResult();
    initilalizeMaxProfitLoss();
    log.info("setting parameter is done.");

    // predict結果ファイルをserverから作業ディレクトリにダウンロード
    if (!downloadPredictResulFile()) return false;

    // buffered reader にファイルをセット
    loadFile();

    // backtestの出力ファイルのヘッダを作成
    createHeader2();

    // datetimeごとの処理を開始
    // datetimeごとの処理を開始
    if (!entry()) return false;
    try {
      calcEvaluation();
    } catch (Exception e) {
      e.printStackTrace();
    }
    closeBufferedReader();

    // 結果ファイルをup
    if (ControlProgram.getLocation().equals(ControlProgram.Location.local)) {
      if (!upFile(testResultLocalPath, testResultServerPath)) return false;
    }
    if (ControlProgram.getLocation().equals(ControlProgram.Location.global)) {
      upFileFtp(testResultLocalPath, testResultFtpPath);
    }

    // resultテーブル更新
    updateResult();

    return true;
  }
Example #2
0
  private boolean entry() {
    int progressCount = 1;
    boolean isLastDatetime = false;
    while (isLastDatetime == false) {

      // datetimeファイルとpredict結果ファイルを読み込み
      // datetimeの書式 ex.2013-01-01 00:06:00.0
      readNextDatetimeClassification5();

      // 初回時はfilterDatetimeの初期化する
      if (progressCount == 1) {
        filterDatetime = btParam.getNowDatetime();
      }

      log.debug("--------------------------------"); // 区切り表示
      log.debug("{} の計算を開始します。", btParam.getNowDatetime());

      // 進捗表示
      progressCount =
          ControlProgram.displayProgress(
              progressCount, 3000, backtest.getId(), btParam.getNowDatetime());

      // datetime&predict結果ファイルが最終行ならbreak
      if (btParam.getNowDatetime() == null & btParam.getAllProbs().length == 0) {
        log.info("work_id:{}  テスト期間の最終datetimeです", work.getId());
        isLastDatetime = true;
        continue;
      } else if ((btParam.getNowDatetime() == null & btParam.getAllProbs().length != 1)
          | (btParam.getNowDatetime() != null & btParam.getAllProbs().length == 0)) {
        log.error("work_id:{} ERROR!!! datetimeとpredict結果ファイルの行数が一致しません。", work.getId());
        return false;
      }

      // datetime filter
      if (isInDatetimeFilter()) continue;

      // 週末
      if (isWeekend()) continue;

      // 現在価格を取得
      btParam.setNowPrice(getCurrentPrice(btParam.getNowDatetime()));

      // 期待値を算出
      calcMlValueType2();

      // debugファイル記載
      if (ModeConstants.IS_OUTPUT_DEBUG)
        outputDebugFile5mean(btParam.getNowDatetime(), btParam.getAllProbs(), mlValue);

      // filter
      setFilterValue();

      // entry
      openPosition();
      closePosition();
    } // while end

    log.info("work_id:{} 最終datetimeまでbacktestが完了しました。", work.getId());
    return true;
  }