Comment définir une base de données de cotations boursières?
Bonjour,
Je souhaiterai des conseilles pour m'aider à définir une base de données de cotations boursières.
Je pense utiliser ce moteur de base de données.
http://www.h2database.com
Comment organiser ma BD ?
Faut-il que je crée une table par symbole boursier ?
Faut-il que je crée une seule table pour tous les symboles boursier, mais en ajoutant un indicateur pour identifier les symboles ?
En fait il peut y avoir plusieurs time-frame pour un même symbole.
Time-frame horaire, journalier, mensuel etc.
Voici comment sont stockées les données en mémoire.
La class PriceBar stocke un enregistrement.
La class Quotes stocke une liste d'enregistrements.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| package jopencomponents.symbol;
import org.joda.time.DateTime;
/**
* Encapsulates the price bar information.
*/
public class PriceBar {
private long date;
private double open, high, low, close;
private long volume;
/**
* This constructor is used to create a new historical bar
*/
public PriceBar(long date, double open, double high, double low, double close, long volume) {
this.date = date;
this.open = open;
this.high = high;
this.low = low;
this.close = close;
this.volume = volume;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(" date: ").append(getShortDate());
sb.append(" open: ").append(open);
sb.append(" high: ").append(high);
sb.append(" low: ").append(low);
sb.append(" close: ").append(close);
sb.append(" volume: ").append(volume);
return sb.toString();
}
public String getShortDate() {
DateTime dateTime = new DateTime(date);
return dateTime.toString("dd MMMMM yyyy");
}
public double getOpen() {
return open;
}
public double getHigh() {
return high;
}
public double getLow() {
return low;
}
public double getClose() {
return close;
}
public double getMidpoint() {
return (low + high) / 2;
}
public void setOpen(double open) {
this.open = open;
}
public void setHigh(double high) {
this.high = high;
}
public void setLow(double low) {
this.low = low;
}
public void setClose(double close) {
this.close = close;
}
public void setDate(long date) {
this.date = date;
}
public void setVolume(long volume) {
this.volume = volume;
}
public long getVolume() {
return volume;
}
public DateTime getDateTime() {
DateTime dateTime = new DateTime(date);
return dateTime;
}
public long getDate() {
return date;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import jopencomponents.startup.Params;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;
/**
* Holds and validates quotes.
*/
public abstract class Quotes {
final static Logger log = Logger.getLogger(Quotes.class);
private static final String lineSep = System.getProperty("line.separator");
private final List<PriceBar> priceBars = new ArrayList<PriceBar>();
private final BarSize barSize;
private PriceBar nextBar;
private PrintWriter writer;
public Quotes(BarSize barSize) {
this.barSize = barSize;
}
etc. |