mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-11 21:40:56 +08:00
BLD: tested issue #111
This commit is contained in:
@@ -196,6 +196,9 @@ def prepare_stats(stats, recorded_cols=list()):
|
||||
if recorded_cols is not None:
|
||||
for column in recorded_cols[:]:
|
||||
value = row_data[column]
|
||||
if isinstance(value, pd.Series):
|
||||
value = value.to_dict()
|
||||
|
||||
if type(value) is dict:
|
||||
for asset in value:
|
||||
if not isinstance(asset, TradingPair):
|
||||
|
||||
@@ -2,33 +2,51 @@ from catalyst import run_algorithm
|
||||
from catalyst.api import order, record, symbol
|
||||
import pandas as pd
|
||||
|
||||
from catalyst.exchange.utils.stats_utils import get_pretty_stats
|
||||
|
||||
|
||||
def initialize(context):
|
||||
context.asset = symbol('btc_usdt')
|
||||
context.assets = [symbol('eth_btc'), symbol('eth_usdt')]
|
||||
|
||||
|
||||
def handle_data(context, data):
|
||||
order(context.asset, 1)
|
||||
order(context.assets[0], 1)
|
||||
|
||||
price = data.current(context.asset, 'price')
|
||||
record(btc=price)
|
||||
prices = data.current(context.assets, 'price')
|
||||
record(price=prices)
|
||||
pass
|
||||
|
||||
|
||||
def analyze(context, perf):
|
||||
stats = get_pretty_stats(perf)
|
||||
print(stats)
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_algorithm(
|
||||
capital_base=1000,
|
||||
data_frequency='daily',
|
||||
initialize=initialize,
|
||||
handle_data=handle_data,
|
||||
exchange_name='poloniex',
|
||||
algo_namespace='buy_btc_polo_jh',
|
||||
base_currency='usd',
|
||||
analyze=analyze,
|
||||
start=pd.to_datetime('2017-01-01', utc=True),
|
||||
end=pd.to_datetime('2017-12-25', utc=True),
|
||||
)
|
||||
live = True
|
||||
if live:
|
||||
run_algorithm(
|
||||
capital_base=0.01,
|
||||
initialize=initialize,
|
||||
handle_data=handle_data,
|
||||
exchange_name='poloniex',
|
||||
algo_namespace='buy_btc_polo_jh',
|
||||
base_currency='btc',
|
||||
analyze=analyze,
|
||||
live=True,
|
||||
simulate_orders=True,
|
||||
)
|
||||
else:
|
||||
run_algorithm(
|
||||
capital_base=1000,
|
||||
data_frequency='daily',
|
||||
initialize=initialize,
|
||||
handle_data=handle_data,
|
||||
exchange_name='poloniex',
|
||||
algo_namespace='buy_btc_polo_jh',
|
||||
base_currency='usd',
|
||||
analyze=analyze,
|
||||
start=pd.to_datetime('2017-01-01', utc=True),
|
||||
end=pd.to_datetime('2017-12-25', utc=True),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user