public UserSelect() { loginInfo = new Label(""); loginInfo.addStyleName("error-font"); loginInfo.addStyleName("margin15"); loginInfo.addStyleName("margin-top40"); loginInfo.setVisible(false); selected = null; loginField = new PasswordField(""); loginField.setWidth("200px"); loginField.addStyleName("margin15"); loginField.addStyleName("margin-bot40"); loginBut = new Button("login"); loginBut.addStyleName("margin15"); loginBut.addClickListener( e -> { if (loginField.getValue().equals(selected.getPassword())) { hidePass(); Globals.user = selected; Globals.root.changeScreen(Globals.user); } else { loginInfo.setVisible(true); loginInfo.setValue("Wrong password"); loginField.setValue(""); } }); loginBox = new HorizontalLayout(); loginBox.addStyleName("popup-box"); loginBox.addComponents(loginField, loginBut, loginInfo); loginBox.setComponentAlignment(loginField, Alignment.MIDDLE_LEFT); loginBox.setComponentAlignment(loginBut, Alignment.MIDDLE_CENTER); loginBox.setComponentAlignment(loginField, Alignment.MIDDLE_RIGHT); loginBox.setVisible(false); userIcon = new ThemeResource("icons/user.png"); users = Globals.control.usersData(); vbox = new VerticalLayout(); // vbox.setSizeUndefined(); vbox.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); Panel p = new Panel(); p.setSizeFull(); p.setContent(vbox); // vbox.addStyleName("border-l-r"); this.addComponent(p, "left: 25%; right: 25%; top: 15px"); this.addComponent(loginBox, "left: 25%; right: 25%; top: 40%"); this.addLayoutClickListener( e -> { if (!loginBox.isVisible()) return; System.out.println(e.getClickedComponent()); if (e.getClickedComponent() == null || e.getClickedComponent().equals(vbox)) hidePass(); }); }
private void buildWorkSpace() { mainLayout.addTab(workSpace, "Work Space"); workSpace.setSizeFull(); final TextField className = new TextField("Correlator Class Name"); final TextArea classCode = new TextArea("Correlator Code"); final TextField builderClassName = new TextField("Builder Class Name"); final TextArea builderClassCode = new TextArea("Builder Code"); final CheckBox withBuilder = new CheckBox("Correlator comes with builder?"); withBuilder.setImmediate(true); withBuilder.addListener( new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent event) { if (withBuilder.booleanValue()) { builderClassName.setVisible(true); builderClassCode.setVisible(true); } else { builderClassName.setVisible(false); builderClassCode.setVisible(false); } } }); final Button compile = new Button("Add Correlator"); compile.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { if (!withBuilder.booleanValue()) { CorrelatorFromCodeFactory.createCorrelator( (String) helper.getBean("classPath"), className.getValue().toString(), classCode.getValue().toString(), correlatorBuilderManager, feed, correlatorPool, null, null, null); } else { RuntimeJavaFileCompiler.compile( (String) helper.getBean("classPath"), className.getValue().toString(), classCode.getValue().toString()); CorrelatorBuilderFromCodeFactory.createCorrelatorBuilder( (String) helper.getBean("classPath"), builderClassName.getValue().toString(), builderClassCode.getValue().toString(), correlatorBuilderManager, feed, correlatorPool); } } }); workSpace.addComponent(className); workSpace.addComponent(classCode); workSpace.addComponent(withBuilder); workSpace.addComponent(builderClassName); workSpace.addComponent(builderClassCode); builderClassName.setVisible(false); builderClassCode.setVisible(false); workSpace.addComponent(compile); classCode.setWidth("100%"); classCode.setHeight("500px"); builderClassCode.setWidth("100%"); builderClassCode.setHeight("500px"); }
private void buildFeedControl() { mainLayout.addTab(feedControl, "Feed Management"); feedControl.setSizeFull(); HorizontalLayout h1 = new HorizontalLayout(); final TextField feedPath = new TextField("Feeds Folder:"); h1.addComponent(feedPath); final Button updateFeedPath = new Button("Update"); h1.addComponent(updateFeedPath); h1.setComponentAlignment(updateFeedPath, Alignment.BOTTOM_RIGHT); feedControl.addComponent(h1); updateFeedPath.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { feed.reset(); feedsPath = feedPath.getValue().toString(); feed.setFeedsPath(feedsPath); buildFeedSelect(); } }); HorizontalLayout h2 = new HorizontalLayout(); final Select pairSelect = buildPairSelect(); h2.addComponent(pairSelect); h2.addComponent(feedSelect); final Button addPairFeed = new Button("Add"); h2.addComponent(addPairFeed); h2.setComponentAlignment(addPairFeed, Alignment.BOTTOM_RIGHT); feedControl.addComponent(h2); addPairFeed.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { feed.addPairFeed((Pair) pairSelect.getValue(), feedSelect.getValue().toString()); } }); HorizontalLayout h3 = new HorizontalLayout(); final TextField maxPopulation = new TextField("Maximum Population:"); maxPopulation.setValue("200"); h3.addComponent(maxPopulation); final Button updateMaxPop = new Button("Update"); h3.addComponent(updateMaxPop); h3.setComponentAlignment(updateMaxPop, Alignment.BOTTOM_RIGHT); feedControl.addComponent(h3); updateMaxPop.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { correlatorPool.setMaxPopulation(Integer.parseInt(maxPopulation.getValue().toString())); } }); final Button startSim = new Button("Start Learning"); feedControl.addComponent(startSim); startSim.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { try { emulator.startEmulation(); // emulator.run(); } catch (Exception e) { e.printStackTrace(); } } }); final Button endSim = new Button("End Learning"); feedControl.addComponent(endSim); endSim.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { try { emulator.die(); // emulator.stop(); } catch (Exception e) { e.printStackTrace(); } } }); final Button pauseFeed = new Button("Pause Feed"); feedControl.addComponent(pauseFeed); pauseFeed.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { feed.pause(); } }); final Button resumeFeed = new Button("Resume Feed"); feedControl.addComponent(resumeFeed); resumeFeed.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { feed.resume(); } }); final Button testInit = new Button("Use Test Init"); feedControl.addComponent(testInit); testInit.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { feed.reset(); feedsPath = "C:\\Users\\Oblene\\Desktop\\Sandbox\\Data"; // feedsPath = "/app/testing/hans/WebApps/Data"; feed.setFeedsPath(feedsPath); buildFeedSelect(); feed.addPairFeed(Pair.EURUSD, "EURUSD_5 Mins_Bid_2008.01.01_2012.12.31.csv"); feed.addPairFeed(Pair.GBPUSD, "GBPUSD_5 Mins_Bid_2008.01.01_2012.12.31.csv"); feed.addPairFeed(Pair.USDCHF, "USDCHF_5 Mins_Bid_2008.01.01_2012.12.31.csv"); // feed.addPairFeed(Pair.USDJPY, "USDJPY_5 Mins_Bid_2008.01.01_2012.12.31.csv"); feed.addPairFeed(Pair.AUDUSD, "AUDUSD_5 Mins_Bid_2008.01.01_2012.12.31.csv"); feed.addPairFeed(Pair.NZDUSD, "NZDUSD_5 Mins_Bid_2008.01.01_2012.12.31.csv"); feed.addCalendarFeed("Calendar_2008.csv"); CorrelatorFromCodeFactory.createCorrelator( (String) helper.getBean("classPath"), "MovingAverageCorrelator", "import com.bluesmoke.farm.correlator.CorrelatorPool;\n" + "import com.bluesmoke.farm.correlator.GenericCorrelator;\n" + "import com.bluesmoke.farm.correlator.builder.CorrelatorBuilderManager;\n" + "import com.bluesmoke.farm.model.tickdata.Tick;\n" + "import com.bluesmoke.farm.service.feed.FeedService;\n" + "import com.bluesmoke.farm.enumeration.PairResolution;\n" + "import com.bluesmoke.farm.enumeration.Pair;\n" + "\n" + "import java.util.HashMap;\n" + "import java.util.TreeMap;\n" + "import java.util.Random;\n" + "\n" + "public class MovingAverageCorrelator extends GenericCorrelator{\n" + "\n" + " private int refresh = 0;\n" + " private double ma;\n" + " private double sum = 0;\n" + " private Pair statePair;" + " private double statePairResolution;" + "\n" + " public MovingAverageCorrelator(String id, CorrelatorBuilderManager correlatorBuilderManager, CorrelatorPool pool, FeedService feed, GenericCorrelator aggressiveParent, GenericCorrelator passiveParent, HashMap<String, Object> config)\n" + " {\n" + " super(\"MovingAverage_\" + pool.getNextID(), correlatorBuilderManager, pool, feed, aggressiveParent, passiveParent, config);\n" + " Random rand = new Random();\n" + " this.config.put(\"price_type\", rand.nextInt(4));\n" + " TreeMap<Double, Pair> randMap = new TreeMap<Double, Pair>();\n" + " for(Pair pair : Pair.values())\n" + " {\n" + " randMap.put(Math.random(), pair);\n" + " }\n" + "\n" + " statePair = randMap.firstEntry().getValue();" + " this.config.put(\"statePair\", statePair);\n" + " statePairResolution = PairResolution.getResolution(statePair);\n" + " this.config.put(\"statePairResolution\", statePairResolution);" + " }\n" + "\n" + "\n" + " @Override\n" + " public void createMutant() {\n" + " new MovingAverageCorrelator(\"MovingAverage_\" + pool.getNextID(), correlatorBuilderManager, pool, feed, null, null, config);\n" + " }\n" + "\n" + " @Override\n" + " public String createState() {\n" + "\n" + " if(refresh == 0)\n" + " {\n" + " refresh = 1000;\n" + " sum = 0;\n" + " boolean passedFirst = false;\n" + " for(Tick tick : ticks)\n" + " {\n" + " double price = 0;\n" + " switch ((Integer)config.get(\"price_type\"))\n" + " {\n" + " case 0:\n" + " price = tick.getPairData(statePair.name()).getOpen();\n" + " break;\n" + " case 1:\n" + " price = tick.getPairData(statePair.name()).getClose();\n" + " break;\n" + " case 2:\n" + " price = tick.getPairData(statePair.name()).getHigh();\n" + " break;\n" + " case 3:\n" + " price = tick.getPairData(statePair.name()).getLow();\n" + " break;\n" + " }" + " if(passedFirst)\n" + " {\n" + " sum += price;\n" + " }\n" + " else {\n" + " passedFirst = true;\n" + " }\n" + " }\n" + " ma = sum/(ticks.size() - 1);\n" + " }\n" + " else {\n" + " double priceRemove = 0;" + " double priceAdd = 0;" + " switch ((Integer)config.get(\"price_type\"))\n" + " {\n" + " case 0:\n" + " priceRemove = ticks.get(0).getPairData(statePair.name()).getOpen();\n" + " priceAdd = currentTick.getPairData(statePair.name()).getOpen();\n" + " break;\n" + " case 1:\n" + " priceRemove = ticks.get(0).getPairData(statePair.name()).getClose();\n" + " priceAdd = currentTick.getPairData(statePair.name()).getClose();\n" + " break;\n" + " case 2:\n" + " priceRemove = ticks.get(0).getPairData(statePair.name()).getHigh();\n" + " priceAdd = currentTick.getPairData(statePair.name()).getHigh();\n" + " break;\n" + " case 3:\n" + " priceRemove = ticks.get(0).getPairData(statePair.name()).getLow();\n" + " priceAdd = currentTick.getPairData(statePair.name()).getLow();\n" + " break;\n" + " }" + " sum -= priceRemove;\n" + " sum += priceAdd;\n" + " ma = sum/(ticks.size() - 1);\n" + " }\n" + " currentUnderlyingComponents.put(\"MA\", ma);\n" + " refresh--;\n" + " return \"\" + (int)(ma/(100 * statePairResolution));\n" + " }\n" + "}\n", correlatorBuilderManager, feed, correlatorPool, null, null, null); CorrelatorFromCodeFactory.createCorrelator( (String) helper.getBean("classPath"), "PriceCorrelator", "import com.bluesmoke.farm.correlator.CorrelatorPool;\n" + "import com.bluesmoke.farm.correlator.GenericCorrelator;\n" + "import com.bluesmoke.farm.correlator.builder.CorrelatorBuilderManager;\n" + "import com.bluesmoke.farm.model.tickdata.Tick;\n" + "import com.bluesmoke.farm.service.feed.FeedService;\n" + "import com.bluesmoke.farm.enumeration.PairResolution;\n" + "import com.bluesmoke.farm.enumeration.Pair;\n" + "\n" + "import java.util.HashMap;\n" + "import java.util.TreeMap;\n" + "import java.util.Random;\n" + "\n" + "public class PriceCorrelator extends GenericCorrelator{\n" + "\n" + " private Pair statePair;" + " private double statePairResolution;" + " public PriceCorrelator(String id, CorrelatorBuilderManager correlatorBuilderManager, CorrelatorPool pool, FeedService feed, GenericCorrelator aggressiveParent, GenericCorrelator passiveParent, HashMap<String, Object> config)\n" + " {\n" + " super(\"Price_\" + pool.getNextID(), correlatorBuilderManager, pool, feed, aggressiveParent, passiveParent, config);\n" + " Random rand = new Random();\n" + " this.config.put(\"price_type\", rand.nextInt(4));\n" + " " + " TreeMap<Double, Pair> randMap = new TreeMap<Double, Pair>();\n" + " for(Pair pair : Pair.values())\n" + " {\n" + " randMap.put(Math.random(), pair);\n" + " }\n" + "\n" + " statePair = randMap.firstEntry().getValue();" + " this.config.put(\"statePair\", statePair);\n" + " statePairResolution = PairResolution.getResolution(statePair);\n" + " this.config.put(\"statePairResolution\", statePairResolution);" + " }\n" + "\n" + "\n" + " @Override\n" + " public void createMutant() {\n" + " new PriceCorrelator(\"Price_\" + pool.getNextID(), correlatorBuilderManager, pool, feed, null, null, config);\n" + " }\n" + "\n" + " @Override\n" + " public String createState() {\n" + "\n" + " double price = 0;\n" + " switch ((Integer)config.get(\"price_type\"))\n" + " {\n" + " case 0:\n" + " price = currentTick.getPairData(statePair.name()).getOpen();\n" + " break;\n" + " case 1:\n" + " price = currentTick.getPairData(statePair.name()).getClose();\n" + " break;\n" + " case 2:\n" + " price = currentTick.getPairData(statePair.name()).getHigh();\n" + " break;\n" + " case 3:\n" + " price = currentTick.getPairData(statePair.name()).getLow();\n" + " break;\n" + " }\n" + " currentUnderlyingComponents.put(\"price\", price);\n" + " return \"\" + (int)(price/(10 * statePairResolution));\n" + " }\n" + "}\n", correlatorBuilderManager, feed, correlatorPool, null, null, null); } }); final Button checkPool = new Button("Check Pool"); feedControl.addComponent(checkPool); checkPool.addListener( new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { System.out.println(correlatorPool.getHandlesInfo()); } }); }