Remove more use of lists for storing internal risk values to use
pandas structures, for easier matching of time to value.
Accordingy, convert use of -1 for getting last value,
to use current dt.
Continue on path of converting values stored inside of risk metrics
to use a DataFrame instead of storing multiple lists.
Also, the need for latest_dt in getting the current volatility for
the sharpe calculation, shows that we need to set the lastest_dt at
the beginning of the update loop.
to account for minimum price variation.
On an order to buy, between .05 below to .95 above a penny, use that penny.
On an order to sell, between .05 above to .95 below a penny, use that penny.
Eventually, all cumulative metrics, (alpha, beta, etc.) will be
stored in the same DataFrame
For easier tracking of dt to values during debugging, but should be
some performance gains as well.
So that it is easier to add new containers, factor out the creation
of the index.
Also, make the returns frequency a parameter, to make the use of
different frequencies more clear from within the risk metrics object,
rather than hot swapping in the new frequency type via the now
removed `initialize_daily_indices`.
The eigen_values, condition_number, algorithm_covariance, and
benchmark variance, which were easy to calculate alongside beta,
since they share the same inputs, but were not passed along to performance.
Remove to trim down the number of risk report members as well as
number of calcluations done.
Can add back in if there is an expressed need for eigen_values etc.,
perhaps in an 'opt-in' type configuration.
Expect the same shape of data for the supplemental data, to make
working and preparing with the supplemental data consistent with
what is passed to the algorithm.
Instead of sliding to the next trading day because of the behavior
of `searchsorted`, if dt argument is not a trading day use it as a
max value for corresponding date of the index.
Fixes a bug where if the end of the quarter is calculated with
disregard to trading days, get_index would return the first day
of the next quarter, instead of the last trading day of the intended
quarter.
For TALib functions like MACD that have output names, return a
DataFrame that for which the columns are the output names of the
function.
So that when using a TALib function, the algorithm doesn't need
to know the index position of the desired result, in favor of using
the name of the result.
e.g.
```
macd_result['AAPL'][0]
```
becomes,
```
macd_result['AAPL']['macd']
```
and
```
macd_result['AAPL'][1]
```
becomes,
```
macd_result['AAPL']['macdsignal']
```
Also, change return type of functions that return floats from a
dictionary to a Series, so that the function is always returning a
pandas type.
Instead of using a pandas Series of with dictionaries as the
values treasury curves, use a DataFrame which more naturally fits
the data type of a having a timeseries with mulitple values.
Should allow easier slicing/manipulation of the treasury curves,
e.g. getting 10 year curves would now be:
```
treasury_curves['10year']
```
Before we were setting benchmark returns on the first day
to 0. This commit changes this by calculating the benchmark
return from open to close.
According to @eherbert this is also what the answer key does.
zipline.__version__ is now present. Closes#94.
Moreover, git master should have a .dev version string according
to convention. Releases then get the .dev label removed.
Also remove test that compares risk metrics batch to iterative,
since the 'iterative' calculations, replaced by the cumulative
calculations, will intentionally drift from the results in the risk
report due to annualization and other factors.
Work towards having separate calculations for the fixed periods versus
the cumulative/headline risk metrics.
Different sumbodules for each type should help make the calculations
type distinct and easier to find.
In anticipation of splitting apart the different risk classes
into their own submodules, a distinct risk module should help
organize those new classes.
For consistency, datetimes returned by the trading calendar should
always show HHMMSS of midnight UTC. Not only is this useful for
consistency, but it also allows us to check if a particular date() is
in an array of these datetimes, because they will hash to the same
thing. For example:
early_closes = get_early_closes()
... later ...
if current_bar_datetime.date() in early_closes:
... today closes early ...
If if the datetimes returned by the trading calendar functions don't
have 00:00:00 for HHMMSS, then the "in" check above will fail because
the date and the datetimes in early_closes won't hash to the same
thing.
If a stock stops gettign updated values, e.g. if a stock rolls out
of a universe strategy, currently the underlying batch transform
for TALib may have nans (which is another issue that could be addressed),
the nans cause crashes when passed to some TALib function, e.g. Bollinger
Bands are incompatible with all nan values.
So, drop sids that only have nan values for the current data panel.
The defaultdict behavior was allowing both algo code and
TradingAlgorithm wrappers to add unintended keys.
Remove use of defaultdict in favor of a dictionary that explicitly
adds the values in tradesimulation, otherwise allow a KeyError
if the bar is indexed with a sid that doesn't exist.
Also, when iterating over the keys in the data bar, only return
those keys that have pricing data.
The deepcopy of events into the EventWindow's ticks was causing
a significant increase in memory consumption, e.g. an algorithm with
almost 200 sids and 14 vwaps removing the deepcopy reduces the amount
of memory consumed by about 40%.
The downside is that if an event's properties are changed, which is
not advised, later on, then the signal derived from vwap etc.
may be changed.