From 1b17296efda87a0132ceba5ab62f731c897e43c9 Mon Sep 17 00:00:00 2001 From: Joe Jevnik Date: Wed, 10 Aug 2016 13:27:28 -0400 Subject: [PATCH] BUG: fix the v5-v4 downgrade path to properly take the most recently held ticker --- zipline/assets/asset_db_migrations.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/zipline/assets/asset_db_migrations.py b/zipline/assets/asset_db_migrations.py index 2c56badd..72d24b78 100644 --- a/zipline/assets/asset_db_migrations.py +++ b/zipline/assets/asset_db_migrations.py @@ -272,14 +272,22 @@ def _downgrade_v5(op): from equities inner join + -- Nested select here to take the most recently held ticker + -- for each sid. The group by with no aggregation function will + -- take the last element in the group, so we first order by + -- the end date ascending to ensure that the groupby takes + -- the last ticker. (select * from - equity_symbol_mappings + (select + * + from + equity_symbol_mappings + order by + equity_symbol_mappings.end_date asc) group by - equity_symbol_mappings.sid - order by - equity_symbol_mappings.end_date desc) sym + sid) sym on equities.sid == sym.sid """,