程序员的量化交易之路(19)--Cointrader之Bar实体(7)

来源:互联网 发布:雅可比矩阵机器人 编辑:程序博客网 时间:2024/04/28 08:20

转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrader.top

1. 代码

package org.cryptocoinpartners.schema;import org.joda.time.format.DateTimeFormat;import org.joda.time.format.DateTimeFormatter;public class Bar extends Event {private long timestamp;//时间戳private Double open;//开盘价private Double close;//收盘价private Double high;//最高价private Double low;//最低价private Market market;//市场private static final DateTimeFormatter FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");// private static final SimpleDateFormat FORMAT = new SimpleDateFormat("dd.MM.yyyy kk:mm:ss");private static final String SEPARATOR = ",";public Bar(long timestamp, Double open, Double close, Double high, Double low, Market market) {this.timestamp = timestamp;this.open = open;this.close = close;this.high = high;this.low = low;this.market = market;}@Overridepublic long getTimestamp() {return timestamp;}public Double getOpen() {return open;}public Double getClose() {return close;}public Double getHigh() {return high;}public Double getLow() {return low;}public Market getMarket() {return market;}protected void setTimestamp(long timestamp) {this.timestamp = timestamp;}protected void setOpen(Double open) {this.open = open;}protected void setHigh(Double high) {this.high = high;}protected void setLow(Double low) {this.low = low;}protected void setClose(Double close) {this.close = close;}protected void setMarket(Market market) {this.market = market;}@Overridepublic String toString() {return "Bar Start=" + (getTimestamp() != 0 ? (FORMAT.print(getTimestamp())) : "") + SEPARATOR + "Market=" + getMarket() + SEPARATOR + "Open="+ getOpen() + SEPARATOR + "High=" + getHigh() + SEPARATOR + "Low=" + getLow() + SEPARATOR + "Close=" + getClose();}}


这个Bar就是条。就是我们K线图中的一根K线。它包含时间以及该时间点上的OCHL值。

这里有个Market,我们在后面的节中会说明。


我们的每一节都很简单,但就是一节节简单的内容最后走下来就组成了一个复杂的量化交易平台。

路遥知马力。




0 0