How to write your own Historical MarketDataFeed
_____________________________________________________________________________
Write your own historical marketDataFeed for backtesting purpose is quite easy and requires a common knowlede of java language.
We want to introduce you with the example provided on GitHub repository:
WHAT TO DO ( Steps ):
1) Identify your data source
It can be an online website, a CSV file, a TXT file, etc...
2) Write your own code to access the data source
3) Write your own code to map your data source data with MarketDataEventTypes: CandleEvent or TickEvent (in according with your data source).
4) Put it all togheter
5) Write a Skel strategy to test your customMarketDataFeed
See the Strategy on GitHub.
6) Feel free to share it with us
Here is the example of a customMarketDataFeed:
[...]
public class MyCustomMarketDataFeed extends BacktestMarketDataFeedBase implements IMarketDataFeed{
protected final static Logger log = Logger.getLogger(MyCustomMarketDataFeed.class);
private BufferedReader input;
private boolean skipFirstLine = true;
public MyCustomMarketDataFeed(){
this.setMarketDataEvent(MarketDataEventType.CANDLE_EVENT);
}
/*
* (non-Javadoc)
* @see com.tbg.core.model.marketDataFeed.BacktestMarketDataFeedBase#onSubscribeMarketData(com.tbg.core.model.Security)
*/
@Override
public void onSubscribeMarketData(Security security) {
downloadQuotes(security);
}
/**
* Downloads Quotes
* @param security
*/
private void downloadQuotes(Security security){
// Put here your code to access your Data Source
// -> Get the historical data for the given security
// define an empty list of events (in this examples candles)
ArrayList<CandleEvent> candles = new ArrayList<CandleEvent>();
// for each dataRow map the MarketEventType
CandleEvent candleEvent = new CandleEvent();
candleEvent.setSymbol(security.getSymbol().toString());
candleEvent.setOpenPrice(OPEN);
candleEvent.setHighPrice(HIGH);
candleEvent.setLowPrice(LOW);
candleEvent.setClosePrice(CLOSE);
candleEvent.setTimeStamp(TIMESTAMP);
candleEvent.setVolume(VOLUME);
if (debug) log.info(" ====> Csv Candle: "+candleEvent.toString());
// add the single CandleEvent to the candle list
candles.add(candleEvent);
// end of for each row
// Finally
candleEvents.put(security, candles);
}
@Override
public void connectToMarketFeed() {
log.info("Connected to YahooMarketDataFeed.");
}
@Override
public void disconnectFromMarketDataFeed() {
log.info("Connection to YahooMarketDataFeed closed.");
}
}
We are looking for someone who wants to implement the Quandl MarketDataFeed ( www.quandl.com ). Other historical data sources are welcomed, expecially for Indian or Asian markets.
Thank you
:-)