This commit is contained in:
7u83 2017-01-05 23:18:19 +01:00
parent 8017ad5834
commit af6acdbab1
13 changed files with 308 additions and 41 deletions

17
nbactions.xml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath gui.MainWin</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId> <groupId>com.cauwersin</groupId>
<artifactId>SeSim</artifactId> <artifactId>SeSim</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -25,7 +25,6 @@
*/ */
package gui; package gui;
import sesim.Exchange.*;
import sesim.Order.*; import sesim.Order.*;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -34,10 +34,10 @@ public class CandlestickDemo extends JFrame {
//Now create the chart and chart panel //Now create the chart and chart panel
JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false); JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false);
ChartPanel chartPanel = new ChartPanel(chart); // ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(600, 300)); // chartPanel.setPreferredSize(new Dimension(600, 300));
this.add(chartPanel); // this.add(chartPanel);
this.pack(); this.pack();
} }
protected AbstractXYDataset getDataSet(String stockSymbol) { protected AbstractXYDataset getDataSet(String stockSymbol) {

View File

@ -74,7 +74,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
DateAxis domainAxis = new DateAxis("Date"); DateAxis domainAxis = new DateAxis("Date");
NumberAxis rangeAxis = new NumberAxis("Price"); NumberAxis rangeAxis = new NumberAxis("Price");
CandlestickRenderer renderer = new CandlestickRenderer(); CandlestickRenderer renderer = new CandlestickRenderer();
XYDataset dataset = getDataSet(stockSymbol); XYDataset dataset = getDataSet(stockSymbol);
XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
@ -87,6 +89,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
//Now create the chart and chart panel //Now create the chart and chart panel
JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false); JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false);
ChartPanel chartPanel = new ChartPanel(chart); ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270)); chartPanel.setPreferredSize(new Dimension(500, 270));
@ -129,25 +132,22 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
double high = 0; double high = 0;
double low = 0; double low = 0;
double close = 0; double close = 0;
double volume=0; double volume = 0;
Iterator<Quote> it = l.iterator(); Iterator<Quote> it = l.iterator();
Quote q; Quote q;
if (it.hasNext()) { if (it.hasNext()) {
q = it.next(); q = it.next();
open = q.price; open = q.price;
high = q.price; high = q.price;
low = q.price; low = q.price;
volume = q.volume; volume = q.volume;
} } else {
else {
q = new Quote(); q = new Quote();
} }
while (it.hasNext() && q.time < last) { while (it.hasNext() && q.time < last) {
q = it.next(); q = it.next();
@ -178,8 +178,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 60); SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 60);
for (long i = (ct - 60)*1000; i < (ct + 10)*1000; i += 10*1000) { for (long i = (ct - 60) * 1000; i < (ct + 10) * 1000; i += 10 * 1000) {
OHLCDataItem d = getOhlcData(i, i + 10*1000, h); OHLCDataItem d = getOhlcData(i, i + 10 * 1000, h);
data.add(d); data.add(d);
} }
@ -255,8 +255,16 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
@Override @Override
public void UpdateQuote(Quote q) { public void UpdateQuote(Quote q) {
return;
//q.print(); // q.print();
long ct;
ct = Exchange.getCurrentTimeSeconds(5);
SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 15);
System.out.print("Number of quotes" + ct + "\n");
System.out.print("Number of quotes:" + h.size() + "\n");
/* SortedSet h = MainWin.se.getQuoteHistory(60); /* SortedSet h = MainWin.se.getQuoteHistory(60);
System.out.print( System.out.print(
"SortedSet size:" "SortedSet size:"

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

View File

@ -0,0 +1,46 @@
/*
* 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 gui;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class ChartPanel extends javax.swing.JPanel {
/**
* Creates new form ChartPanel
*/
public ChartPanel() {
initComponents();
}
/**
* 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() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,130 @@
/*
* 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 gui;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.Timer;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.DynamicTimeSeriesCollection;
import org.jfree.data.time.Second;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
/**
* @see http://stackoverflow.com/questions/5048852
*/
public class DTSCTest extends ApplicationFrame {
private static final String TITLE = "Dynamic Series";
private static final String START = "Start";
private static final String STOP = "Stop";
private static final float MINMAX = 300;
private static final int COUNT = 2 * 60;
private static final int FAST = 100;
private static final int SLOW = FAST * 5;
private static final Random RANDOM = new Random();
private Timer timer;
public DTSCTest(final String title) {
super(title);
final DynamicTimeSeriesCollection dataset
= new DynamicTimeSeriesCollection(1, COUNT, new Second());
dataset.setTimeBase(new Second(0, 0, 0, 1, 1, 2011));
dataset.addSeries(gaussianData(), 0, "Gaussian data");
JFreeChart chart = createChart(dataset);
final JButton run = new JButton(STOP);
run.addActionListener((ActionEvent e) -> {
String cmd = e.getActionCommand();
if (STOP.equals(cmd)) {
timer.stop();
run.setText(START);
} else {
timer.start();
run.setText(STOP);
}
});
final JComboBox combo = new JComboBox();
combo.addItem("Fast");
combo.addItem("Slow");
combo.addActionListener((ActionEvent e) -> {
if ("Fast".equals(combo.getSelectedItem())) {
timer.setDelay(FAST);
} else {
timer.setDelay(SLOW);
}
});
this.add(new ChartPanel(chart), BorderLayout.CENTER);
JPanel btnPanel = new JPanel(new FlowLayout());
// btnPanel.add(run);
// btnPanel.add(combo);
this.add(btnPanel, BorderLayout.SOUTH);
timer = new Timer(FAST, new ActionListener() {
float[] newData = new float[1];
@Override
public void actionPerformed(ActionEvent e) {
newData[0] = randomValue();
dataset.advanceTime();
dataset.appendData(newData);
}
});
}
private float randomValue() {
return (float) (RANDOM.nextGaussian() * MINMAX / 3);
}
private float[] gaussianData() {
float[] a = new float[COUNT];
for (int i = 0; i < a.length; i++) {
a[i] = randomValue();
}
return a;
}
private JFreeChart createChart(final XYDataset dataset) {
final JFreeChart result = ChartFactory.createTimeSeriesChart(
TITLE, "hh:mm:ss", "milliVolts", dataset, true, true, false);
final XYPlot plot = result.getXYPlot();
ValueAxis domain = plot.getDomainAxis();
domain.setAutoRange(true);
ValueAxis range = plot.getRangeAxis();
range.setRange(-MINMAX, MINMAX);
return result;
}
public void start() {
timer.start();
}
public static void main(final String[] args) {
EventQueue.invokeLater(() -> {
DTSCTest demo = new DTSCTest(TITLE);
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
demo.start();
});
}
}

View File

@ -97,7 +97,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
protected class OrderBookListModel extends AbstractTableModel { protected class OrderBookListModel extends AbstractTableModel {
private ArrayList list; private ArrayList list;
private boolean desc = false; //private final boolean desc = false;
public OrderBookListModel() { public OrderBookListModel() {
// System.out.print("CREATING A NEW MODEL\n"); // System.out.print("CREATING A NEW MODEL\n");

View File

@ -106,9 +106,46 @@ public class test {
return ts.tailSet(iter.next()); return ts.tailSet(iter.next());
} }
static abstract interface Rc {
public abstract int inc(int x);
// public abstract int dec(int x);
}
public static void main(String args[]) { public static void main(String args[]) {
NoProblem p = new NoProblem(); // NoProblem p = new NoProblem();
p.run(); // p.run();
Rc a = new Rc(){
@Override
public int inc(int x) {
return x+1;
}
/* @Override
public int dec(int x) {
return x+1;
}
*/
};
Rc l = (x) -> x+1;
System.out.print("A:"
+a.inc(17)
+" "
+l.inc(4)
);
} }

View File

@ -39,25 +39,26 @@ public abstract class AutoTrader extends Trader implements Runnable {
protected void doSleep(int seconds) { protected void doSleep(int seconds) {
try { try {
sleep(seconds*1000); sleep(seconds * 1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
public void start(){ public void start() {
System.out.print("Starting AutoTrader\n"); System.out.print("Starting AutoTrader\n");
class Runner extends Thread{ class Runner extends Thread {
AutoTrader trader; AutoTrader trader;
@Override @Override
public void run(){ public void run() {
trader.run(); trader.run();
} }
} }
Runner r = new Runner(); Runner r = new Runner();
r.trader=this; r.trader = this;
r.start(); r.start();
} }
} }

View File

@ -28,20 +28,19 @@ public class Exchange extends Thread {
} }
public static long getCurrentTimeSeconds(long div) { public static long getCurrentTimeSeconds(long div) {
long ct = System.currentTimeMillis() / 1000*div; long ct = System.currentTimeMillis() / (1000 * div) * div;
return ct * div; return ct * div;
} }
public static long getCurrentTimeSeconds(){ public static long getCurrentTimeSeconds() {
return getCurrentTimeSeconds(1); return getCurrentTimeSeconds(1);
} }
public SortedSet<Quote> getQuoteHistory(long start) { public SortedSet<Quote> getQuoteHistory(long start) {
Quote s = new Quote(); Quote s = new Quote();
s.time = start; s.time = start*1000;
s.time = 2; s.id = 0;
s.id = 2;
TreeSet<Quote> result = new TreeSet<>(); TreeSet<Quote> result = new TreeSet<>();
result.addAll(this.quoteHistory.tailSet(s)); result.addAll(this.quoteHistory.tailSet(s));
@ -55,7 +54,6 @@ public class Exchange extends Thread {
return this.getQuoteHistory(seconds, last.time); return this.getQuoteHistory(seconds, last.time);
} }
*/ */
// Class to describe an executed order // Class to describe an executed order
// QuoteReceiver has to be implemented by objects that wants // QuoteReceiver has to be implemented by objects that wants
// to receive quote updates // to receive quote updates

View File

@ -40,7 +40,7 @@ public class SwitchingTrader extends RandomTrader{
public SwitchingTrader(Account account, TraderConfig config) { public SwitchingTrader(Account account, TraderConfig config) {
super(account, config); super(account, config);
System.out.print("SWTrader Created\n"); // System.out.print("SWTrader Created\n");
if (account.shares>0) if (account.shares>0)
mode=Action.sell; mode=Action.sell;
@ -53,26 +53,29 @@ public class SwitchingTrader extends RandomTrader{
private void printstartus(){ private void printstartus(){
System.out.print("SWTrader:"); // System.out.print("SWTrader:");
switch (mode){ switch (mode){
case buy: case buy:
System.out.print("buy" /* System.out.print("buy"
+account.shares +account.shares
+" " +" "
+account.money +account.money
); );
*/
break; break;
case sell: case sell:
/*
System.out.print("sell" System.out.print("sell"
+account.shares +account.shares
+" " +" "
+account.money +account.money
); );
*/
break; break;
} }
System.out.print("\n"); // System.out.print("\n");
} }