mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-13 12:00:16 +08:00
BLD: testing each sample algo and fixing an issue with data.history
This commit is contained in:
@@ -61,7 +61,6 @@ def handle_data(context, data):
|
|||||||
context.asset,
|
context.asset,
|
||||||
target_hodl_value,
|
target_hodl_value,
|
||||||
limit_price=price * 1.1,
|
limit_price=price * 1.1,
|
||||||
stop_price=price * 0.9,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
record(
|
record(
|
||||||
|
|||||||
@@ -21,8 +21,9 @@
|
|||||||
To see which assets are available on each exchange, visit:
|
To see which assets are available on each exchange, visit:
|
||||||
https://www.enigma.co/catalyst/status
|
https://www.enigma.co/catalyst/status
|
||||||
'''
|
'''
|
||||||
|
from catalyst import run_algorithm
|
||||||
from catalyst.api import order, record, symbol
|
from catalyst.api import order, record, symbol
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
def initialize(context):
|
def initialize(context):
|
||||||
@@ -32,3 +33,17 @@ def initialize(context):
|
|||||||
def handle_data(context, data):
|
def handle_data(context, data):
|
||||||
order(context.asset, 1)
|
order(context.asset, 1)
|
||||||
record(btc=data.current(context.asset, 'price'))
|
record(btc=data.current(context.asset, 'price'))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run_algorithm(
|
||||||
|
capital_base=10000,
|
||||||
|
data_frequency='daily',
|
||||||
|
initialize=initialize,
|
||||||
|
handle_data=handle_data,
|
||||||
|
exchange_name='bitfinex',
|
||||||
|
algo_namespace='buy_and_hodl',
|
||||||
|
base_currency='usd',
|
||||||
|
start=pd.to_datetime('2015-03-01', utc=True),
|
||||||
|
end=pd.to_datetime('2017-10-31', utc=True),
|
||||||
|
)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ instructions on how to install the required dependencies.
|
|||||||
import talib
|
import talib
|
||||||
from logbook import Logger
|
from logbook import Logger
|
||||||
|
|
||||||
|
from catalyst import run_algorithm
|
||||||
from catalyst.api import (
|
from catalyst.api import (
|
||||||
order,
|
order,
|
||||||
order_target_percent,
|
order_target_percent,
|
||||||
@@ -21,6 +22,7 @@ from catalyst.api import (
|
|||||||
get_open_orders,
|
get_open_orders,
|
||||||
)
|
)
|
||||||
from catalyst.exchange.stats_utils import get_pretty_stats
|
from catalyst.exchange.stats_utils import get_pretty_stats
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
algo_namespace = 'buy_low_sell_high_xrp'
|
algo_namespace = 'buy_low_sell_high_xrp'
|
||||||
log = Logger(algo_namespace)
|
log = Logger(algo_namespace)
|
||||||
@@ -101,8 +103,8 @@ def _handle_data(context, data):
|
|||||||
|
|
||||||
if price < cost_basis:
|
if price < cost_basis:
|
||||||
is_buy = True
|
is_buy = True
|
||||||
elif(position.amount > 0
|
elif (position.amount > 0
|
||||||
and price > cost_basis * (1 + context.PROFIT_TARGET)):
|
and price > cost_basis * (1 + context.PROFIT_TARGET)):
|
||||||
profit = (price * position.amount) - (cost_basis * position.amount)
|
profit = (price * position.amount) - (cost_basis * position.amount)
|
||||||
log.info('closing position, taking profit: {}'.format(profit))
|
log.info('closing position, taking profit: {}'.format(profit))
|
||||||
order_target_percent(
|
order_target_percent(
|
||||||
@@ -157,3 +159,18 @@ def handle_data(context, data):
|
|||||||
def analyze(context, stats):
|
def analyze(context, stats):
|
||||||
log.info('the daily stats:\n{}'.format(get_pretty_stats(stats)))
|
log.info('the daily stats:\n{}'.format(get_pretty_stats(stats)))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run_algorithm(
|
||||||
|
capital_base=10000,
|
||||||
|
data_frequency='daily',
|
||||||
|
initialize=initialize,
|
||||||
|
handle_data=handle_data,
|
||||||
|
analyze=analyze,
|
||||||
|
exchange_name='poloniex',
|
||||||
|
algo_namespace='buy_and_hodl',
|
||||||
|
base_currency='usd',
|
||||||
|
start=pd.to_datetime('2015-03-01', utc=True),
|
||||||
|
end=pd.to_datetime('2017-10-31', utc=True),
|
||||||
|
)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ def _handle_data(context, data):
|
|||||||
context.asset,
|
context.asset,
|
||||||
fields='price',
|
fields='price',
|
||||||
bar_count=20,
|
bar_count=20,
|
||||||
frequency='1d'
|
frequency='1D'
|
||||||
)
|
)
|
||||||
rsi = talib.RSI(prices.values, timeperiod=14)[-1]
|
rsi = talib.RSI(prices.values, timeperiod=14)[-1]
|
||||||
log.info('got rsi: {}'.format(rsi))
|
log.info('got rsi: {}'.format(rsi))
|
||||||
@@ -88,8 +88,8 @@ def _handle_data(context, data):
|
|||||||
|
|
||||||
if price < cost_basis:
|
if price < cost_basis:
|
||||||
is_buy = True
|
is_buy = True
|
||||||
elif(position.amount > 0
|
elif (position.amount > 0
|
||||||
and price > cost_basis * (1 + context.PROFIT_TARGET)):
|
and price > cost_basis * (1 + context.PROFIT_TARGET)):
|
||||||
profit = (price * position.amount) - (cost_basis * position.amount)
|
profit = (price * position.amount) - (cost_basis * position.amount)
|
||||||
log.info('closing position, taking profit: {}'.format(profit))
|
log.info('closing position, taking profit: {}'.format(profit))
|
||||||
order_target_percent(
|
order_target_percent(
|
||||||
@@ -146,23 +146,15 @@ def analyze(context, stats):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
run_algorithm(
|
if __name__ == '__main__':
|
||||||
capital_base=100000,
|
run_algorithm(
|
||||||
initialize=initialize,
|
capital_base=0.001,
|
||||||
handle_data=handle_data,
|
initialize=initialize,
|
||||||
analyze=analyze,
|
handle_data=handle_data,
|
||||||
exchange_name='poloniex',
|
analyze=analyze,
|
||||||
start=pd.to_datetime('2017-5-01', utc=True),
|
exchange_name='bittrex',
|
||||||
end=pd.to_datetime('2017-10-16', utc=True),
|
live=True,
|
||||||
base_currency='usdt',
|
algo_namespace=algo_namespace,
|
||||||
data_frequency='daily'
|
base_currency='btc',
|
||||||
)
|
simulate_orders=True,
|
||||||
# run_algorithm(
|
)
|
||||||
# initialize=initialize,
|
|
||||||
# handle_data=handle_data,
|
|
||||||
# analyze=analyze,
|
|
||||||
# exchange_name='poloniex',
|
|
||||||
# live=True,
|
|
||||||
# algo_namespace=algo_namespace,
|
|
||||||
# base_currency='btc'
|
|
||||||
# )
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ run_algorithm(
|
|||||||
initialize=initialize,
|
initialize=initialize,
|
||||||
handle_data=handle_data,
|
handle_data=handle_data,
|
||||||
analyze=None,
|
analyze=None,
|
||||||
exchange_name='gdax',
|
exchange_name='poloniex',
|
||||||
live=True,
|
live=True,
|
||||||
algo_namespace='simple_loop',
|
algo_namespace='simple_loop',
|
||||||
base_currency='eth',
|
base_currency='eth',
|
||||||
|
|||||||
@@ -238,12 +238,6 @@ class DataPortalExchangeLive(DataPortalExchangeBase):
|
|||||||
"""
|
"""
|
||||||
exchange = self.exchanges[exchange_name]
|
exchange = self.exchanges[exchange_name]
|
||||||
|
|
||||||
if end_dt >= pd.Timestamp.utcnow().floor('1T'):
|
|
||||||
is_current = True
|
|
||||||
|
|
||||||
else:
|
|
||||||
is_current = False
|
|
||||||
|
|
||||||
df = exchange.get_history_window(
|
df = exchange.get_history_window(
|
||||||
assets,
|
assets,
|
||||||
end_dt,
|
end_dt,
|
||||||
@@ -251,7 +245,7 @@ class DataPortalExchangeLive(DataPortalExchangeBase):
|
|||||||
frequency,
|
frequency,
|
||||||
field,
|
field,
|
||||||
data_frequency,
|
data_frequency,
|
||||||
is_current)
|
False)
|
||||||
return df
|
return df
|
||||||
|
|
||||||
def get_exchange_spot_value(self, exchange_name, assets, field, dt,
|
def get_exchange_spot_value(self, exchange_name, assets, field, dt,
|
||||||
|
|||||||
Reference in New Issue
Block a user