BLD: testing each sample algo and fixing an issue with data.history

This commit is contained in:
Frederic Fortier
2017-12-12 14:43:06 -05:00
parent 7091546b2b
commit ddf0c480a0
6 changed files with 52 additions and 35 deletions
-1
View File
@@ -61,7 +61,6 @@ def handle_data(context, data):
context.asset,
target_hodl_value,
limit_price=price * 1.1,
stop_price=price * 0.9,
)
record(
+16 -1
View File
@@ -21,8 +21,9 @@
To see which assets are available on each exchange, visit:
https://www.enigma.co/catalyst/status
'''
from catalyst import run_algorithm
from catalyst.api import order, record, symbol
import pandas as pd
def initialize(context):
@@ -32,3 +33,17 @@ def initialize(context):
def handle_data(context, data):
order(context.asset, 1)
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),
)
+19 -2
View File
@@ -13,6 +13,7 @@ instructions on how to install the required dependencies.
import talib
from logbook import Logger
from catalyst import run_algorithm
from catalyst.api import (
order,
order_target_percent,
@@ -21,6 +22,7 @@ from catalyst.api import (
get_open_orders,
)
from catalyst.exchange.stats_utils import get_pretty_stats
import pandas as pd
algo_namespace = 'buy_low_sell_high_xrp'
log = Logger(algo_namespace)
@@ -101,8 +103,8 @@ def _handle_data(context, data):
if price < cost_basis:
is_buy = True
elif(position.amount > 0
and price > cost_basis * (1 + context.PROFIT_TARGET)):
elif (position.amount > 0
and price > cost_basis * (1 + context.PROFIT_TARGET)):
profit = (price * position.amount) - (cost_basis * position.amount)
log.info('closing position, taking profit: {}'.format(profit))
order_target_percent(
@@ -157,3 +159,18 @@ def handle_data(context, data):
def analyze(context, stats):
log.info('the daily stats:\n{}'.format(get_pretty_stats(stats)))
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),
)
+15 -23
View File
@@ -41,7 +41,7 @@ def _handle_data(context, data):
context.asset,
fields='price',
bar_count=20,
frequency='1d'
frequency='1D'
)
rsi = talib.RSI(prices.values, timeperiod=14)[-1]
log.info('got rsi: {}'.format(rsi))
@@ -88,8 +88,8 @@ def _handle_data(context, data):
if price < cost_basis:
is_buy = True
elif(position.amount > 0
and price > cost_basis * (1 + context.PROFIT_TARGET)):
elif (position.amount > 0
and price > cost_basis * (1 + context.PROFIT_TARGET)):
profit = (price * position.amount) - (cost_basis * position.amount)
log.info('closing position, taking profit: {}'.format(profit))
order_target_percent(
@@ -146,23 +146,15 @@ def analyze(context, stats):
pass
run_algorithm(
capital_base=100000,
initialize=initialize,
handle_data=handle_data,
analyze=analyze,
exchange_name='poloniex',
start=pd.to_datetime('2017-5-01', utc=True),
end=pd.to_datetime('2017-10-16', utc=True),
base_currency='usdt',
data_frequency='daily'
)
# run_algorithm(
# initialize=initialize,
# handle_data=handle_data,
# analyze=analyze,
# exchange_name='poloniex',
# live=True,
# algo_namespace=algo_namespace,
# base_currency='btc'
# )
if __name__ == '__main__':
run_algorithm(
capital_base=0.001,
initialize=initialize,
handle_data=handle_data,
analyze=analyze,
exchange_name='bittrex',
live=True,
algo_namespace=algo_namespace,
base_currency='btc',
simulate_orders=True,
)
+1 -1
View File
@@ -127,7 +127,7 @@ run_algorithm(
initialize=initialize,
handle_data=handle_data,
analyze=None,
exchange_name='gdax',
exchange_name='poloniex',
live=True,
algo_namespace='simple_loop',
base_currency='eth',
+1 -7
View File
@@ -238,12 +238,6 @@ class DataPortalExchangeLive(DataPortalExchangeBase):
"""
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(
assets,
end_dt,
@@ -251,7 +245,7 @@ class DataPortalExchangeLive(DataPortalExchangeBase):
frequency,
field,
data_frequency,
is_current)
False)
return df
def get_exchange_spot_value(self, exchange_name, assets, field, dt,