/** * tells the market that the model is starting up, and it would be a good idea to start the data * collector. It also schedules a final cleanup step to update gui if needed * * @param model */ public void start(MacroII model) { marketData.start(model, this); if (priceSeries != null) { Steppable guiUpdater = new Steppable() { @Override public void step(SimState simState) { if (!marketData.isActive()) return; final Double newPrice = marketData.getLatestObservation(MarketDataType.CLOSING_PRICE); final Double newVolume = marketData.getLatestObservation(MarketDataType.VOLUME_TRADED); final Double day = new Double(marketData.getLastObservedDay()); // if(newPrice >=0 Platform.runLater( new Runnable() { @Override public void run() { System.out.println( newPrice + "--- " + day + ", " + priceSeries.getData().size()); priceSeries.getData().add(new XYChart.Data<Number, Number>(day, newPrice)); volumeSeries.getData().add(new XYChart.Data<Number, Number>(day, newVolume)); } }); model.scheduleTomorrow(ActionOrder.CLEANUP_DATA_GATHERING, this, Priority.FINAL); panel.repaint(); } }; model.scheduleSoon(ActionOrder.CLEANUP_DATA_GATHERING, guiUpdater, Priority.FINAL); } }
public int getLastObservedDay() { return marketData.getLastObservedDay() - 1; }
/** * a method to check if, given the acceptor, the latest observation is valid * * @param acceptor * @return */ public boolean isLastDayAcceptable(MarketData.MarketDataAcceptor acceptor) { return marketData.isLastDayAcceptable(acceptor); }
/** return the latest price observed */ public Double getLatestObservation(MarketDataType type) { return marketData.getLatestObservation(type); }
/** utility method to analyze only a specific day */ public double getObservationRecordedThisDay(MarketDataType type, int day) { return marketData.getObservationRecordedThisDay(type, day); }
/** utility method to analyze only specific days */ public double[] getObservationsRecordedTheseDays( MarketDataType type, int beginningDay, int lastDay) { return marketData.getObservationsRecordedTheseDays(type, beginningDay, lastDay); }
/** utility method to analyze only specific days */ public double[] getObservationsRecordedTheseDays(MarketDataType type, int[] days) { return marketData.getObservationsRecordedTheseDays(type, days); }
/** returns a copy of all the observed last prices so far! */ public double[] getAllRecordedObservations(MarketDataType type) { return marketData.getAllRecordedObservations(type); }
/** check which days have observations that are okay with the acceptor! */ public int[] getAcceptableDays(int[] days, MarketData.MarketDataAcceptor acceptor) { return marketData.getAcceptableDays(days, acceptor); }
/** how many days worth of observations are here? */ public int getNumberOfObservations() { if (marketData == null) return 0; return marketData.numberOfObservations(); }
public void turnOff() { // the game is over, tell the rest of the crew marketData.turnOff(); }