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

简介:

转载需注明出处:http://blog.csdn.net/minimicallhttp://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;
	}

	@Override
	public 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;
	}

	@Override
	public 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,我们在后面的节中会说明。


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

路遥知马力。




相关文章
|
JavaScript 前端开发 监控
WebComponent魔法堂:深究Custom Element 之 面向痛点编程
 最近加入到新项目组负责前端技术预研和选型,一直偏向于以Polymer为代表的WebComponent技术线,于是查阅各类资料想说服老大向这方面靠,最后得到的结果是:"资料99%是英语无所谓,最重要是UI/UX上符合要求,技术的事你说了算。",于是我只好乖乖地去学UI/UX设计的事,木有设计师撑腰的
2324 0