Better fairValue calculation

This commit is contained in:
7u83 2017-03-19 16:07:38 +01:00
parent 1fd742f714
commit 2a78e13510
4 changed files with 80 additions and 52 deletions

View File

@ -16,9 +16,15 @@
<Layout>
<DimensionLayout dim="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"/>
<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"/>
</Group>
</Group>
@ -27,8 +33,10 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" 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"/>
<Component id="summary" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="16" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -76,5 +84,10 @@
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="summary">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel1"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -93,7 +93,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
JSONObject rowobj = traders.getJSONObject(row);
for (int col = 0; col < list.getColumnCount(); 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;
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
*/
@ -147,7 +165,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
Globals.getStrategiesIntoComboBox(comboBox);
DefaultTableModel model = (DefaultTableModel) list.getModel();
model = (DefaultTableModel) list.getModel();
list.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(comboBox));
// list.getColumnModel().getColumn(2).setCellRenderer(new javax.swing.table.DefaultTableCellRenderer());
// model.setRowCount(3);
@ -155,22 +173,10 @@ public class EditAutoTraderList extends javax.swing.JPanel {
list.setRowHeight(30);
list.getModel().addTableModelListener((TableModelEvent e) -> {
System.out.printf("Table has changed\n", "");
// if (summary==null)
// return;
this.summary.setText(String.format("Fair Value: %.5f", this.getFairValue()));
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() {
@ -178,8 +184,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
model.setRowCount(model.getRowCount() + 1);
}
JLabel summary = null;
// JLabel summary = null;
/**
* 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
@ -191,6 +196,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
jScrollPane1 = new javax.swing.JScrollPane();
list = new javax.swing.JTable();
summary = new javax.swing.JLabel();
list.setAutoCreateRowSorter(true);
list.setModel(new javax.swing.table.DefaultTableModel(
@ -212,21 +218,29 @@ public class EditAutoTraderList extends javax.swing.JPanel {
});
jScrollPane1.setViewportView(list);
summary.setText("jLabel1");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.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())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
.addContainerGap())
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(summary)
.addContainerGap(16, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
@ -234,5 +248,6 @@ public class EditAutoTraderList extends javax.swing.JPanel {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable list;
private javax.swing.JLabel summary;
// End of variables declaration//GEN-END:variables
}

View File

@ -25,28 +25,31 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabelSummary" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace 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 type="103" groupAlignment="1" attributes="0">
<Component id="editAutoTraderList1" pref="529" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace 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"/>
</Group>
<Component id="editAutoTraderList1" alignment="1" pref="541" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" 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"/>
<Group type="103" groupAlignment="3" 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="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabelSummary" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -54,8 +57,6 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="gui.EditAutoTraderList" name="editAutoTraderList1">
</Component>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<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"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabelSummary">
<Component class="gui.EditAutoTraderList" name="editAutoTraderList1">
</Component>
</SubComponents>
</Form>

View File

@ -39,7 +39,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog {
initComponents();
this.setTitle("Edit Auto Traders");
this.setLocationRelativeTo(this.getParent());
this.editAutoTraderList1.summary=this.jLabelSummary;
// this.editAutoTraderList1.summary=this.jLabelSummary;
//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
private void initComponents() {
editAutoTraderList1 = new gui.EditAutoTraderList();
jButton1 = new javax.swing.JButton();
jOkButton = 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);
@ -90,26 +89,27 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabelSummary, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jOkButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(editAutoTraderList1, javax.swing.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jOkButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))
.addContainerGap())
.addComponent(editAutoTraderList1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.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)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jOkButton)
.addComponent(jButton2)
.addComponent(jLabelSummary))
.addComponent(jButton2))
.addContainerGap())
);
@ -176,7 +176,6 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog {
private gui.EditAutoTraderList editAutoTraderList1;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabelSummary;
private javax.swing.JButton jOkButton;
// End of variables declaration//GEN-END:variables
}