some efficiency changes - no longer transferring the list of daily returns, no longer holding transactions in the daily and the cumulative performance periods.

This commit is contained in:
fawce
2012-04-18 10:55:21 -04:00
parent 7eb0ba67ac
commit 6561292e4c
4 changed files with 13 additions and 30 deletions
+9 -4
View File
@@ -178,7 +178,9 @@ class PerformanceTracker():
# initial portfolio positions have zero value
0,
# initial cash is your capital base.
starting_cash = self.capital_base
starting_cash = self.capital_base,
# save the transactions for the daily periods
keep_transactions = True
)
def get_portfolio(self):
@@ -288,7 +290,8 @@ class PerformanceTracker():
self.todays_performance = PerformancePeriod(
self.todays_performance.positions,
self.todays_performance.ending_value,
self.todays_performance.ending_cash
self.todays_performance.ending_cash,
keep_transactions = True
)
def handle_simulation_end(self):
@@ -374,7 +377,7 @@ class Position():
class PerformancePeriod():
def __init__(self, initial_positions, starting_value, starting_cash):
def __init__(self, initial_positions, starting_value, starting_cash, keep_transactions=False):
self.ending_value = 0.0
self.period_capital_used = 0.0
self.pnl = 0.0
@@ -384,6 +387,7 @@ class PerformancePeriod():
#cash balance at start of period
self.starting_cash = starting_cash
self.ending_cash = starting_cash
self.keep_transactions = keep_transactions
self.processed_transactions = []
self.cumulative_capital_used = 0.0
self.max_capital_used = 0.0
@@ -434,7 +438,8 @@ class PerformancePeriod():
self.max_leverage = 1.1 * self.max_capital_used / self.starting_cash
# add transaction to the list of processed transactions
self.processed_transactions.append(txn)
if self.keep_transactions:
self.processed_transactions.append(txn)
def round_to_nearest(self, x, base=5):
return int(base * round(float(x)/base))
+3 -3
View File
@@ -439,12 +439,12 @@ class TransactionSimulator(qmsg.BaseTransform):
warning = """
Calculated a zero volume transaction on trade:
{event}
for order:
{order}
for orders:
{orders}
"""
warning = warning.format(
event=str(event),
order=str(order)
orders=str(orders)
)
qutil.LOGGER.warn(warning)
return None
+1 -15
View File
@@ -623,11 +623,6 @@ def PERF_FRAME(perf):
"""
#TODO: add asserts...
# DATE fields:
# started_at, period_start, period_end, last_close, last_open
# pos.last_sale_date
# txn.dt
assert isinstance(perf['started_at'], datetime.datetime)
assert isinstance(perf['period_start'], datetime.datetime)
@@ -654,16 +649,7 @@ def PERF_FRAME(perf):
tp['transactions'] = convert_transactions(tp['transactions'])
cp['transactions'] = convert_transactions(cp['transactions'])
returns = []
for dr in perf['returns']:
updated = {}
updated['returns'] = dr['returns']
updated['date'] = EPOCH(dr['dt'])
returns.append(updated)
perf['returns'] = returns
return BT_UPDATE_FRAME('PERF', perf)
def convert_transactions(transactions):
-8
View File
@@ -139,14 +139,6 @@ class FinanceTestCase(TestCase):
zipline.trading_client.order_count
)
# the number of transactions in the performance tracker's cumulative
# period should be the same as the number of orders place by the
# algorithm.
self.assertEqual(
zipline.trading_client.order_count,
len(zipline.trading_client.perf.cumulative_performance.processed_transactions)
)
@timed(EXTENDED_TIMEOUT)
def test_aggressive_buying(self):