I'm not too concerned yet with setting and changing the universe. As I understand, the universe is set before initialize
using results of a preprocessor run looking for calls (or what appear to be calls) to sid
, symbol
, or symbols
(and it seems you can't use both sids and symbols in the same code). It can then be changed by no more than one explicit call to set_universe
in initialize
and/or any number of calls to update_universe
in before_trading_start
. Thus, when before_trading_start
is called, a universe is already set. Correct?
My present need for a function like after_trading_end
is for simple bookkeeping: say, how many shares of which asset I bought, how many sold, at what average price, what my gross and net profit or loss was, and how much I paid in commissions. I want that calculated and displayed after trading - not during trading, when orders might still be sent after the summary (even at 4:00pm), and not before the start of the next trading day, because I shouldn't have to wait till Monday morning to see how I did this week, and because this may be the last day of the run and the next before-trading-start will never happen. I think the code to call after_trading_end
would be simple and similar enough to the code that calls before_trading_start
, and so wouldn't cost Quantopian much; but it would make algorithm writers' work much easier. Convinced, unconvinced?
At present, I use my own after_trading_end
, set with schedule_function
to run 1 minute before markets close (because minutes=0
causes a runtime error, even though there's no good reason), and a Boolean context.trading
switch set in before_trading_start
and cleared in after_trading_end
, which seems to run after handle_data
at 3:59pm. Very inelegant.
Other before_*
/after_*
functions can wait. With after_trading_end
and/or minutes=0
, they shouldn't be too hard for users to write.
I do need get_commission
to calculate how many shares I can afford to buy or have to sell, and because I like to know what I'm paying. I could keep commission parameters in context
and pass them to set_commission
, but Quantopian won't allow it in the contest, even in a comment. I want my algos to meet all the contest requirements as well as to calculate numbers of shares correctly, even if Quantopian later changes its default commission scheme. This is currently impossible.
Others might need get_universe
to see why they can't sell what they bought before a call to update_universe
. I only mentioned get_slippage
because there should be a getter for every setter.