List of usage examples for org.jfree.data.time TimeSeries getNextTimePeriod
public RegularTimePeriod getNextTimePeriod()
From source file:com.jaxzin.iraf.demo.GSDemo.java
private static XYDataset createData() { TimeSeriesCollection tsc = new TimeSeriesCollection(); GrowthSimulator sim = new StandardGrowthSimulator(); sim.setDomain(new GSDomainImpl()); // Locate the simulation start point sim.getDomain().setInitialInvestment(Quantity.<Money>valueOf("45000 USD")); // Setup the data about me sim.getDomain().setInitialAge(28);/*from www .j a v a 2s . c om*/ sim.getDomain().setRetirementAge(60); sim.getDomain().setLifespan(90); // Setup the data about my job sim.getDomain().setInitialSalary(Quantity.<Money>valueOf("95000 USD")); sim.getDomain().setBonus(Quantity.<Dimensionless>valueOf("14 %")); sim.getDomain().setRaise(Quantity.<Dimensionless>valueOf("5.5 %")); sim.getDomain().setPaychecksPerYear(1); // Setup the data about contributions to IRA sim.getDomain().setContribution(Quantity.<Dimensionless>valueOf("4 %")); sim.getDomain().setEmployerMatch(Quantity.<Dimensionless>valueOf("75 %")); // Setup data about the market sim.getDomain().setRor1(Quantity.<Dimensionless>valueOf("10 %")); sim.getDomain().setRor2(Quantity.<Dimensionless>valueOf("5 %")); sim.getDomain().setRiskFreeRate(Quantity.<Dimensionless>valueOf("3 %")); sim.getDomain().setAdjustForInflation(false); // Setup data about retirement sim.getDomain().setRetirementFactor(Quantity.<Dimensionless>valueOf("25 %")); java.util.List<Money> moneys = null; try { moneys = sim.simulate(); } catch (SimulationException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } TimeSeries ts = new TimeSeries("", Year.class); for (Money money : moneys) { if (ts.getItemCount() == 0) { ts.add(RegularTimePeriod.createInstance(Year.class, DateUtilities.createDate(2006, 1, 1), TimeZone.getDefault()), money.doubleValue()); } else { ts.add(ts.getNextTimePeriod(), money.doubleValue()); } } tsc.addSeries(ts); return tsc; }
From source file:com.jaxzin.iraf.forecast.swing.JForecaster.java
@SuppressWarnings({ "MethodWithMultipleLoops" }) protected XYDataset createDataset() { final TimeSeriesCollection tsc = new TimeSeriesCollection(); // long start = System.currentTimeMillis(); Forecast forecastData = null;/* w w w.ja va 2 s . c om*/ try { // System.out.println("Generating dataset; initial salary is <"+domain.getInitialSalary()+">"); forecastData = forecaster.forecast(domain); } catch (ForecastException e) { e.printStackTrace(); } int count = 1; assert forecastData != null; final int total = forecastData.getForecastData().size() + 1; //noinspection ForLoopThatDoesntUseLoopVariable for (Iterator i = forecastData.getForecastData().iterator(); i.hasNext(); count++) { final List<Money> universeData = (List<Money>) i.next(); //noinspection ObjectAllocationInLoop,UnqualifiedStaticUsage final TimeSeries ts = new TimeSeries(new StringBuilder() .append(String.valueOf((count * TOTAL_PERCENTILES) / total)).append("th").toString(), Year.class); for (Money money : universeData) { if (ts.getItemCount() == 0) { //noinspection ObjectAllocationInLoop ts.add(RegularTimePeriod.createInstance(Year.class, new Date(), TimeZone.getDefault()), money.doubleValue()); } else { ts.add(ts.getNextTimePeriod(), money.doubleValue()); } } tsc.addSeries(ts); } // System.out.println(System.currentTimeMillis()-start); return tsc; }