Commit Graph
134 Commits
Author SHA1 Message Date
Richard Frank 73a61caaeb MAINT: Removing unused array and unused attribute 2016-09-19 15:19:30 -04:00
Andrew Liang 98f3fc9326 MAINT: Refactor application of capital changes
Previously, on the dt of a capital change, we use the un-updated
prices to find the ending performance of the previous subperiod and
then got the new prices to determine the portfolio value used to
calculate the delta, without actually updating the performance
before applying the capital change. This logic is confusing and
unintuitive. Instead, save the ending performance as we do previously,
but have temp values for the starting current subperiod value.
Update those temp values after processing the capital change
2016-08-01 11:51:45 -04:00
Andrew Liang a9d698018a MAINT: Refactor checking, calculation and processing of capital changes
AlgorithmSimulator will no longer check for capital changes.
Instead, TradingAlgorithm find and calculate the changes, and
PerformanceTracker will apply the changes
2016-07-25 10:05:47 -04:00
Andrew Liang f146d6d8c1 MAINT: For capital changes, support input of delta or target value
For target changes, calculate the delta using the portfolio value
of the current minute
2016-07-20 15:44:41 -04:00
Andrew Liang 52cb0fc70a DEV: Allow net_leverage value to be forced by broker 2016-07-20 11:20:08 -04:00
Jean Bredeche 6fb4923cc7 Re-implemented the Calendar API.
Instead of having separate ExchangeCalendar and TradingSchedule objects, we
now just have TradingCalendar.  The TradingCalendar keeps track of each
session (defined as a contiguous set of minutes between an open and a close).
It's also responsible for handling the grouping logic of any given minute
to its containing session, or the next/previous session if it's not a market
minute for the given calendar.
2016-07-12 13:13:50 -04:00
Andrew Liang ba3ba053cb MAINT: Refactor schedule function rules
Refactor to eliminate unnecessary type coercion. Reduce some code
duplication
2016-06-14 13:55:59 -04:00
jfkirkandJean Bredeche 75e0e4723d TST: Refactors more tests to use WithTradingSchedule 2016-06-08 13:34:20 -04:00
jfkirkandJean Bredeche d9fc514fa8 TST: Adds TradingSchedule test fixture 2016-06-08 13:34:20 -04:00
jfkirkandJean Bredeche 4b7390ac81 WIP: Refactors tests to use TradingSchedule 2016-06-08 13:34:19 -04:00
jfkirkandJean Bredeche c8304e8601 ENH: Adds ExchangeCalendar, TradingSchedule, and implementations
Conflicts:
	tests/data/test_minute_bars.py
	tests/data/test_us_equity_pricing.py
	tests/finance/test_slippage.py
	tests/pipeline/test_engine.py
	tests/pipeline/test_us_equity_pricing_loader.py
	tests/serialization_cases.py
	tests/test_algorithm.py
	tests/test_assets.py
	tests/test_bar_data.py
	tests/test_benchmark.py
	tests/test_exception_handling.py
	tests/test_fetcher.py
	tests/test_finance.py
	tests/test_history.py
	tests/test_perf_tracking.py
	tests/test_security_list.py
	tests/utils/test_events.py
	zipline/algorithm.py
	zipline/data/data_portal.py
	zipline/data/us_equity_loader.py
	zipline/errors.py
	zipline/finance/trading.py
	zipline/testing/core.py
	zipline/utils/events.py
2016-06-08 13:34:18 -04:00
Andrew Liang 40f42b43f5 DEV: Adjust performance calculations for capital changes
Refactor PerformancePeriod so that it creates a sub-period every
time a capital change happens within the period
2016-05-24 17:23:36 -04:00
Andrew LiangandJean Bredeche 7641247b41 BUG: DAY_END action not emitted during minute emission
Refactor AlgorithmSimulator so that DAY_END is emitted for both
minute and daily emission, and that handling of end-of-minute
and end-of-day are separated
2016-05-06 10:25:44 -04:00
Andrew Liang d69b960c49 BUG: Don't save empty positions when user access non-existent position
Previously, whenever we try to access a missing value on the Positions
dict, we return a default Position and save it to the dict. Instead,
just return the Position
2016-04-26 13:28:35 -04:00
Richard Frank 70befd490b MAINT: Don't store data portal everywhere
Removed lots of data portal references that participated in ref cycles
and prevented deterministic cleanup of dbs.
2016-04-12 19:33:22 -04:00
Jean Bredeche dc01c45dc4 DEV: Apply adjustments for portfolio and account in BTS
completely copied from https://github.com/quantopian/zipline/pull/1104/

All credit goes to Andrew Liang (@lianga888)
2016-04-05 11:37:34 -04:00
Eddie HebertandJean Bredeche 16fd6681a6 ENH: Rewrite of Zipline to use lazy access pattern
More documentation to follow in release notes.

Based on lazy-mainline branch, see for more details.

Also-By: Jean Bredeche <jean@quantopian.com>
Also-By: Andrew Liang <aliang@quantopian.com>
Also-By: Abhijeet Kalyan <akalyan@quantopian.com>
2016-04-04 16:12:58 -04:00
Stewart Douglas e47cb96479 BUG: Ensure consistent ordering of amounts, prices & multipliers
Previously, we have assumed that the `amounts` and `last_sale_prices`
lists have the same order as the `value_multipliers`. This is not
correct, since to populate the `amounts` and `last_sale_prices` lists
we iterate over a `dict` (self.positions). The order of this `dict`
can change in arbitrary ways when it is updated, which occurs when
we call `update_positions`. Our `value_multipliers` however are stored
in an `OrderedDict`, meaning the order of existing key/value pairs
is not changed when they are updated.

To address this issue, we make sure that `self.positions` subclasses
`OrderedDict`.
2016-03-11 13:16:24 -05:00
Scott Sanderson e940a56b08 MAINT: Don't recompute portfolio in BTS. 2016-02-23 00:41:58 -05:00
dmichalowicz 5be63f36d5 ENH: Add auto_close_date support for equities 2016-02-22 13:51:20 -05:00
Richard Frank 318ac4deb5 TST: Use np.floor to preserve float return, since py3 returns an int 2016-02-11 18:46:43 -05:00
Richard Frank 1075e0573e PERF: Updated to sort_values for new pandas 2016-02-11 18:46:43 -05:00
jfkirk ece9e59ef9 ENH: Adds asset db downgrade management and tests 2016-01-22 14:56:30 -05:00
jfkirk db1e62971a ENH: Adds tick_size and renames futures multiplier 2016-01-22 14:56:30 -05:00
jfkirk b8b7049f39 BUG: Fixes incorrect value assignment in perf period 2016-01-19 16:11:22 -05:00
Eddie Hebert 1362f155c6 BUG: Make payout affect ending_cash.
The payout should be reflected in ending cash, not just the total used
for pnl.
2016-01-06 10:17:37 -05:00
Eddie Hebert 7a6c6695f7 MAINT: Factor out payout calculation. 2016-01-05 10:39:41 -05:00
Eddie Hebert 962347318d MAINT: Futures cash adjustment on change and calc.
In preparation for the incoming changes which no longer push every bar
through the tradesimulation, remove the adjustment of the period's cash on
every pricing change of a held futures asset.

Instead hold the last sale price for each held future either:

- At the end of each peformance period update the last sale prices of
  all held futures, so that the pnl for the next period uses values
  derived from the cash difference between the end of the two periods.

- When a transaction is processed for the Future, so that the correct
  amount is applied to each cash adjustment. (i.e. the cash adjustment
  is reset on every change of amount of the Future being held, so that
  multiple size and prices do not need to be tracked for the same asset.)

Also, remove now unused dict of payout calculation modifier, since new
calculation reads the value directly off of the asset.

Remove update_last_sale test, since the method no longer returns a cash
value.
2016-01-04 16:52:37 -05:00
Eddie Hebert 0b588219af Fix spelling error. 2015-12-31 15:18:03 -05:00
Eddie Hebert d07d42263a MAINT: Make tracker stats a method.
Instead of calling a function, where the only parameter is the tracker
object, make it a method, so that the snapshot of position tracker stats
can be more easily called as `pt.stats()`.
2015-12-18 09:52:53 -05:00
Eddie Hebert 104245bb19 MAINT: Make split method coarse.
In preparation for removal of widespread events, change the split
methods to use params for sid and cost, instead of an event, for
compatibility with lazy branch.

co-author: @jbredeche <jean@quantopian.com>
2015-12-17 15:11:09 -05:00
Eddie Hebert 7eae960b21 MAINT: Make commission methods coarse.
In preparation for removal of widespread events, change the commission
methods to use params for sid and cost, instead of an event, for
compatibility with lazy branch.

co-author: @jbredeche <jean@quantopian.com>
2015-12-17 15:09:12 -05:00
Eddie Hebert 7df0f9e4b0 MAINT: Pass leverage instead of account to risk.
The only value used in the account is leverage, so pass the leverage
value directly.

Also, remove account from risk init, since it is not used.
2015-12-16 15:32:48 -05:00
Eddie Hebert bbb9cc87a9 REF: Move transaction class to own module. 2015-12-15 16:23:59 -05:00
Eddie Hebert 06d4d7e74b MAINT: Remove perf_periods member.
Refer to cumulative and todays performance explicitly instead of always
looping through.

The third value (minute) for which this was useful, has been removed.

Also, there are some actions where only cumulative may need application,
e.g. application of dividends. (However, this patch does not remove
dividend processing from todays performance, but opens up later patches
to make that distinction.)
2015-12-15 13:47:38 -05:00
jfkirk a1584cebe7 STY: Factors-out event price handling 2015-11-02 10:02:58 -05:00
jfkirk 7d29bb6a67 BUG: Fixes failure to account for Futures transaction prices 2015-10-30 12:04:38 -04:00
Stewart Douglas 3feb78807e MAINT: Add license to various files 2015-10-07 15:47:45 -04:00
Eddie Hebert 644cfe6a42 MAINT: Remove unused minute performance period.
Minute performance period is no longer used. The minute risk containers,
which had been removed, were the last usage of the minute performance
period.
2015-09-29 12:10:37 -04:00
Eddie Hebert 20c64b591f MAINT: Clean up net calculations.
- Combine the net value and exposure functions into `calc_net` since
  they use the same logic.

- Change the logic to handle on empty list to using the a start value of
  0.0. More concise, and reduces the number of return points from the
  function to one.
2015-09-25 16:43:34 -04:00
Eddie Hebert 31d214d8ff MAINT: Combine leverage calculations.
Instead of having two leverage functions, whose differences were the
parameter names, add a `calc_leverage` function, with the calling code
determining whether it is gross or net by the type of exposure passed in.
2015-09-25 13:58:44 -04:00
Eddie Hebert ae97e75388 MAINT: Only calc position values once per packet.
Instead of calculating the position values for each stat result, e.g.
gross_exposure, net_liquidity etc.; get the positions upfront and then
calculate the period and position stats in order, passing each value
explicitly to the ones that follow it in the dependency chain.

e.g. the gross_value depends on the long_value and the short_value,
which called the position_values property for calculating both the
long_value and the short_value.

Removing the repeated calls to position_values (and
position_exposures) removes the need for the caching the last sale
prices and position amounts in separate vectors, since it is inexpensive
enough to read those values off of the positions dictionary held in the
position tracker.

This patch gives a small gain to ~500 sized portfolios, but the main
intent is to clear the path to not storing last_sale_prices on the
position objects at all. Removing all of the caching layer in this class
makes that change easier to apply. Removing the extra calls to
position_values also made this class easier to step through/reason about
when splicing in the new last sale price access, as well.
2015-09-23 22:26:13 -04:00
jfkirk a6ce1e5e8d ENH: Adds auto_close_date field to Future objects 2015-09-11 14:08:03 -04:00
jfkirk 6e6ef447d2 TST: Adds tearDownClass methods to delete TradingEnvironments 2015-09-10 11:53:29 -04:00
jfkirk dc964a7e7d MAINT: Removes the ability to reference a global TradingEnvironment
This commit removes the ability to reference a shared TradingEnvironment through the zipline.finance.trading module. In place, the classes that require a TradingEnvironment, or its child AssetFinder, contain their own references to those objects.

This commit also adds serialization utilities that allow for the pickling/unpickling of objects without unintentionally their TradingEnvironments or AssetFinders.
2015-09-10 11:53:28 -04:00
jfkirk 67c56f768b ENH: Adds auto-closing feature and implements for Futures 2015-07-31 10:38:44 -04:00
jfkirk 16ab46b69c DEV: Uses ValueError when PerformanceTracker.to_dict receives invalid emission type 2015-07-21 16:06:52 -04:00
jfkirk 8d5bfd3c91 BUG: Aligns performance packet generation between minute and daily modes 2015-07-21 13:25:39 -04:00
Eddie Hebert 27ab36deb2 MAINT: Remove references to minute risk.
The minutely calculation of risk metrics had been removed with a
previous patch, remove vestigial references.

Remove a test which tested the behavior of updating the second minute of
a day.

Remove the logic that changed the datetime index of the risk metrics
depending on emission rate, now only trading_days are needed.

Remove `returns_frequency` parameter since both minute and daily
data frequency always use daily returns.
2015-07-15 15:36:35 -04:00
jfkirk efa6d8dbce ENH: Adds a perf tracker method to handle SIDs leaving the universe 2015-07-09 17:03:21 -04:00