diff --git a/catalyst/__main__.py b/catalyst/__main__.py index d6ce581a..c006df68 100644 --- a/catalyst/__main__.py +++ b/catalyst/__main__.py @@ -138,7 +138,7 @@ def ipython_only(option): @click.option( '-b', '--bundle', - default='quantopian-quandl', + default='poloniex', metavar='BUNDLE-NAME', show_default=True, help='The data bundle to use for the simulation.', @@ -285,7 +285,7 @@ def catalyst_magic(line, cell=None): @click.option( '-b', '--bundle', - default='quantopian-quandl', + default='poloniex', metavar='BUNDLE-NAME', show_default=True, help='The data bundle to ingest.', @@ -317,7 +317,7 @@ def ingest(bundle, assets_version, show_progress): @click.option( '-b', '--bundle', - default='quantopian-quandl', + default='poloniex', metavar='BUNDLE-NAME', show_default=True, help='The data bundle to clean.', diff --git a/catalyst/data/bundles/poloniex.py b/catalyst/data/bundles/poloniex.py index 77bad0b1..b37999c8 100644 --- a/catalyst/data/bundles/poloniex.py +++ b/catalyst/data/bundles/poloniex.py @@ -99,7 +99,7 @@ def poloniex_cryptoassets(symbols, start=None, end=None): df['date']=pd.to_datetime(df['date'], utc=True, unit='s') df.set_index('date', inplace=True) - df = df.resample('D').mean() + #df = df.resample('D').mean() df = df.loc[df.index.isin(calendar.schedule.index)] # the start date is the date of the first trade and diff --git a/catalyst/data/bundles/quandl.py b/catalyst/data/bundles/quandl.py index 3a423d6c..d9bcbdc2 100644 --- a/catalyst/data/bundles/quandl.py +++ b/catalyst/data/bundles/quandl.py @@ -407,39 +407,3 @@ def quantopian_quandl_bundle(environ, register_calendar_alias("QUANDL", "NYSE") - -CATALYST_URL = ( - 'https://s3.amazonaws.com/quantopian-public-zipline-data/quandl' -) - - -@bundles.register( - 'catalyst', - calendar_name='NYSE', - minutes_per_day=390, - create_writers=False, -) -def catalyst_bundle(environ, - asset_db_writer, - minute_bar_writer, - daily_bar_writer, - adjustment_writer, - calendar, - start_session, - end_session, - cache, - show_progress, - output_dir): - if show_progress: - data = download_with_progress( - CATALYST_URL, - chunk_size=ONE_MEGABYTE, - label="Downloading Bundle: catalyst", - ) - else: - data = download_without_progress(CATALYST_URL) - - with tarfile.open('r', fileobj=data) as tar: - if show_progress: - print("Writing data to %s." % output_dir) - tar.extractall(output_dir) diff --git a/catalyst/examples/buybtc.py b/catalyst/examples/buybtc.py index 21a844ce..7222d369 100644 --- a/catalyst/examples/buybtc.py +++ b/catalyst/examples/buybtc.py @@ -14,7 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from catalyst.api import order, record, symbol +from catalyst.api import ( + order_target_percent, + record, + symbol, + get_open_orders, +) def initialize(context): @@ -22,8 +27,13 @@ def initialize(context): def handle_data(context, data): - order(context.asset, 10) - record(USDT_BTC=data.current(context.asset, 'price')) + if context.asset not in get_open_orders() and data.can_trade(context.asset): + order_target_percent(context.asset, 1.0) + + record( + USDT_BTC=data.current(context.asset, 'price'), + leverage=context.account.leverage, + ) # Note: this function can be removed if running @@ -31,12 +41,15 @@ def handle_data(context, data): def analyze(context=None, results=None): import matplotlib.pyplot as plt # Plot the portfolio and asset data. - ax1 = plt.subplot(211) + ax1 = plt.subplot(311) results.portfolio_value.plot(ax=ax1) ax1.set_ylabel('Portfolio value (USD)') - ax2 = plt.subplot(212, sharex=ax1) + ax2 = plt.subplot(312, sharex=ax1) results.USDT_BTC.plot(ax=ax2) ax2.set_ylabel('USDT_BTC price (USD)') + ax3 = plt.subplot(313, sharex=ax1) + results.leverage.plot(ax=ax3) + ax3.set_ylabel('Leverage (USD)') # Show the plot. plt.gcf().set_size_inches(18, 8) diff --git a/catalyst/examples/momentum_pipeline.py b/catalyst/examples/momentum_pipeline.py index 40cac050..f56b9e9b 100644 --- a/catalyst/examples/momentum_pipeline.py +++ b/catalyst/examples/momentum_pipeline.py @@ -13,7 +13,7 @@ from catalyst.api import ( symbol, ) from catalyst.pipeline import Pipeline -from catalyst.pipeline.factors.equity import RSI +from catalyst.pipeline.factors.crypto import RSI def make_pipeline(): @@ -35,7 +35,10 @@ def rebalance(context, data): longs = all_assets[pipeline_data.longs] shorts = all_assets[pipeline_data.shorts] - record(universe_size=len(all_assets)) + record( + universe_size=len(all_assets), + leverage=context.account.leverage, + ) # Build a 2x-leveraged, equal-weight, long-short portfolio. one_third = 1.0 / 3.0 @@ -67,6 +70,21 @@ def initialize(context): def before_trading_start(context, data): context.pipeline_data = pipeline_output('my_pipeline') +def analyze(context=None, results=None): + import matplotlib.pyplot as plt + + ax1 = plt.subplot(311) + results.portfolio_value.plot(ax=ax1) + ax1.set_ylabel('Portfolio value (USD)') + ax2 = plt.subplot(312, sharex=ax1) + results.universe_size.plot(ax=ax2) + ax2.set_ylabel('Universe Size') + ax3 = plt.subplot(313, sharex=ax1) + results.leverage.plot(ax=ax3) + ax3.set_ylabel('Leverage (USD)') + + plt.gcf().set_size_inches(18, 8) + plt.show() def _test_args(): """ diff --git a/catalyst/utils/run_algo.py b/catalyst/utils/run_algo.py index 696b8245..c58e7835 100644 --- a/catalyst/utils/run_algo.py +++ b/catalyst/utils/run_algo.py @@ -164,7 +164,7 @@ def _run(handle_data, bundle_timestamp, ) - if b == 'catalyst': + if b == 'poloniex': return CryptoPricingLoader( bundle_data.equity_daily_bar_reader, CryptoPricing,