user9098929
user9098929

Reputation:

How to Execute Zipline in Pycharm for Debugging

I am a beginner with Python and would like to understand whether zipline is the right backtesting framework for me.

I can understand other peoples code best while debugging and looking in variable contents at certain points. For doing this, I like Pycharms debugging possibilities most.

From the zipline manual I understood, that zipline can either be executed from the OS command line:

zipline run -f ../../zipline/examples/buyapple.py --start 2000-1-1 --end 2014-1-1 -o buyapple_out.pickle

or via IPython:

The IPython Notebook is a very powerful browser-based interface to a Python interpreter (this tutorial was written in it). As it is already the de-facto interface for most quantitative researchers zipline provides an easy way to run your algorithm inside the Notebook without requiring you to use the CLI.

Is there any way that I could work with zipline and Pycharm, so that I can also debug the zipline code itself (or at least my own code)?

After installing it with pip, I find the following entry point in my file system:

file /home/user/anaconda3/bin/zipline

#!/home/user/anaconda3/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from zipline.__main__ import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main()) 

But is it wise to try to access zipline this way? Or is it better to clone the git repository and call zipline that way? And how should a wrapper look like that passes the parameter to zipline?

Upvotes: 1

Views: 779

Answers (1)

ShlomiK
ShlomiK

Reputation: 73

you can run zipline inside pycharm or any IDE by using the run_algorithm method. something like this:

from datetime import datetime
import pandas as pd
from zipline import run_algorithm

start = pd.Timestamp(datetime(2018, 1, 1, tzinfo=pytz.UTC))
end = pd.Timestamp(datetime(2018, 7, 25, tzinfo=pytz.UTC))

run_algorithm(start=start,
              end=end,
              initialize=initialize,
              capital_base=100000,
              handle_data=handle_data,
              before_trading_start=before_trading_start,
              data_frequency='daily')

I am using these packages:

pandas==0.18.1
pandas-datareader==0.6.0
zipline-live==1.1.0.5
numpy==1.15.0
matplotlib==2.2.2

and python27

Upvotes: 2

Related Questions