码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-06-04 06:13:32      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:cointrader   esper   量化交易   bar   

转载需注明出处: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,我们在后面的节中会说明。


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

路遥知马力。




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

标签:cointrader   esper   量化交易   bar   

原文地址:http://blog.csdn.net/minimicall/article/details/46354411

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!