Better fairValue calculation
This commit is contained in:
parent
1fd742f714
commit
2a78e13510
@ -16,9 +16,15 @@
|
|||||||
<Layout>
|
<Layout>
|
||||||
<DimensionLayout dim="0">
|
<DimensionLayout dim="0">
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Group type="102" alignment="0" attributes="0">
|
<Group type="102" attributes="0">
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jScrollPane1" pref="446" max="32767" attributes="0"/>
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Component id="jScrollPane1" pref="446" max="32767" attributes="0"/>
|
||||||
|
<Group type="102" attributes="0">
|
||||||
|
<Component id="summary" min="-2" pref="264" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
@ -27,8 +33,10 @@
|
|||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Group type="102" alignment="0" attributes="0">
|
<Group type="102" alignment="0" attributes="0">
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jScrollPane1" pref="288" max="32767" attributes="0"/>
|
<Component id="jScrollPane1" min="-2" pref="257" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="summary" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace pref="16" max="32767" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
@ -76,5 +84,10 @@
|
|||||||
</Component>
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Container>
|
</Container>
|
||||||
|
<Component class="javax.swing.JLabel" name="summary">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="jLabel1"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -93,7 +93,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
|||||||
JSONObject rowobj = traders.getJSONObject(row);
|
JSONObject rowobj = traders.getJSONObject(row);
|
||||||
for (int col = 0; col < list.getColumnCount(); col++) {
|
for (int col = 0; col < list.getColumnCount(); col++) {
|
||||||
String h = this.getColumnHeader(col);
|
String h = this.getColumnHeader(col);
|
||||||
// System.out.printf("Doing stuff for %s\n", h);
|
// System.out.printf("Doing stuff for %s\n", h);
|
||||||
|
|
||||||
String val = null;
|
String val = null;
|
||||||
try {
|
try {
|
||||||
@ -131,6 +131,24 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefaultTableModel model;
|
||||||
|
|
||||||
|
private double getFairValue() {
|
||||||
|
Double money = 0.0;
|
||||||
|
Double shares = 0.0;
|
||||||
|
|
||||||
|
for (int r = 0; r < model.getRowCount(); r++) {
|
||||||
|
Boolean e = (Boolean) list.getValueAt(r, list.getColumn("Enabled").getModelIndex());
|
||||||
|
if (!e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
money += (Double) list.getValueAt(r, list.getColumn("Money").getModelIndex());
|
||||||
|
shares += (Double) list.getValueAt(r, list.getColumn("Shares").getModelIndex());
|
||||||
|
System.out.printf("Row: %d %f %f\n", r, money, shares);
|
||||||
|
}
|
||||||
|
return money / shares;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form NewJPanel
|
* Creates new form NewJPanel
|
||||||
*/
|
*/
|
||||||
@ -147,7 +165,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
|||||||
|
|
||||||
Globals.getStrategiesIntoComboBox(comboBox);
|
Globals.getStrategiesIntoComboBox(comboBox);
|
||||||
|
|
||||||
DefaultTableModel model = (DefaultTableModel) list.getModel();
|
model = (DefaultTableModel) list.getModel();
|
||||||
list.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(comboBox));
|
list.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(comboBox));
|
||||||
// list.getColumnModel().getColumn(2).setCellRenderer(new javax.swing.table.DefaultTableCellRenderer());
|
// list.getColumnModel().getColumn(2).setCellRenderer(new javax.swing.table.DefaultTableCellRenderer());
|
||||||
// model.setRowCount(3);
|
// model.setRowCount(3);
|
||||||
@ -155,22 +173,10 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
|||||||
list.setRowHeight(30);
|
list.setRowHeight(30);
|
||||||
|
|
||||||
list.getModel().addTableModelListener((TableModelEvent e) -> {
|
list.getModel().addTableModelListener((TableModelEvent e) -> {
|
||||||
System.out.printf("Table has changed\n", "");
|
this.summary.setText(String.format("Fair Value: %.5f", this.getFairValue()));
|
||||||
// if (summary==null)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
Double money = 0.0;
|
|
||||||
Double shares = 0.0;
|
|
||||||
|
|
||||||
for (int r = 0; r < model.getRowCount(); r++) {
|
|
||||||
// money += (Double) list.getValueAt(r, list.getColumn("Money").getModelIndex());
|
|
||||||
// shares += (Double) list.getValueAt(r, list.getColumn("Shares").getModelIndex());
|
|
||||||
System.out.printf("Row: %d %f %f\n", r, money, shares);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.summary.setText(String.format("Fair Value: %.5f", money / shares));
|
|
||||||
});
|
});
|
||||||
|
this.summary.setText(String.format("Fair Value: %.5f", this.getFairValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void add() {
|
void add() {
|
||||||
@ -178,8 +184,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
|||||||
model.setRowCount(model.getRowCount() + 1);
|
model.setRowCount(model.getRowCount() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
JLabel summary = null;
|
// JLabel summary = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* 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
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
@ -191,6 +196,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
|||||||
|
|
||||||
jScrollPane1 = new javax.swing.JScrollPane();
|
jScrollPane1 = new javax.swing.JScrollPane();
|
||||||
list = new javax.swing.JTable();
|
list = new javax.swing.JTable();
|
||||||
|
summary = new javax.swing.JLabel();
|
||||||
|
|
||||||
list.setAutoCreateRowSorter(true);
|
list.setAutoCreateRowSorter(true);
|
||||||
list.setModel(new javax.swing.table.DefaultTableModel(
|
list.setModel(new javax.swing.table.DefaultTableModel(
|
||||||
@ -212,21 +218,29 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
|||||||
});
|
});
|
||||||
jScrollPane1.setViewportView(list);
|
jScrollPane1.setViewportView(list);
|
||||||
|
|
||||||
|
summary.setText("jLabel1");
|
||||||
|
|
||||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||||
this.setLayout(layout);
|
this.setLayout(layout);
|
||||||
layout.setHorizontalGroup(
|
layout.setHorizontalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
|
||||||
|
.addGroup(layout.createSequentialGroup()
|
||||||
|
.addComponent(summary, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addGap(0, 0, Short.MAX_VALUE)))
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
);
|
);
|
||||||
layout.setVerticalGroup(
|
layout.setVerticalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
|
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addContainerGap())
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addComponent(summary)
|
||||||
|
.addContainerGap(16, Short.MAX_VALUE))
|
||||||
);
|
);
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
@ -234,5 +248,6 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
|||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JScrollPane jScrollPane1;
|
private javax.swing.JScrollPane jScrollPane1;
|
||||||
private javax.swing.JTable list;
|
private javax.swing.JTable list;
|
||||||
|
private javax.swing.JLabel summary;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
}
|
}
|
||||||
|
@ -25,28 +25,31 @@
|
|||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Group type="102" alignment="1" attributes="0">
|
<Group type="102" alignment="1" attributes="0">
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jLabelSummary" max="32767" attributes="0"/>
|
<Group type="103" groupAlignment="1" attributes="0">
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<Component id="editAutoTraderList1" pref="529" max="32767" attributes="0"/>
|
||||||
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
|
<Group type="102" attributes="0">
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||||
<Component id="jOkButton" min="-2" max="-2" attributes="0"/>
|
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
|
<Component id="jOkButton" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
<Component id="editAutoTraderList1" alignment="1" pref="541" max="32767" attributes="0"/>
|
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
<DimensionLayout dim="1">
|
<DimensionLayout dim="1">
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Group type="102" alignment="1" attributes="0">
|
<Group type="102" alignment="1" attributes="0">
|
||||||
<Component id="editAutoTraderList1" pref="267" max="32767" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="editAutoTraderList1" pref="331" max="32767" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="3" attributes="0">
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
<Component id="jOkButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="jOkButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
<Component id="jLabelSummary" alignment="3" min="-2" max="-2" attributes="0"/>
|
|
||||||
</Group>
|
</Group>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
@ -54,8 +57,6 @@
|
|||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
</Layout>
|
</Layout>
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Component class="gui.EditAutoTraderList" name="editAutoTraderList1">
|
|
||||||
</Component>
|
|
||||||
<Component class="javax.swing.JButton" name="jButton1">
|
<Component class="javax.swing.JButton" name="jButton1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="mnemonic" type="int" value="99"/>
|
<Property name="mnemonic" type="int" value="99"/>
|
||||||
@ -83,7 +84,7 @@
|
|||||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
|
||||||
</Events>
|
</Events>
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="javax.swing.JLabel" name="jLabelSummary">
|
<Component class="gui.EditAutoTraderList" name="editAutoTraderList1">
|
||||||
</Component>
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -39,7 +39,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog {
|
|||||||
initComponents();
|
initComponents();
|
||||||
this.setTitle("Edit Auto Traders");
|
this.setTitle("Edit Auto Traders");
|
||||||
this.setLocationRelativeTo(this.getParent());
|
this.setLocationRelativeTo(this.getParent());
|
||||||
this.editAutoTraderList1.summary=this.jLabelSummary;
|
// this.editAutoTraderList1.summary=this.jLabelSummary;
|
||||||
//this.setLocationRelativeTo(MainWin.instance);
|
//this.setLocationRelativeTo(MainWin.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,11 +52,10 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog {
|
|||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
|
|
||||||
editAutoTraderList1 = new gui.EditAutoTraderList();
|
|
||||||
jButton1 = new javax.swing.JButton();
|
jButton1 = new javax.swing.JButton();
|
||||||
jOkButton = new javax.swing.JButton();
|
jOkButton = new javax.swing.JButton();
|
||||||
jButton2 = new javax.swing.JButton();
|
jButton2 = new javax.swing.JButton();
|
||||||
jLabelSummary = new javax.swing.JLabel();
|
editAutoTraderList1 = new gui.EditAutoTraderList();
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
@ -90,26 +89,27 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog {
|
|||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(jLabelSummary, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addComponent(editAutoTraderList1, javax.swing.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE)
|
||||||
.addComponent(jButton2)
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addGap(0, 0, Short.MAX_VALUE)
|
||||||
.addComponent(jOkButton)
|
.addComponent(jButton2)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(jButton1)
|
.addComponent(jOkButton)
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addComponent(jButton1)))
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
.addComponent(editAutoTraderList1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
|
|
||||||
);
|
);
|
||||||
layout.setVerticalGroup(
|
layout.setVerticalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
.addComponent(editAutoTraderList1, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
|
.addContainerGap()
|
||||||
|
.addComponent(editAutoTraderList1, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(jButton1)
|
.addComponent(jButton1)
|
||||||
.addComponent(jOkButton)
|
.addComponent(jOkButton)
|
||||||
.addComponent(jButton2)
|
.addComponent(jButton2))
|
||||||
.addComponent(jLabelSummary))
|
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -176,7 +176,6 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog {
|
|||||||
private gui.EditAutoTraderList editAutoTraderList1;
|
private gui.EditAutoTraderList editAutoTraderList1;
|
||||||
private javax.swing.JButton jButton1;
|
private javax.swing.JButton jButton1;
|
||||||
private javax.swing.JButton jButton2;
|
private javax.swing.JButton jButton2;
|
||||||
private javax.swing.JLabel jLabelSummary;
|
|
||||||
private javax.swing.JButton jOkButton;
|
private javax.swing.JButton jOkButton;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user