Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package lob; import java.awt.BorderLayout; import java.awt.Dimension; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.ListIterator; import java.util.Map; import java.util.Random; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import lob.Order.Side; import static lob.Order.Side.ASK; import static lob.Order.Side.BID; import static lob.Order.Type.LIMIT; import static lob.Order.Type.MARKET; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** * * @author kevinjohnston */ public class VisualisationGUI extends javax.swing.JFrame { //User input variables private float sp; //start price private float ts; //tick size private long ms; //market size private float ic; //initial capital private int mt; //max timesteps //User selected agent variables private int nmm; //num market makers; private int ntf; //num trend followers; private int nc; //num contrarians private int nlt; //num lay traders; private float smm; //split of capital to market makers private float stf; //split to trend followers private float sc; //split to contrarians private float slt; //split to lay traders //Determine whether to display the agent states. If there are more than 100 //agents, the states cannot be displayed due to jTable limitations! private boolean displayAgentStates; //Number of steps to advance at a time private int delay; //Broker class owned by GUI private Brokerage broker; //To plot to graph private int time; private float midPrice; final XYSeries series1; final XYSeries series2; private ArrayList<Float> midPriceHistory; private ArrayList<Long> volHistory; //For updates on agents private long averageTradeVolume; private long totalTraded; private HashMap<Integer, Float> agentBestValue; /** * Creates new form VisualisationGUI */ public VisualisationGUI() { initComponents(); this.delay = 50; this.totalTraded = 0; this.agentBestValue = new HashMap<>(); series1 = new XYSeries("MidPrice"); series2 = new XYSeries("Volume"); //Disable advance button initially jButton4.setEnabled(false); this.midPriceHistory = new ArrayList<>(); this.volHistory = new ArrayList<>(); setVisible(true); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel5 = new javax.swing.JPanel(); jPanel7 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel25 = new javax.swing.JLabel(); jLabel26 = new javax.swing.JLabel(); jLabel27 = new javax.swing.JLabel(); jLabel28 = new javax.swing.JLabel(); jLabel29 = new javax.swing.JLabel(); jLabel30 = new javax.swing.JLabel(); jTextField7 = new javax.swing.JTextField(); jTextField8 = new javax.swing.JTextField(); jTextField9 = new javax.swing.JTextField(); jTextField10 = new javax.swing.JTextField(); jTextField11 = new javax.swing.JTextField(); jTextField12 = new javax.swing.JTextField(); jTextField13 = new javax.swing.JTextField(); jTextField14 = new javax.swing.JTextField(); jLabel31 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jLabel11 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); jTable2 = new javax.swing.JTable(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jLabel10 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jSlider1 = new javax.swing.JSlider(); jButton4 = new javax.swing.JButton(); jLabel14 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jPanel8 = new javax.swing.JPanel(); jLabel16 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); jLabel18 = new javax.swing.JLabel(); jLabel19 = new javax.swing.JLabel(); jLabel20 = new javax.swing.JLabel(); jLabel21 = new javax.swing.JLabel(); jLabel22 = new javax.swing.JLabel(); jLabel23 = new javax.swing.JLabel(); jLabel24 = new javax.swing.JLabel(); jPanel6 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); jScrollPane3 = new javax.swing.JScrollPane(); jTable3 = new javax.swing.JTable(); jPanel4 = new javax.swing.JPanel(); jPanel9 = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setResizable(false); jPanel5.setBackground(new java.awt.Color(255, 255, 255)); jPanel7.setBackground(new java.awt.Color(56, 56, 56)); jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 155, 68)); jLabel1.setText("Setup"); jLabel2.setForeground(new java.awt.Color(255, 255, 255)); jLabel2.setText("Start Price"); jLabel3.setForeground(new java.awt.Color(255, 255, 255)); jLabel3.setText("Tick Size"); jLabel4.setForeground(new java.awt.Color(255, 255, 255)); jLabel4.setText("Market Size"); jLabel5.setForeground(new java.awt.Color(255, 255, 255)); jLabel5.setText("Initial Capital"); jLabel8.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N jLabel8.setForeground(new java.awt.Color(255, 255, 255)); jLabel8.setText("Market Paramaters"); jTextField1.setText("10"); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); jTextField2.setText("0.1"); jTextField3.setText("10000"); jTextField3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField3ActionPerformed(evt); } }); jTextField4.setText("100000"); jTextField4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField4ActionPerformed(evt); } }); jButton2.setText("Start Simulation"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText("End Simatulation"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jLabel6.setForeground(new java.awt.Color(255, 255, 255)); jLabel6.setText( "<html>Click end simulation to dump the<br/> mid price and volume history to<br/> .txt files in parent directory</html>"); jLabel7.setForeground(new java.awt.Color(255, 255, 255)); jLabel7.setText("<html>Market<br/>Maker</html>"); jLabel25.setForeground(new java.awt.Color(255, 255, 255)); jLabel25.setText("<html>Trend<br/>Follower</html>"); jLabel26.setForeground(new java.awt.Color(255, 255, 255)); jLabel26.setText("<html>Contrarian</html>"); jLabel27.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N jLabel27.setForeground(new java.awt.Color(255, 255, 255)); jLabel27.setText("Agent Distribution"); jLabel28.setForeground(new java.awt.Color(255, 255, 255)); jLabel28.setText("<html>Lay Trader</html>"); jLabel29.setForeground(new java.awt.Color(255, 255, 255)); jLabel29.setText("Num"); jLabel30.setForeground(new java.awt.Color(255, 255, 255)); jLabel30.setText("% Start Cap"); jTextField7.setText("20"); jTextField7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField7ActionPerformed(evt); } }); jTextField8.setText("20"); jTextField8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField8ActionPerformed(evt); } }); jTextField9.setText("20"); jTextField9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField9ActionPerformed(evt); } }); jTextField10.setText("20"); jTextField10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField10ActionPerformed(evt); } }); jTextField11.setText("70"); jTextField11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField11ActionPerformed(evt); } }); jTextField12.setText("10"); jTextField12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField12ActionPerformed(evt); } }); jTextField13.setText("10"); jTextField13.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField13ActionPerformed(evt); } }); jTextField14.setText("10"); jTextField14.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField14ActionPerformed(evt); } }); jLabel31.setForeground(new java.awt.Color(255, 0, 51)); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout .setHorizontalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup().addGap(14, 14, 14) .addComponent( jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel27).addGap(31, 31, 31)) .addGroup(jPanel7Layout.createSequentialGroup().addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout .createSequentialGroup().addGap(14, 14, 14).addGroup(jPanel7Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3).addComponent(jLabel2)) .addGap(19, 19, 19)) .addGroup(jPanel7Layout.createSequentialGroup().addContainerGap().addGroup( jPanel7Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING).addComponent( jLabel4, javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel5, javax.swing.GroupLayout.Alignment.LEADING)))) .addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField4).addComponent(jTextField3) .addComponent(jTextField2).addComponent(jTextField1)) .addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jPanel7Layout.createSequentialGroup() .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent( jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(70, 70, 70)) .addGroup(jPanel7Layout.createSequentialGroup() .addGroup(jPanel7Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel28, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(jPanel7Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup( jPanel7Layout.createSequentialGroup() .addGap(1, 1, 1).addComponent( jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(22, 22, 22)) .addGroup(jPanel7Layout.createSequentialGroup().addGap(83, 83, 83) .addGroup(jPanel7Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel7Layout .createSequentialGroup() .addComponent(jLabel29).addGap( 18, 18, 18) .addComponent(jLabel30, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(jPanel7Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))))) .addGroup(jPanel7Layout.createSequentialGroup().addGap(106, 106, 106) .addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel31)) .addGroup(jPanel7Layout.createSequentialGroup().addGap(151, 151, 151) .addComponent(jLabel1))) .addContainerGap(9, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel7Layout.createSequentialGroup().addGap(25, 25, 25) .addComponent(jButton2))) .addGap(62, 62, 62))); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel27, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel29).addComponent(jLabel30)) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel7Layout.createSequentialGroup().addGap(15, 15, 15) .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup() .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel7Layout.createSequentialGroup().addGap(15, 15, 15) .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel28, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel7Layout.createSequentialGroup().addGap(15, 15, 15) .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(15, 15, 15) .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) .addComponent(jButton2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel31).addComponent(jButton3)))); jTextField7.getAccessibleContext().setAccessibleName(""); jPanel1.setBackground(new java.awt.Color(56, 56, 56)); jLabel11.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N jLabel11.setForeground(new java.awt.Color(255, 155, 68)); jLabel11.setText("Current Book State"); jTable2.setBackground(new java.awt.Color(56, 56, 56)); jTable2.setForeground(new java.awt.Color(255, 255, 255)); jTable2.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null }, { null, null, null } }, new String[] { "Bid Price", "Volume", "Ask Price" }) { boolean[] canEdit = new boolean[] { false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane2.setViewportView(jTable2); if (jTable2.getColumnModel().getColumnCount() > 0) { jTable2.getColumnModel().getColumn(0).setResizable(false); jTable2.getColumnModel().getColumn(1).setResizable(false); jTable2.getColumnModel().getColumn(2).setResizable(false); } jLabel12.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N jLabel12.setForeground(new java.awt.Color(255, 255, 255)); jLabel12.setText("Mid-price"); jLabel13.setForeground(new java.awt.Color(255, 255, 255)); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(135, 135, 135) .addComponent(jLabel11)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(18, 18, 18) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel12).addComponent(jLabel13)) .addGap(18, 18, 18).addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(81, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel11) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(113, 113, 113) .addComponent(jLabel12) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel13))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel2.setBackground(new java.awt.Color(55, 55, 55)); jLabel10.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N jLabel10.setForeground(new java.awt.Color(255, 155, 68)); jLabel10.setText("Control Panel"); jLabel9.setForeground(new java.awt.Color(255, 255, 255)); jLabel9.setText("Control Number of Steps Per Advance"); jSlider1.setMinimum(1); jSlider1.setMinorTickSpacing(1); jSlider1.setToolTipText(""); jSlider1.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { jSlider1StateChanged(evt); } }); jButton4.setText("Advance Step"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jLabel14.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N jLabel14.setForeground(new java.awt.Color(255, 255, 255)); jLabel14.setText("Timestep"); jLabel15.setForeground(new java.awt.Color(255, 255, 255)); jLabel15.setText("-----"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel2Layout.createSequentialGroup().addGap(114, 114, 114).addComponent(jLabel10)) .addGroup(jPanel2Layout.createSequentialGroup().addGap(58, 58, 58).addComponent(jLabel9)) .addGroup(jPanel2Layout.createSequentialGroup().addGap(75, 75, 75).addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton4) .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel14) .addGap(18, 18, 18).addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(133, 133, 133))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(21, 21, 21).addComponent(jLabel10) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton4) .addGap(28, 28, 28) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel14).addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel8.setBackground(new java.awt.Color(56, 56, 56)); jPanel8.setForeground(new java.awt.Color(255, 255, 255)); jLabel16.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N jLabel16.setForeground(new java.awt.Color(255, 155, 68)); jLabel16.setText("Timestep Metrics"); jLabel17.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N jLabel17.setForeground(new java.awt.Color(255, 255, 255)); jLabel17.setText("Total Volume traded"); jLabel18.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N jLabel18.setForeground(new java.awt.Color(255, 255, 255)); jLabel18.setText("Trade volume above midprice"); jLabel19.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N jLabel19.setForeground(new java.awt.Color(255, 255, 255)); jLabel19.setText("Average volume traded"); jLabel20.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N jLabel20.setForeground(new java.awt.Color(255, 255, 255)); jLabel20.setText("Trade volume below midprice"); jLabel21.setForeground(new java.awt.Color(255, 255, 255)); jLabel21.setText("------"); jLabel22.setForeground(new java.awt.Color(255, 255, 255)); jLabel22.setText("------"); jLabel23.setForeground(new java.awt.Color(255, 255, 255)); jLabel23.setText("------"); jLabel24.setForeground(new java.awt.Color(255, 255, 255)); jLabel24.setText("------"); javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8); jPanel8.setLayout(jPanel8Layout); jPanel8Layout.setHorizontalGroup( jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout .createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel16).addGap(164, 164, 164)) .addGroup(jPanel8Layout.createSequentialGroup().addGap(22, 22, 22) .addGroup(jPanel8Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel20).addComponent(jLabel19).addComponent(jLabel18) .addComponent(jLabel17)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel21).addComponent(jLabel22) .addComponent(jLabel23).addComponent(jLabel24)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel8Layout.setVerticalGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel8Layout.createSequentialGroup().addContainerGap().addComponent(jLabel16) .addGap(18, 18, 18) .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel17).addComponent(jLabel21)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel19).addComponent(jLabel22)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel18).addComponent(jLabel23)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel20).addComponent(jLabel24)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout .setHorizontalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); jTabbedPane1.addTab("Setup and Control", jPanel5); jPanel3.setBackground(new java.awt.Color(56, 56, 56)); jTable3.setBackground(new java.awt.Color(56, 56, 56)); jTable3.setForeground(new java.awt.Color(255, 255, 255)); jTable3.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null }, { null, null, null, null, null, null } }, new String[] { "Agent Type", "Agent Number", "Capital", "Shares", "Value", "Peak Val" })); jTable3.setGridColor(new java.awt.Color(56, 56, 56)); jTable3.setSelectionBackground(new java.awt.Color(56, 56, 56)); jTable3.setSelectionForeground(new java.awt.Color(255, 155, 68)); jScrollPane3.setViewportView(jTable3); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 839, Short.MAX_VALUE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout .createSequentialGroup().addContainerGap().addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE) .addContainerGap()))); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 560, Short.MAX_VALUE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout .createSequentialGroup().addContainerGap().addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE) .addContainerGap()))); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup( jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jTabbedPane1.addTab("Agent States", jPanel6); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 839, Short.MAX_VALUE)); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 560, Short.MAX_VALUE)); jTabbedPane1.addTab("Price Variation", jPanel4); javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9); jPanel9.setLayout(jPanel9Layout); jPanel9Layout.setHorizontalGroup(jPanel9Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 839, Short.MAX_VALUE)); jPanel9Layout.setVerticalGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 560, Short.MAX_VALUE)); jTabbedPane1.addTab("Volume Traded", jPanel9); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jTabbedPane1))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jTabbedPane1))); pack(); }// </editor-fold>//GEN-END:initComponents /* Run the broker by clicking the "advance" button */ public void run() { int i = 0; /* Run the number expected by the 'advance step' bar */ while (i < this.delay) { this.broker.runTimestep(this.time); setNewGUIState(); this.time++; i++; } } /* Runs the simulation with the input file. Currently not in use public void ParseFromFile() { this.broker = new Brokerage(this.sp, this.ic, this.mt, this.ms, this.ts, 0.83f,null,null); this.time = 0; int maxTime; ArrayList<String[]> ordersList = new ArrayList<String[]>(); BufferedReader br = null; String line = ""; String cvsSplitBy = ","; try { br = new BufferedReader(new FileReader("csvOrders.csv")); while ((line = br.readLine()) != null) { // use comma as separator String[] order = line.split(cvsSplitBy); ordersList.add(order); maxTime = Integer.parseInt(order[5]); //whatever is the time entry. } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } //File now parsed into string array, now pass this to another method to construct and send orders simFromFile(9,ordersList); } public void simFromFile(int maxTime, ArrayList<String[]> input) { int i = 1; int pos = 0; int maxPos = input.size(); while (i<=maxTime && pos<maxPos) { boolean currentStep = true; ArrayList<String[]> toConvert = new ArrayList<String[]>(); while (currentStep && pos<maxPos) { System.out.println(input.get(pos)[5]); if (Integer.parseInt(input.get(pos)[5])==i) { toConvert.add(input.get(pos)); pos++; } else currentStep = false; } ArrayList<Order> newOrders = convertToOrder(toConvert); if (i==1) this.broker.runFirstFromFIle(newOrders); else this.broker.runFromFile(newOrders,i); setNewGUIState(); i++; this.time++; } } public ArrayList<Order> convertToOrder(ArrayList<String[]> orders){ ArrayList<Order> newOrders = new ArrayList<>(); ListIterator<String[]> LI = orders.listIterator(); while (LI.hasNext()) { String[] curr = LI.next(); int AgentID = Integer.parseInt(curr[0]); Side side; if (curr[1].equals("BID")) side = BID; else side = ASK; Order.Type typeO; if (curr[2].equals("LIMIT")) typeO = LIMIT; else typeO = MARKET; long volume = Long.parseLong(curr[3]); float price = Float.parseFloat(curr[4]); System.out.println("NEW ORDER: "+AgentID+side+typeO+volume+price); Order newOrder = new Order(AgentID,side, typeO, volume, price); newOrders.add(newOrder); } return newOrders; } /* run the next set of steps */ private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: run(); }//GEN-LAST:event_jButton4ActionPerformed /* Change time steps advanced per click */ private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider1StateChanged // TODO add your handling code here: int val = jSlider1.getValue(); this.delay = val; }//GEN-LAST:event_jSlider1StateChanged private void jTextField14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField14ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField14ActionPerformed private void jTextField13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField13ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField13ActionPerformed private void jTextField12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField12ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField12ActionPerformed private void jTextField11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField11ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField11ActionPerformed private void jTextField10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField10ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField10ActionPerformed private void jTextField9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField9ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField9ActionPerformed private void jTextField8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField8ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField8ActionPerformed private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField7ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField7ActionPerformed /* Exit the simulation; dump data then exit. */ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try { // TODO add your handling code here: dumpData(); } catch (FileNotFoundException ex) { Logger.getLogger(VisualisationGUI.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(VisualisationGUI.class.getName()).log(Level.SEVERE, null, ex); } System.exit(0); }//GEN-LAST:event_jButton3ActionPerformed /* Start simulation pressed, parse all input data and then instantiate broker; disable start button. */ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: boolean validEntry = true; //Convert all entries into acceptable format for broker. Alert user if //unacceptable entries try { this.sp = Float.parseFloat(jTextField1.getText()); this.ts = Float.parseFloat(jTextField2.getText()); this.ms = Long.parseLong(jTextField3.getText()); this.ic = Float.parseFloat(jTextField4.getText()); this.nmm = Integer.parseInt(jTextField7.getText()); this.ntf = Integer.parseInt(jTextField8.getText()); this.nc = Integer.parseInt(jTextField9.getText()); this.nlt = Integer.parseInt(jTextField10.getText()); this.smm = Float.parseFloat(jTextField11.getText()); this.stf = Float.parseFloat(jTextField12.getText()); this.sc = Float.parseFloat(jTextField13.getText()); this.slt = Float.parseFloat(jTextField14.getText()); jLabel31.setText(""); } catch (NumberFormatException e) { validEntry = false; jLabel31.setText("Invalid Entry!"); } //Check number of agents allows agent state display or not if ((this.nmm + this.ntf + this.nc + this.nlt) <= 100) this.displayAgentStates = true; else this.displayAgentStates = false; //Check the split of agents is acceptable if ((this.smm + this.stf + this.sc + this.slt) != 100) { //if not default to 70/10/10/10 this.smm = 0.7f; this.stf = 0.1f; this.sc = 0.1f; this.slt = 0.1f; } else { this.smm = (smm / 100); this.stf = (stf / 100); this.sc = (sc / 100); this.slt = (slt / 100); } //To pass the broker on initialisation int[] agentNums = { this.nmm, this.ntf, this.nc, this.nlt }; float[] agentSplit = { this.smm, this.stf, this.sc, this.slt }; //If the initial capital is less than the market size * starting price, //make the initial capital an acceptable value. if (this.ic < this.ms * this.sp) this.ic = this.ms * this.sp; //Before the simulation can start, an initial volatility is set: float volatility; Random rand = new Random(); volatility = rand.nextFloat() * (1f - 0.8f) + 0.8f; if (validEntry) { //start simulation; disable input here; jButton2.setEnabled(false); //jButton1.setEnabled(false); jButton4.setEnabled(true); this.broker = new Brokerage(this.sp, this.ic, this.mt, this.ms, this.ts, volatility, agentNums, agentSplit); this.time = 1; this.broker.runFirstStep(); setNewGUIState(); this.time = 2; } } //GEN-LAST:event_jButton2ActionPerformed private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField4ActionPerformed private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField3ActionPerformed private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField1ActionPerformed /* Dump data to two text files labeled MidPrice.txt and Volume.txt in the parent directory. */ public void dumpData() throws FileNotFoundException, UnsupportedEncodingException { PrintWriter midPriceWriter = new PrintWriter("MidPrice.txt", "UTF-8"); ListIterator<Float> MLI = this.midPriceHistory.listIterator(); while (MLI.hasNext()) { midPriceWriter.println(MLI.next()); } midPriceWriter.close(); PrintWriter volWriter = new PrintWriter("Volume.txt", "UTF-8"); ListIterator<Long> VLI = this.volHistory.listIterator(); while (VLI.hasNext()) { volWriter.println(VLI.next()); } volWriter.close(); } /* Update the price table on the setup and control tab containing the order book info */ public void updatePriceTable(LinkedHashMap<Float, Long> askTree, LinkedHashMap<Float, Long> bidTree) { //Clear old entries clearTable(jTable2); //Get the number of points on each side int numberAskPoints = askTree.size(); int numberBidPoints = bidTree.size(); int currentTableRow = 7; //Fill ask entries for (Map.Entry<Float, Long> entry : askTree.entrySet()) { float key = entry.getKey(); long value = entry.getValue(); jTable2.getModel().setValueAt(key, currentTableRow, 2); jTable2.getModel().setValueAt(value, currentTableRow, 1); currentTableRow--; if (currentTableRow < 1) break; } //Fill bid entries currentTableRow = 8 + numberBidPoints; for (Map.Entry<Float, Long> entry : bidTree.entrySet()) { float key = entry.getKey(); long value = entry.getValue(); jTable2.getModel().setValueAt(key, currentTableRow, 0); jTable2.getModel().setValueAt(value, currentTableRow, 1); currentTableRow--; if (currentTableRow < 9) break; } } /* Only occurs if less than 100 agents used */ public void updateAgentStates() { HashMap<AgentSuper, AgentInformation> agentInfo = this.broker.getAgentInfo(); int currRow = 0; float totalcash = 0; long totalVol = 0; /* This section of code iteratres through each agents info from the broker class and updates their holdings for the table in the GUI */ if (displayAgentStates) { for (Map.Entry<AgentSuper, AgentInformation> entry : agentInfo.entrySet()) { AgentSuper agent = entry.getKey(); AgentInformation AI = entry.getValue(); totalcash = totalcash + AI.getCapital(); //Absolutes in market (not per agent) totalVol = totalVol + AI.getVolume(); float value = (AI.getVolume() * this.midPrice) + AI.getCapital(); if (this.time == 1) this.agentBestValue.put(agent.getAgentNo(), value); else { float peak = this.agentBestValue.get(agent.getAgentNo()); if (value > peak) this.agentBestValue.put(agent.getAgentNo(), value); } jTable3.getModel().setValueAt(AI.getType(), currRow, 0); jTable3.getModel().setValueAt(agent.agentNo, currRow, 1); jTable3.getModel().setValueAt(AI.getCapital(), currRow, 2); jTable3.getModel().setValueAt((AI.getVolume()), currRow, 3); jTable3.getModel().setValueAt(value, currRow, 4); jTable3.getModel().setValueAt((this.agentBestValue.get(agent.getAgentNo())), currRow, 5); currRow++; } } } /* Update the state of the gui */ public void setNewGUIState() { GUIUpdatePackage GUP = broker.updateGUI(); LinkedHashMap<Float, Long> askTree = GUP.getAskTree(); LinkedHashMap<Float, Long> bidTree = GUP.getBidTree(); updateLabels(GUP); updatePriceTable(askTree, bidTree); updateAgentStates(); updatePriceChart(GUP); updateVolumeChart(GUP); } /* updates all labels in the main GUI screen */ public void updateLabels(GUIUpdatePackage GUP) { jLabel15.setText(Integer.toString(this.time)); LinkedList<Trade> newTrades = this.broker.getNewTrades(); float mid = GUP.getMidpriceHistory().getLast(); this.midPrice = mid; long above = 0; long below = 0; long exact = 0; //Add up trade metrics for (int i = 0; i < newTrades.size(); i++) { Trade trade = newTrades.get(i); if (trade.getTradePrice() > mid) above = above + trade.getTradeVolume(); else if (trade.getTradePrice() < mid) below = below + trade.getTradeVolume(); else exact = exact + trade.getTradeVolume(); } long tot = above + below + exact; this.totalTraded = this.totalTraded + tot; this.averageTradeVolume = this.totalTraded / this.time; jLabel21.setText(Long.toString(tot)); jLabel22.setText(Long.toString(this.averageTradeVolume)); jLabel23.setText(Long.toString(above)); jLabel24.setText(Long.toString(below)); } //creates a new chart to display price - time public void updatePriceChart(GUIUpdatePackage GUP) { float currMid = GUP.getMidpriceHistory().getLast(); int t = GUP.getTime(); jLabel13.setText(Float.toString(currMid)); series1.add(t, currMid); this.midPriceHistory.add(currMid); JFreeChart chart = createChart(series1, "Price-Time", "Time", "Price"); ChartPanel chPanel = new ChartPanel(chart); chPanel.setPreferredSize(new Dimension(785, 440)); chPanel.setMouseWheelEnabled(true); jPanel4.setLayout(new java.awt.BorderLayout()); jPanel4.add(chPanel, BorderLayout.CENTER); jPanel4.validate(); } //New chart for volume public void updateVolumeChart(GUIUpdatePackage GUP) { long volume = GUP.getTradeVolumeHistory().getLast(); int t = GUP.getTime(); series2.add(t, volume); this.volHistory.add(volume); JFreeChart chart = createChart(series2, "Volume-Time", "Time", "Volume"); ChartPanel chPanel = new ChartPanel(chart); chPanel.setPreferredSize(new Dimension(785, 440)); chPanel.setMouseWheelEnabled(true); jPanel9.setLayout(new java.awt.BorderLayout()); jPanel9.add(chPanel, BorderLayout.CENTER); jPanel9.validate(); } //Chart constructor generic private JFreeChart createChart(final XYSeries series, String title, String x, String y) { final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title x, // x axis label y, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); return chart; } //Clears table generic public void clearTable(final JTable table) { DefaultTableModel dm = (DefaultTableModel) table.getModel(); for (int i = 0; i < dm.getRowCount(); i++) { for (int j = 0; j < dm.getColumnCount(); j++) { dm.setValueAt("", i, j); } } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Windows".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(VisualisationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(VisualisationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(VisualisationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(VisualisationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new VisualisationGUI().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel22; private javax.swing.JLabel jLabel23; private javax.swing.JLabel jLabel24; private javax.swing.JLabel jLabel25; private javax.swing.JLabel jLabel26; private javax.swing.JLabel jLabel27; private javax.swing.JLabel jLabel28; private javax.swing.JLabel jLabel29; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel30; private javax.swing.JLabel jLabel31; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JPanel jPanel8; private javax.swing.JPanel jPanel9; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JSlider jSlider1; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTable jTable2; private javax.swing.JTable jTable3; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField10; private javax.swing.JTextField jTextField11; private javax.swing.JTextField jTextField12; private javax.swing.JTextField jTextField13; private javax.swing.JTextField jTextField14; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField7; private javax.swing.JTextField jTextField8; private javax.swing.JTextField jTextField9; // End of variables declaration//GEN-END:variables }