def zipline_magic(line, cell=None): """The zipline IPython cell magic. """ load_extensions( default=True, extensions=[], strict=True, environ=os.environ, ) try: return run.main( # put our overrides at the start of the parameter list so that # users may pass values with higher precedence [ '--algotext', cell, '--output', os.devnull, # don't write the results by default ] + ([ # these options are set when running in line magic mode # set a non None algo text to use the ipython user_ns '--algotext', '', '--local-namespace', ] if cell is None else []) + line.split(), '%s%%zipline' % ((cell or '') and '%'), # don't use system exit and propogate errors to the caller standalone_mode=False, ) except SystemExit as e: # https://github.com/mitsuhiko/click/pull/533 # even in standalone_mode=False `--help` really wants to kill us ;_; if e.code: raise ValueError('main returned non-zero status code: %d' % e.code)
def main(extension, strict_extensions, default_extension): """Top level zipline entry point. """ # install a logbook handler before performing any other operations logbook.StderrHandler().push_application() load_extensions( default_extension, extension, strict_extensions, os.environ, )
def main(ctx, extension, strict_extensions, default_extension, x): """Top level zipline entry point. """ # install a logbook handler before performing any other operations logbook.StderrHandler().push_application() create_args(x, zipline.extension_args) load_extensions( default_extension, extension, strict_extensions, os.environ, )
def zipline_magic(line, cell=None): """The zipline IPython cell magic.""" load_extensions( default=True, extensions=[], strict=True, environ=os.environ, ) try: return run.main( # put our overrides at the start of the parameter list so that # users may pass values with higher precedence [ "--algotext", cell, "--output", os.devnull, # don't write the results by default ] + ( [ # these options are set when running in line magic mode # set a non None algo text to use the ipython user_ns "--algotext", "", "--local-namespace", ] if cell is None else [] ) + line.split(), "%s%%zipline" % ((cell or "") and "%"), # don't use system exit and propogate errors to the caller standalone_mode=False, ) except SystemExit as e: # https://github.com/mitsuhiko/click/pull/533 # even in standalone_mode=False `--help` really wants to kill us ;_; if e.code: raise ValueError("main returned non-zero status code: %d" % e.code)
from zipline_extensions_cn.data.data_portal import CNDataPortal from zipline_extensions_cn.pipeline.data import CNEquityPricing, CNFinancialData from zipline.pipeline.engine import SimplePipelineEngine from zipline_extensions_cn.pipeline.loaders import CNEquityPricingLoader, FundamentalsLoader from zipline.utils.calendars import get_calendar from zipline.assets._assets import Equity from zipline.utils.run_algo import load_extensions import alphalens as al import zipline.pipeline.domain as domain _DEFAULT_DOMAINS = {d.calendar_name: d for d in domain.BUILT_IN_DOMAINS} # Load extensions.py; this allows you access to custom bundles load_extensions( default=True, extensions=[], strict=True, environ=os.environ, ) # Set-Up Pricing Data Access trading_calendar = get_calendar('AShare') bundle = 'mydb' bundle_data = bundles.load(bundle) loaders = {} # create and empty BlazeLoader # blaze_loader = BlazeLoader() def my_dispatcher(column):
from pyfolio.plotting import plot_rolling_returns, plot_rolling_sharpe from pyfolio.timeseries import forecast_cone_bootstrap # In[3]: sns.set_style('whitegrid') pd.set_option('display.expand_frame_repr', False) np.random.seed(42) # ### Load zipline extensions # Only need this in notebook to find bundle. # In[4]: load_extensions(default=True, extensions=[], strict=True, environ=None) # In[5]: log_handler = StderrHandler( format_string='[{record.time:%Y-%m-%d %H:%M:%S.%f}]: ' + '{record.level_name}: {record.func_name}: {record.message}', level=INFO) log_handler.push_application() log = Logger('Algorithm') # ## Algo Params # We plan to hold up to 20 long and 20 short positions whenever there are at least 10 on either side that meet the criteria (positive/negative prediction for long/short position). # In[6]: