@Override public void eventFired(PersistentEntity event) { if (event instanceof PNLChangeEvent) { process((PNLChangeEvent) event); } } });
/** * @param args * @throws TemplateException * @throws IOException */ public static void main(String[] args) throws IOException, TemplateException { new FreemarkerWrapper("/home/ustaudinger/work/activequant/trunk/src/test/resources/transactions/", "./src/main/resources/templates/perfreport.tpl"); }
/** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws Exception { /* new TransactionInputToReport( "/home/ustaudinger/work/activequant/trunk/src/test/resources/transactions/transactions.csv", "/home/ustaudinger/work/activequant/trunk/src/test/resources/transactions/report.config", "/home/ustaudinger/work/activequant/trunk/src/test/resources/transactions/", "reporting.pecoracapital.com"); */ new TransactionInputToReport(args[0], args[1], args[2], args[3]); // // // SimpleDateFormat newYorkTimeFormatter = new SimpleDateFormat("HH"); // newYorkTimeFormatter.setTimeZone(TimeZone.getTimeZone("America/New_York")); // // // // SimpleDateFormat localTimeFormatter = new SimpleDateFormat("HH"); // // System.out.println(newYorkTimeFormatter.format(new Date()) + " -- " + // localTimeFormatter.format(new Date())); }
TransactionFileStreamIterator tfsi = new TransactionFileStreamIterator(transactionsFile); streamIters.add(tfsi); CSVFileFillExporter fillExporter = new CSVFileFillExporter(); PNLMonitor pnlMonitor = new PNLMonitor(transFac, timeFrame); PNLChangeEvent pce = prc.execution(ofe.getTimeStamp(), ofe.getOptionalInstId(), ofe.getFillPrice(), ofe.getSide().getSide() * ofe.getFillAmount()); increaseTransactionCount(ofe.getOptionalInstId()); } else if (se instanceof OHLCV) { OHLCV o = (OHLCV) se; TSContainer2 tsc = pnlMonitor.getCumulatedTSContainer(); fillExporter.export(targetFolder, oel.getFillEvents()); TSContainer2 pnlContainer = pnlMonitor.getCumulatedTSContainer(); FileOutputStream fout; ChartUtilities.saveChartAsPNG(new File(targetFolder + File.separator + "pnl.png"), pnlMonitor.getStaticChart(), 800, 600); TSContainer2 deltaCashPositionsOverTime = calcCashPositions(posDeltaOverTime, executionPricesOverTime); TSContainer2 inflatedCashPositionSeries = resampleSeries(deltaCashPositionsOverTime, TimeFrame.HOURS_1, startTimeStamp, endTimeStamp); TSContainer2 borrowingAndLendingContainer = calcInterestChanges(startTimeStamp, endTimeStamp,
TSContainerMethods tcm = new TSContainerMethods(); new File(targetFolder).mkdirs(); fillExporter.export(targetFolder, oelistener.getFillEvents()); TSContainer2 pnlContainer = pnlMonitor.getCumulatedTSContainer(); tcm.overwriteNull(pnlContainer); tcm.overwriteNull(pnlContainer, 0.0); pnlMonitor.getStaticChart(), 800, 600); BacktestStatistics bs = new BacktestStatistics(); bs.setReportId(new SimpleDateFormat("yyyyMMdd").format(new Date())); bs.calcPNLStats(pnlContainer); bs.calcPosStats(oelistener.getPositionOverTime()); bs.populateOrderStats(oelistener); new CsvMapWriter().write(bs.getStatistics(), fout); fout.close(); } catch (Exception e) { generate(algoConfigs, btConfig, bs); } catch (IOException ex) { log.warn("Error", ex);
public SimulationReport generateReport(String targetFolder) throws IOException { SimulationReport sr = new SimulationReport(); TSContainerMethods tcm = new TSContainerMethods(); TSContainer2 pnlContainer = pnlMonitor.getCumulatedTSContainer(); tcm.overwriteNull(pnlContainer); tcm.overwriteNull(pnlContainer, 0.0); sr.setPnlSeries(pnlContainer); // HTMLReportGen h = new HTMLReportGen(targetFolder, templateFolder); if(oelistener.getFillEvents().size()>0){ h.genReport(algoConfigs, oelistener, pnlMonitor, btConfig); } else{ log.warn("No trades were generated!"); System.out.println("No trades were generated."); } // fill the sr return sr; }
public void testMonitor() throws FileNotFoundException, Exception { // PNLMonitor monitor = new PNLMonitor(null); // monitor.process(ce(10L, "A", 0.0)); monitor.process(ce(20L, "A", 1.0)); monitor.process(ce(30L, "A", 0.0)); monitor.process(ce(40L, "A", 2.0)); monitor.process(ce(50L, "A", -0.2)); // assertEquals(2, monitor.getTsContainer().getNumColumns()); assertEquals(5, monitor.getTsContainer().getNumRows()); // DoubleColumn dc = (DoubleColumn)monitor.getTsContainer().getColumn("A"); assertNotNull(dc); DoubleColumn cumulatedPnl = dc.cumsum(); assertEquals(2.8, cumulatedPnl.get(4)); // }
public void generateReport(String localTargetFolder, String localTemplateFolder) throws IOException { HTMLReportGen h = new HTMLReportGen(localTargetFolder, localTemplateFolder); if(oelistener.getFillEvents().size()>0){ h.genReport(algoConfigs, oelistener, pnlMonitor, btConfig); } else{ log.warn("No trades were generated!"); System.out.println("No trades were generated."); } }
private TSContainer2 calcInterestChanges(TimeStamp startTimeStamp, TimeStamp endTimeStamp, TimeFrame reportResolution, TSContainer2 cashPositionsOverTime) throws IOException { ChargedInterestRates chargedIr = new ChargedInterestRates(); EarnedInterestRates earnedIr = new EarnedInterestRates(); if (val != null) { if (val < 0.0) { Double charge = chargedIr.getOvernightChange(cncy, val); tsc.setValue(cncy, ts, charge); } else if (val > 0.0) { Double earnings = earnedIr.getOvernightChange(cncy, val); tsc.setValue(cncy, ts, earnings);
templateString = templateString.replace("{REPORTID}", bt.getReportId()); if (bc != null) { templateString = templateString.replace("{MDIS}", ArrayUtils.toString(bc.getMdis())); for (String instrument : bt.getInstrumentIDs()) { log.info("Replacing for " + instrument); String t = new String(instrumentTemplate); t = t.replace("{INSTRUMENTID}", instrument); t = t.replace("{MAXPNL}", "" + bt.getStatistics().get(instrument + ".MAXPNL")); t = t.replace("{TOTALPLACED}", "" + bt.getStatistics().get(instrument + ".TOTALPLACED")); t = t.replace("{TOTALFILLS}", "" + bt.getStatistics().get(instrument + ".TOTALFILLS")); t = t.replace("{TOTALORDERUPDS}", "" + bt.getStatistics().get(instrument + ".TOTALORDERUPDS")); t = t.replace("{TOTALORDERCNCL}", "" + bt.getStatistics().get(instrument + ".TOTALORDERCNCL")); t = t.replace("{FINALPNL}", "" + bt.getStatistics().get(instrument + ".FINALPNL")); t = t.replace("{PNLPERTRADE}", "" + bt.getStatistics().get(instrument + ".PNLPERTRADE"));
pnlMonitor = new PNLMonitor(transportFactory); jframe.toFront(); pnlMonitor.showLiveChart();
/** * @param args */ // public static void main(String[] args) throws Exception { // new ExtTrsctFileReporting(null).run(args[0], args[1]); // } public static void main(String[] args) { // Add the values in the datamodel Map datamodel = new HashMap(); datamodel.put("pet", "Bunny"); datamodel.put("number", new Integer(6)); // Process the template using FreeMarker try { freemarkerDo(datamodel, "./src/main/resources/templates/perfreport.tpl"); } catch(Exception e) { System.out.println(e.getLocalizedMessage()); } }
private TSContainer2 resampleSeries(TSContainer2 container, TimeFrame timeFrame, TimeStamp startTimeStamp, TimeStamp endTimeStamp) { // resample the position series. TSContainer2 resampled = getEmptyContainer(container.getColumnHeaders(), startTimeStamp, endTimeStamp, timeFrame); List<String> headers = container.getColumnHeaders(); for (int i = 0; i < container.getTimeStamps().size(); i++) { TimeStamp ts = container.getTimeStamps().get(i); Object[] o = container.getRow(ts); for (int j = 0; j < o.length; j++) { if (o[j] != null) { resampled.setValue(headers.get(j), ts, (Double) o[j]); } } } return resampled; }
addColAndInit(cashPositionsOverTime, base, timeStamps); addColAndInit(cashPositionsOverTime, quotee, timeStamps);
public void run(String reportId, String folder) throws DaoException, FileNotFoundException, IOException{ Report r = reportDao.load(reportId); r.setStatus("PROCESSING"); reportDao.update(r); try{ new TransactionInputToReport( folder + "/transactions.csv", folder + "/report.config", folder, "localhost"); // r.setStatus("DONE"); reportDao.update(r); } catch(Exception ex){ r.setStatus("ERROR: " + ex); reportDao.update(r); } }