Back-Testing Non-US data with Zipline

I created this post to share how we can use Zipline to back-test non-us data. Zipline is designed by a VC company called Quantopian and they open the source code for retail traders to use for stock back testing. However, it is only support US market data. Fortunately, there are some things we can do to make it works with Non-US data.

I am going to make Zipline works with Thai Stock data because I am a professional investors in Thailand and want Zipline to be my main tools to check my trading strategies whether or not it sounds for Thailand stock market.

I assume that you are familiar with Python and Zipline and how to install packages by using command lines. If not, please check my other posts to see how we can setup Zipline.

Here is the steps:

1) Downloaded data from yahoo into a csv file
2) Implemented the steps to ingest custom data from this link:
3) Ran the ingest comment using the LSE calendar (learn more about LSE calendar on this link)

from zipline.data.bundles import register 
from zipline.data.bundles.viacsv import viacsv 
from zipline.utils.calendars import get_calendar 
from zipline.utils.calendars import exchange_calendar_lse

eqSym = { 
 "CPI", 
}

register( 
 'csv2', # name this whatever you like 
 viacsv(eqSym), 
 calendar_name='LSE', 
)

4) Implemented the following code – and so far – bundle_data.equity_daily_bar_reader.trading_calendar.all_sessions has returned a UK looking calendar

bundle_data = load('csv2', os.environ, None) 
 cal = bundle_data.equity_daily_bar_reader.trading_calendar.all_sessions 
 pipeline_loader = USEquityPricingLoader(bundle_data.equity_daily_bar_reader, bundle_data.adjustment_reader) 
 choose_loader = make_choose_loader(pipeline_loader) 
 env = TradingEnvironment(bm_symbol='^FTSE', 
 exchange_tz='Europe/London',asset_db_path=parse_sqlite_connstr(bundle_data.asset_finder.engine.url))

data = DataPortal( 
 env.asset_finder, get_calendar("LSE"), 
 first_trading_day=bundle_data.equity_minute_bar_reader.first_trading_day, 
 equity_minute_reader=bundle_data.equity_minute_bar_reader, 
 equity_daily_reader=bundle_data.equity_daily_bar_reader, 
 adjustment_reader=bundle_data.adjustment_reader, 
 )

sadfasf

Leave a Reply

Your email address will not be published. Required fields are marked *