...
This commit is contained in:
parent
8017ad5834
commit
af6acdbab1
17
nbactions.xml
Normal file
17
nbactions.xml
Normal 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>
|
2
pom.xml
2
pom.xml
@ -1,7 +1,7 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mycompany</groupId>
|
||||
<groupId>com.cauwersin</groupId>
|
||||
<artifactId>SeSim</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
@ -25,7 +25,6 @@
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import sesim.Exchange.*;
|
||||
import sesim.Order.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -34,10 +34,10 @@ public class CandlestickDemo extends JFrame {
|
||||
|
||||
//Now create the chart and chart panel
|
||||
JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false);
|
||||
ChartPanel chartPanel = new ChartPanel(chart);
|
||||
chartPanel.setPreferredSize(new Dimension(600, 300));
|
||||
// ChartPanel chartPanel = new ChartPanel(chart);
|
||||
// chartPanel.setPreferredSize(new Dimension(600, 300));
|
||||
|
||||
this.add(chartPanel);
|
||||
// this.add(chartPanel);
|
||||
this.pack();
|
||||
}
|
||||
protected AbstractXYDataset getDataSet(String stockSymbol) {
|
||||
|
@ -74,7 +74,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
DateAxis domainAxis = new DateAxis("Date");
|
||||
NumberAxis rangeAxis = new NumberAxis("Price");
|
||||
|
||||
CandlestickRenderer renderer = new CandlestickRenderer();
|
||||
|
||||
XYDataset dataset = getDataSet(stockSymbol);
|
||||
|
||||
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
|
||||
JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false);
|
||||
|
||||
ChartPanel chartPanel = new ChartPanel(chart);
|
||||
|
||||
chartPanel.setPreferredSize(new Dimension(500, 270));
|
||||
@ -129,25 +132,22 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
double high = 0;
|
||||
double low = 0;
|
||||
double close = 0;
|
||||
double volume=0;
|
||||
double volume = 0;
|
||||
|
||||
Iterator<Quote> it = l.iterator();
|
||||
|
||||
Quote q;
|
||||
|
||||
|
||||
if (it.hasNext()) {
|
||||
q = it.next();
|
||||
open = q.price;
|
||||
high = q.price;
|
||||
low = q.price;
|
||||
volume = q.volume;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
q = new Quote();
|
||||
}
|
||||
|
||||
|
||||
while (it.hasNext() && q.time < last) {
|
||||
q = it.next();
|
||||
|
||||
@ -178,13 +178,13 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 60);
|
||||
|
||||
for (long i = (ct - 60)*1000; i < (ct + 10)*1000; i += 10*1000) {
|
||||
OHLCDataItem d = getOhlcData(i, i + 10*1000, h);
|
||||
for (long i = (ct - 60) * 1000; i < (ct + 10) * 1000; i += 10 * 1000) {
|
||||
OHLCDataItem d = getOhlcData(i, i + 10 * 1000, h);
|
||||
data.add(d);
|
||||
}
|
||||
|
||||
System.out.print(data.size() + "\n");
|
||||
// System.exit(0);
|
||||
// System.exit(0);
|
||||
|
||||
return data.toArray(new OHLCDataItem[data.size()]);
|
||||
|
||||
@ -255,8 +255,16 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
@Override
|
||||
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);
|
||||
System.out.print(
|
||||
"SortedSet size:"
|
||||
|
28
src/main/java/gui/ChartPanel.form
Normal file
28
src/main/java/gui/ChartPanel.form
Normal 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>
|
46
src/main/java/gui/ChartPanel.java
Normal file
46
src/main/java/gui/ChartPanel.java
Normal 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
|
||||
}
|
130
src/main/java/gui/DTSCTest.java
Normal file
130
src/main/java/gui/DTSCTest.java
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
@ -97,7 +97,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
|
||||
protected class OrderBookListModel extends AbstractTableModel {
|
||||
|
||||
private ArrayList list;
|
||||
private boolean desc = false;
|
||||
//private final boolean desc = false;
|
||||
|
||||
public OrderBookListModel() {
|
||||
// System.out.print("CREATING A NEW MODEL\n");
|
||||
|
@ -106,9 +106,46 @@ public class test {
|
||||
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[]) {
|
||||
NoProblem p = new NoProblem();
|
||||
p.run();
|
||||
// NoProblem p = new NoProblem();
|
||||
// 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)
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -39,25 +39,26 @@ public abstract class AutoTrader extends Trader implements Runnable {
|
||||
|
||||
protected void doSleep(int seconds) {
|
||||
try {
|
||||
sleep(seconds*1000);
|
||||
sleep(seconds * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void start(){
|
||||
public void start() {
|
||||
System.out.print("Starting AutoTrader\n");
|
||||
class Runner extends Thread{
|
||||
class Runner extends Thread {
|
||||
|
||||
AutoTrader trader;
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
public void run() {
|
||||
trader.run();
|
||||
}
|
||||
}
|
||||
Runner r = new Runner();
|
||||
r.trader=this;
|
||||
r.trader = this;
|
||||
r.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,20 +28,19 @@ public class Exchange extends Thread {
|
||||
}
|
||||
|
||||
public static long getCurrentTimeSeconds(long div) {
|
||||
long ct = System.currentTimeMillis() / 1000*div;
|
||||
long ct = System.currentTimeMillis() / (1000 * div) * div;
|
||||
return ct * div;
|
||||
}
|
||||
|
||||
public static long getCurrentTimeSeconds(){
|
||||
public static long getCurrentTimeSeconds() {
|
||||
return getCurrentTimeSeconds(1);
|
||||
}
|
||||
|
||||
public SortedSet<Quote> getQuoteHistory(long start) {
|
||||
|
||||
Quote s = new Quote();
|
||||
s.time = start;
|
||||
s.time = 2;
|
||||
s.id = 2;
|
||||
s.time = start*1000;
|
||||
s.id = 0;
|
||||
|
||||
TreeSet<Quote> result = new TreeSet<>();
|
||||
result.addAll(this.quoteHistory.tailSet(s));
|
||||
@ -50,12 +49,11 @@ public class Exchange extends Thread {
|
||||
|
||||
}
|
||||
|
||||
/* public SortedSet<Quote> getQuoteHistory(int seconds) {
|
||||
/* public SortedSet<Quote> getQuoteHistory(int seconds) {
|
||||
Quote last = quoteHistory.last();
|
||||
return this.getQuoteHistory(seconds, last.time);
|
||||
}
|
||||
*/
|
||||
|
||||
*/
|
||||
// Class to describe an executed order
|
||||
// QuoteReceiver has to be implemented by objects that wants
|
||||
// to receive quote updates
|
||||
|
@ -40,7 +40,7 @@ public class SwitchingTrader extends RandomTrader{
|
||||
public SwitchingTrader(Account account, TraderConfig config) {
|
||||
|
||||
super(account, config);
|
||||
System.out.print("SWTrader Created\n");
|
||||
// System.out.print("SWTrader Created\n");
|
||||
|
||||
if (account.shares>0)
|
||||
mode=Action.sell;
|
||||
@ -53,26 +53,29 @@ public class SwitchingTrader extends RandomTrader{
|
||||
|
||||
private void printstartus(){
|
||||
|
||||
System.out.print("SWTrader:");
|
||||
// System.out.print("SWTrader:");
|
||||
switch (mode){
|
||||
case buy:
|
||||
System.out.print("buy"
|
||||
/* System.out.print("buy"
|
||||
+account.shares
|
||||
+" "
|
||||
+account.money
|
||||
);
|
||||
*/
|
||||
break;
|
||||
case sell:
|
||||
/*
|
||||
System.out.print("sell"
|
||||
+account.shares
|
||||
+" "
|
||||
+account.money
|
||||
);
|
||||
*/
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
System.out.print("\n");
|
||||
// System.out.print("\n");
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user