Adjustments to the sample arbitrage algo

This commit is contained in:
fredfortier
2017-09-11 18:20:28 -04:00
parent 3e2a8dd78b
commit 41d9bbca1b
3 changed files with 19 additions and 6 deletions
@@ -1,6 +1,7 @@
from logbook import Logger
from catalyst.api import (
record,
order,
symbol,
get_open_orders
@@ -26,12 +27,12 @@ def initialize(context):
symbol(context.trading_pair_symbol, context.selling_exchange.name)
context.entry_points = [
dict(gap=0.01, amount=0.05),
dict(gap=0.02, amount=0.1),
dict(gap=0.03, amount=0.05),
dict(gap=0.04, amount=0.1),
dict(gap=0.05, amount=0.5),
]
context.exit_points = [
dict(gap=0.01, amount=0.05),
dict(gap=-0.02, amount=0.01),
dict(gap=-0.02, amount=0.5),
]
context.MAX_POSITIONS = 50
@@ -168,6 +169,7 @@ def handle_data(context, data):
gap_percent=gap * 100
)
)
record(buying_price=buying_price, selling_price=selling_price, gap=gap)
for exchange in context.trading_pairs:
asset = context.trading_pairs[exchange]
+8 -1
View File
@@ -409,6 +409,9 @@ class ExchangeTradingAlgorithm(TradingAlgorithm):
self.add_pnl_stats(minute_stats)
if self.recorded_vars:
self.add_custom_signals_stats(minute_stats)
recorded_cols = self.recorded_vars.keys()
else:
recorded_cols = None
self.add_exposure_stats(minute_stats)
@@ -416,7 +419,11 @@ class ExchangeTradingAlgorithm(TradingAlgorithm):
log.debug(
'statistics for the last {stats_minutes} minutes:\n{stats}'.format(
stats_minutes=self.stats_minutes,
stats=get_pretty_stats(print_df, self.stats_minutes)
stats=get_pretty_stats(
stats_df=print_df,
recorded_cols=recorded_cols,
num_rows=self.stats_minutes
)
))
today = pd.to_datetime('today', utc=True)
+5 -1
View File
@@ -1,7 +1,7 @@
import pandas as pd
def get_pretty_stats(stats_df, num_rows=10):
def get_pretty_stats(stats_df, recorded_cols=None, num_rows=10):
"""
Format and print the last few rows of a statistics DataFrame.
See the pyfolio project for the data structure.
@@ -22,6 +22,10 @@ def get_pretty_stats(stats_df, num_rows=10):
'pnl', 'long_exposure', 'short_exposure', 'orders',
'transactions', 'positions']
if recorded_cols is not None:
for column in recorded_cols:
columns.append(column)
def format_positions(positions):
parts = []
for position in positions: