mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-09 15:51:38 +08:00
Working crypto data on NYSE calendar
This commit is contained in:
@@ -289,7 +289,7 @@ class TradingAlgorithm(object):
|
||||
# If a schedule has been provided, pop it. Otherwise, use NYSE.
|
||||
self.trading_calendar = kwargs.pop(
|
||||
'trading_calendar',
|
||||
get_calendar('OPEN')
|
||||
get_calendar('NYSE')
|
||||
)
|
||||
|
||||
self.sim_params = kwargs.pop('sim_params', None)
|
||||
@@ -1115,7 +1115,7 @@ class TradingAlgorithm(object):
|
||||
if calendar is None:
|
||||
cal = self.trading_calendar
|
||||
elif calendar is calendars.CRYPTO_ASSETS:
|
||||
cal = get_calendar('OPEN')
|
||||
cal = get_calendar('NYSE')
|
||||
elif calendar is calendars.US_EQUITIES:
|
||||
cal = get_calendar('NYSE')
|
||||
elif calendar is calendars.US_FUTURES:
|
||||
|
||||
@@ -100,14 +100,7 @@ def poloniex_cryptoassets(symbols, start=None, end=None):
|
||||
df.set_index('date', inplace=True)
|
||||
|
||||
df = df.resample('D').mean()
|
||||
|
||||
# ToDo: we assume that the source is always up to date and complete, otherwise fetch
|
||||
if(pd.to_datetime(start).tz_convert(None) < df.index[0]): df_start = df.index[0]
|
||||
else: df_start = pd.to_datetime(start).tz_convert(None)
|
||||
if(pd.to_datetime(end).tz_convert(None) > df.index[-1]): df_end = df.index[-1]
|
||||
else: df_end = pd.to_datetime(end).tz_convert(None)
|
||||
|
||||
df = df.loc[ df_start : df_end ]
|
||||
df = df.loc[df.index.isin(calendar.schedule.index)]
|
||||
|
||||
# the start date is the date of the first trade and
|
||||
# the end date is the date of the last trade
|
||||
@@ -164,12 +157,14 @@ def poloniex_cryptoassets(symbols, start=None, end=None):
|
||||
|
||||
symbol_map = pd.Series(metadata.symbol.index, metadata.symbol)
|
||||
|
||||
# Hardcode the exchange to "POLONIEX" for all assets and (elsewhere)
|
||||
# Hardcode the exchange to "POLO" for all assets and (elsewhere)
|
||||
# register "YAHOO" to resolve to the OPEN calendar, because these are
|
||||
# all cryptoassets and thus use the OPEN calendar.
|
||||
metadata['exchange'] = 'POLO'
|
||||
asset_db_writer.write(equities=metadata)
|
||||
|
||||
adjustment_writer.write()
|
||||
|
||||
return ingest
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2014 Quantopian, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from catalyst.api import order, record, symbol
|
||||
|
||||
|
||||
def initialize(context):
|
||||
context.asset = symbol('USDT_BTC')
|
||||
|
||||
|
||||
def handle_data(context, data):
|
||||
order(context.asset, 10)
|
||||
record(USDT_BTC=data.current(context.asset, 'price'))
|
||||
|
||||
|
||||
# Note: this function can be removed if running
|
||||
# this algorithm on quantopian.com
|
||||
def analyze(context=None, results=None):
|
||||
import matplotlib.pyplot as plt
|
||||
# Plot the portfolio and asset data.
|
||||
ax1 = plt.subplot(211)
|
||||
results.portfolio_value.plot(ax=ax1)
|
||||
ax1.set_ylabel('Portfolio value (USD)')
|
||||
ax2 = plt.subplot(212, sharex=ax1)
|
||||
results.USDT_BTC.plot(ax=ax2)
|
||||
ax2.set_ylabel('USDT_BTC price (USD)')
|
||||
|
||||
# Show the plot.
|
||||
plt.gcf().set_size_inches(18, 8)
|
||||
plt.show()
|
||||
|
||||
|
||||
def _test_args():
|
||||
"""Extra arguments to use when catalyst's automated tests run this example.
|
||||
"""
|
||||
import pandas as pd
|
||||
|
||||
return {
|
||||
'start': pd.Timestamp('2014-01-01', tz='utc'),
|
||||
'end': pd.Timestamp('2014-11-01', tz='utc'),
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class CryptoPricingLoader(PipelineLoader):
|
||||
self.raw_price_loader = raw_price_loader
|
||||
self._columns = dataset.columns
|
||||
|
||||
cal = get_calendar('OPEN')
|
||||
cal = get_calendar('NYSE')
|
||||
|
||||
self._all_sessions = cal.all_sessions
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ def _run(handle_data,
|
||||
bundle_data.equity_minute_bar_reader.first_trading_day
|
||||
data = DataPortal(
|
||||
env.asset_finder,
|
||||
get_calendar('OPEN'),
|
||||
get_calendar('NYSE'),
|
||||
first_trading_day=first_trading_day,
|
||||
equity_minute_reader=bundle_data.equity_minute_bar_reader,
|
||||
equity_daily_reader=bundle_data.equity_daily_bar_reader,
|
||||
|
||||
Reference in New Issue
Block a user