Commit Graph

79 Commits

Author SHA1 Message Date
Thomas Wiecki d52a7b6d8e DOC: Added doc string for instant_fill. 2013-12-04 07:16:18 -05:00
Thomas Wiecki 860a340e55 BUG: Erroneous call to log. 2013-11-25 19:52:05 -05:00
Thomas Wiecki c199a0d956 STY: Move order_value from blotter to TradingAlgorithm. 2013-11-25 17:38:30 -05:00
Thomas Wiecki 579cb56663 STY: Long line break for pep8. 2013-11-25 12:16:41 -05:00
Thomas Wiecki 9cb9831c08 STY: Prepend order_ to all target methods. 2013-11-25 11:28:27 -05:00
Eddie Hebert ccb7f493f7 PERF: Only update the portfolio once per dt.
So that each reference to `.portfolio` in the algoscript,
cache the value of the portfolio, and mark the need for a new
value at the end of each dt in the tradesimulation loop.
2013-11-19 14:39:19 -05:00
fawce 6d46eb71ea PERF: moved performance calculation out of inner loop
lazy loading for portfolio
less repeating in performance period updates
2013-11-19 10:39:57 -05:00
stanh 1f1be35734 ENH: Added commission model PerDollar
Commissions will be calculated based on total dollar traded.
2013-11-15 11:49:58 -05:00
Jonathan Kamens 73faf9133e MAINT: Clean up imports of zipline.finance.trading
Use "from zipline.finance import trading" instead of "import
zipline.finance.trading as trading".
2013-10-29 13:50:14 -04:00
Eddie Hebert 37c56b9aa4 MAINT: Use Series throughout for daily returns.
Remove the lists of DailyReturn objects in favor of using pd.Series
to store the return values.

Should make it easier to inspect the values when stepping through,
make the windowing of data to a certain range more facile by using,
and have some performance increases due to removing object creation
and member access.
2013-10-19 23:06:18 -04:00
Thomas Wiecki 65637b9430 ENH: Add option of instantly filling orders. 2013-10-01 20:30:01 -04:00
Jeremiah Lowin 48486c9814 ENH: New order methods. 2013-08-08 15:54:59 -04:00
Thomas Wiecki e1475cc24f BUG: cum_perfs defined but not used. 2013-08-01 16:33:26 -04:00
Thomas Wiecki 37bab9bb72 ENH: Safe risk_report in TradingAlgorthm. 2013-08-01 16:08:56 -04:00
Eddie Hebert 9ff588e7fc BUG: Fix spelling of capital base in TradingAlgorithm repr.
s/captial_base/capital_base/
2013-07-23 14:40:39 -04:00
Eddie Hebert b7b4d397ba BUG: Revert "Merge ability to specify timing of fills."
This reverts commit e3a9ca27b1, reversing
changes made to 3d8bdeb429.

Conflicts:
	zipline/gens/tradesimulation.py

The aforementioned change needs a revert because it caused a 'doubling'
of orders, since the portfolio is not updated until after handle_data
is called a second time after an order has been processed.

The flexibility of fill_delay is still desired, but remove for now,
favoring reverting back to existing behavior over trying ot fix the
fill_delay logic.
2013-07-15 10:47:55 -04:00
Eddie Hebert d901a12e93 BUG: Prevent algorithm init failure due to missing fill_delay.
Provide a default value for data_frequency, choosing 'daily',
so that the fill_delay is set even when a data_frequency value
is not in kwargs.

This does open up a place for disjointedness if the sim_params that
is passed to run does not match the data_frequency set during initialize.
2013-07-09 12:45:56 -04:00
Thomas Wiecki 5a58ade0fc ENH: Add flag fill_delay kwarg to TradingAlgorithm. 2013-07-09 11:38:09 -04:00
Matti Hanninen 43d3757004 DOC: Fix docstring for TradingAlgorithm
Get the amount from the algorithm object instead of referring to
a (undefined) global.
2013-06-14 15:43:51 -04:00
Matti Hanninen d475766c63 DOC: Fix docstring for TradingAlgorithm
Fix the example given in the class docstring as the original didn't work
on REPL.
2013-06-14 15:43:40 -04:00
Eddie Hebert 4bde1e4c11 MAINT: Change slippage guard to check for slippage model base type.
Now that VolumeShareSlippage and FixedSlippage inherit from the same
class, check for `SlippageModel` instead of the inividual classes.
2013-06-10 10:27:16 -04:00
Jonathan Kamens f9580316c9 MAINT: Reformat comment to make flake8 happy 2013-05-30 10:06:23 -04:00
Eddie Hebert 0ef428c8e0 BUG: Fix exception when using capital_base as a kwarg to an algorithm.
Need to pop of the kwarg, since `initialize` does not use it as a
parameter.
2013-05-21 17:51:51 -04:00
Richard Frank 381df3534d MAINT: Ensure we're not setting the blotter to None. 2013-05-10 12:09:38 -04:00
Eddie Hebert b33243da63 BUG: Ensure that data_frequency set on algo is set on sim_params.
Set the data_frequency member of an algorithm on the sim_params
configuration object.

Though the extra setting is slightly redundant, it is needed to
ensure that the same data_frequency is used throughout.

Should fix a bug where an algo that was intended to be run in minute
mode was operating as if it were daily in performance.

Possible TODO: Remove data_frequency as a param to TradingAlgorithm,
in favor of only being a property of sim_params.
2013-05-09 03:44:51 -04:00
Eddie Hebert 91e5abbc44 MAINT: Use a for loop for main algorithm run loop instead of list
So that stepping through a debugger is a little easier, with
respect to having easy access to the algorithm object, and seeing
which step in `self.gen` the interpreter is currently at.
2013-05-07 17:19:38 -04:00
Eddie Hebert aa54d0ae0e MAINT: Allow the algorithm benchmark returns to be overrideable.
So that test data can be well defined with a short list of benchmarks.

This could also lead to having more customizable benchmarks for
backtests.
2013-05-07 16:09:58 -04:00
Eddie Hebert 4b7afb43d2 MAINT: Change repr's so that they are both human and machine readable.
For printability in the repr when debugging algo config and state,
change the repr of TradingAlgorithm and the objects it contains
so that the more closely adhere to the repr interface of being
able to recreate an object instance.
2013-05-04 22:26:28 -04:00
fawce 28df9ec423 MAINT: Refactor performance tracker as part of algorithm.
Instead of having the performance tracker as part of the
tradesimulation class, hold on to it inside of the algorithm
object, so that the perf_tracker is more easily accessed for
reset behavior, etc.
2013-04-30 17:19:01 -04:00
fawce f3cfc9623d ENH: new order management methods:
- get_open_orders
- get_order
- cancel
2013-04-26 19:46:00 -04:00
fawce 9062b9636a MAINT: refactoring for orders api
- moved Order and Blotter to zipline.finance.blotter
- moved order method from AlgoSimulator to Blotter
- eliminated the set_order method in algorithm
- moved blotter to the algorithm
2013-04-26 19:45:59 -04:00
fawce 24dfcaffc8 MAINT: Remove TradeSimulationClient class layer.
In favor of directly using the AlgorithmSimulator class.
2013-04-25 18:03:44 -04:00
Eddie Hebert 2b0a91e568 BUG: Fix examples with regards to simulation parameters.
Fix bug where algorithms that lack sim_params do not pass the source
derived created sim_params through the generator creation logic.
2013-04-25 12:57:56 -04:00
Eddie Hebert 9099d301f3 ENH: Stream benchmark returns as events.
Instead of creating a list of benchmarks in the risk module,
stream benchmarks through the system as events, starting from the
algorithm generator.

Works towards more easily setting arbritrary pricing data as
a a benchmark, as well as working towards live minutely benchmarks.
2013-04-15 11:43:13 -04:00
Eddie Hebert 35f57ada3e ENH: Send transactions and orders as standalone events.
- Add transaction and order types
- Move TransactionSimulator from trading.py to tradesimulation.py
  (only used by other members of the tradesimulation module)
- Make Transaction an independent event, like dividend
- Add Blotter class.
- Flatten the transaction events to be independent of trade bar events
- Make orders into events that reach performance (need to add
handling)
- Issue IDs to orders and tracking each transaction's order id.
- Make volume share slippage fill orders independently, rather than
  aggregating them into a single transaction.
- Perf tracker holds orders, serializes them with transactions.
- Order state defined and maintained by order class.
- Minutely emission of orders based on last_modified date.
2013-04-14 18:59:57 -04:00
Richard Frank 5a7702c22d MAINT: Factored out _create_data_generator helper method 2013-04-03 16:04:33 -04:00
fawce 241a43bb13 ENH: Adds an optional filter to the algorithm's date_sorted_sources
So that a filter function can filter out sids on a 'static' source,
when the universe of sids changes.

e.g. when using fetch_csv with a changing universe of stocks.
2013-03-26 16:48:34 -04:00
Eddie Hebert 3707c7b225 MAINT: Changes name of grouping of by dt in generator chain.
Changes name to `grouped_by_dt` instead of `grouped_by_date` to
clarify that the grouping is by dt, which can be by minute, instead
of grouping by calendar date.
2013-03-20 12:12:33 -04:00
Eddie Hebert 0169251c89 MAINT: Removes unused init method from algorithm.
The init method had been copied to method called initialize,
to avoid confusion with __init__
2013-03-19 22:59:38 -04:00
Eddie Hebert d2bdfc931d BUG: Fixes error added while rearticulating sim_params.
Previous attempt to make sim_parms logic clearer had clobbered the
override logic when sim_params is passed to the run function.

Added a few comments as well as restructuring how the sim_params
that are passed to run overrides the default values or not.

This also makes the passing of sim_params to run to no longer have
the side-effect of overwriting the default sim_params.
2013-03-19 22:46:04 -04:00
Eddie Hebert ccef17dec6 MAINT: Fixes comment about perf type. 2013-03-19 21:35:01 -04:00
Eddie Hebert a645b2a86e MAINT: Fixes comment about returned performance types.
The simulator had been changed to return dictionary objects instead
of ndicts.
2013-03-19 20:56:56 -04:00
Eddie Hebert 50e0334b3d STY: Uses if/else for setting sim_params in algorithm.
Instead of checking 'if' and then 'if not', uses an if/else.
2013-03-19 20:53:44 -04:00
Eddie Hebert 1909a0576f MAINT: Removes unused frame_count member from algorithm class.
frame_count is only over incremented, but never read or otherwise
used.
2013-03-19 20:36:53 -04:00
Eddie Hebert 0b6e4650d9 MAINT: Removes unused flag from algorithm class.
The `self.done` member of TradingAlgorithm is never used.
2013-03-19 19:50:40 -04:00
Eddie Hebert 3e65980bda MAINT: Updates copyright of algorithm module to current year. 2013-03-19 19:06:54 -04:00
fawce 890762bde7 MAINT: added typed errors module
- added exceptions in place of asserts for expected fields for rolling
transforms.
- removed assertions with Messages in favor of typed exceptions.
2013-03-19 11:39:23 -04:00
Eddie Hebert e901e06f39 Changes the API for recording variables.
Uses a method called 'record' that provides a key value,
instead of providing keys to extract from context.

The variables are stored internally to the algorithm in a dictionary,
and not just stared as a property of the algorithm.

Main intent behind this change is to make the API more user friendly,
since the previous recorded_variables relies on the value to be set
in the algorithms context/self, the hope is that only having to use
the `record` method means less moving pieces and a more understandable
API.

i.e., instead of:

```
def initialize(self):
    recorded_variables('foo', bar')

def handle_data(self, data):
    self.foo = 1
    self.bar = 2
```

The API is now:

```
def initialize(self):
    pass

def handle_data(self, data):
    self.record(foo=1, bar=2)
```
2013-03-02 18:28:35 -05:00
fawce 1a85781170 updated run method to use sim_params. 2013-02-18 10:24:32 -05:00
fawce 2c7355a0dc Refactoring of TradingEnvironment to isolate the global state: index symbol and exchange timezone. Parameters that define the simulation (start, end, and capital base) were put in a new class, SimulationParameters.
Global state for the financial simulation environment is accessed through the
zipline.finance.trading module, which now contains a module variable:
environment.

Parameters are passed into an algorithm as a keyword argument, sim_params.
SimulationParameters creates a trading day index for the test period that
can be used to find trading days, calculate distance between trading days,
and other common operations. The sim params index is just selected from the
global state.

================

Details:

    - adding delorean to the requirements.
    - made index symbol a parameter for loading the benchmark data. changed
    messagepack storage to be symbol specific.
    - ported risk, performance, algorithm, transforms, batch transforms
    and associated tests to use simulation parameters and global environment
    - factory and sim factory use global state and sim params
    - factory method parameter names now reflect the class expected
2013-02-18 10:24:32 -05:00