1
+ import collections
1
2
from zipline .assets import Asset , Equity , Future
2
3
from zipline .assets .futures import FutureChain
4
+ from zipline .finance .asset_restrictions import Restrictions
3
5
from zipline .finance .cancel_policy import CancelPolicy
4
6
from zipline .pipeline import Pipeline
5
7
from zipline .protocol import Order
6
8
from zipline .utils .events import EventRule
9
+ from zipline .utils .security_list import SecurityList
7
10
8
11
9
- def attach_pipeline (pipeline , name , chunksize = None ):
12
+ def attach_pipeline (pipeline , name , chunks = None ):
10
13
"""Register a pipeline to be computed at the start of each day.
11
14
12
15
Parameters
@@ -15,10 +18,11 @@ def attach_pipeline(pipeline, name, chunksize=None):
15
18
The pipeline to have computed.
16
19
name : str
17
20
The name of the pipeline.
18
- chunksize : int, optional
21
+ chunks : int or iterator , optional
19
22
The number of days to compute pipeline results for. Increasing
20
23
this number will make it longer to get the first results but
21
- may improve the total runtime of the simulation.
24
+ may improve the total runtime of the simulation. If an iterator
25
+ is passed, we will run in chunks based on values of the itereator.
22
26
23
27
Returns
24
28
-------
@@ -30,6 +34,23 @@ def attach_pipeline(pipeline, name, chunksize=None):
30
34
:func:`zipline.api.pipeline_output`
31
35
"""
32
36
37
+ def batch_order_target_percent (weights ):
38
+ """Place orders towards a given portfolio of weights.
39
+
40
+ Parameters
41
+ ----------
42
+ weights : collections.Mapping[Asset -> float]
43
+
44
+ Returns
45
+ -------
46
+ order_ids : pd.Series[Asset -> str]
47
+ The unique identifiers for the orders that were placed.
48
+
49
+ See Also
50
+ --------
51
+ :func:`zipline.api.order_target_percent`
52
+ """
53
+
33
54
def cancel_order (order_param ):
34
55
"""Cancel an open order.
35
56
@@ -39,6 +60,26 @@ def cancel_order(order_param):
39
60
The order_id or order object to cancel.
40
61
"""
41
62
63
+ def continuous_future (root_symbol_str , offset , roll ):
64
+ """Create a specifier for a continuous contract.
65
+
66
+ Parameters
67
+ ----------
68
+ root_symbol_str : str
69
+ The root symbol for the future chain.
70
+
71
+ offset : int
72
+ The distance from the primary contract.
73
+
74
+ roll_style : str
75
+ How rolls are determined.
76
+
77
+ Returns
78
+ -------
79
+ continuous_future : ContinuousFuture
80
+ The continuous future specifier.
81
+ """
82
+
42
83
def fetch_csv (url , pre_func = None , post_func = None , date_column = 'date' , date_format = None , timezone = 'UTC' , symbol = None , mask = True , symbol_column = None , special_params_checker = None , ** kwargs ):
43
84
"""Fetch a csv from a remote url and register the data so that it is
44
85
queryable from the ``data`` object.
@@ -83,32 +124,6 @@ def fetch_csv(url, pre_func=None, post_func=None, date_column='date', date_forma
83
124
A requests source that will pull data from the url specified.
84
125
"""
85
126
86
- def future_chain (root_symbol , as_of_date = None , offset = 0 ):
87
- """
88
- Look up a future chain.
89
-
90
- Parameters
91
- ----------
92
- root_symbol : str
93
- The root symbol of a future chain.
94
- as_of_date : datetime.datetime or pandas.Timestamp or str, optional
95
- Date at which the chain determination is rooted. If this date is
96
- not passed in, the current simulation session (not minute) is used.
97
- offset: int
98
- Number of sessions to shift `as_of_date`. Positive values shift
99
- forward in time. Negative values shift backward in time.
100
-
101
- Returns
102
- -------
103
- chain : FutureChain
104
- The future chain matching the specified parameters.
105
-
106
- Raises
107
- ------
108
- RootSymbolNotFound
109
- If a future chain could not be found for the given root symbol.
110
- """
111
-
112
127
def future_symbol (symbol ):
113
128
"""Lookup a futures contract with a given symbol.
114
129
@@ -221,8 +236,9 @@ def order(asset, amount, limit_price=None, stop_price=None, style=None):
221
236
222
237
Returns
223
238
-------
224
- order_id : str
225
- The unique identifier for this order.
239
+ order_id : str or None
240
+ The unique identifier for this order, or None if no order was
241
+ placed.
226
242
227
243
Notes
228
244
-----
@@ -338,7 +354,7 @@ def order_target_percent(asset, target, limit_price=None, stop_price=None, style
338
354
----------
339
355
asset : Asset
340
356
The asset that this order is for.
341
- percent : float
357
+ target : float
342
358
The desired percentage of the porfolio value to allocate to
343
359
``asset``. This is specified as a decimal, for example:
344
360
0.50 means 50%.
@@ -532,6 +548,19 @@ def schedule_function(func, date_rule=None, time_rule=None, half_days=True, cale
532
548
:class:`zipline.api.time_rules`
533
549
"""
534
550
551
+ def set_asset_restrictions (restrictions , on_error = 'fail' ):
552
+ """Set a restriction on which assets can be ordered.
553
+
554
+ Parameters
555
+ ----------
556
+ restricted_list : Restrictions
557
+ An object providing information about restricted assets.
558
+
559
+ See Also
560
+ --------
561
+ zipline.finance.asset_restrictions.Restrictions
562
+ """
563
+
535
564
def set_benchmark (benchmark ):
536
565
"""Set the benchmark asset.
537
566
@@ -575,16 +604,16 @@ def set_commission(commission):
575
604
:class:`zipline.finance.commission.PerDollar`
576
605
"""
577
606
578
- def set_do_not_order_list (restricted_list ):
607
+ def set_do_not_order_list (restricted_list , on_error = 'fail' ):
579
608
"""Set a restriction on which assets can be ordered.
580
609
581
610
Parameters
582
611
----------
583
- restricted_list : container[Asset]
612
+ restricted_list : container[Asset], SecurityList
584
613
The assets that cannot be ordered.
585
614
"""
586
615
587
- def set_long_only ():
616
+ def set_long_only (on_error = 'fail' ):
588
617
"""Set a rule specifying that this algorithm cannot take short
589
618
positions.
590
619
"""
@@ -599,7 +628,7 @@ def set_max_leverage(max_leverage):
599
628
be no maximum.
600
629
"""
601
630
602
- def set_max_order_count (max_count ):
631
+ def set_max_order_count (max_count , on_error = 'fail' ):
603
632
"""Set a limit on the number of orders that can be placed in a single
604
633
day.
605
634
@@ -609,7 +638,7 @@ def set_max_order_count(max_count):
609
638
The maximum number of orders that can be placed on any single day.
610
639
"""
611
640
612
- def set_max_order_size (asset = None , max_shares = None , max_notional = None ):
641
+ def set_max_order_size (asset = None , max_shares = None , max_notional = None , on_error = 'fail' ):
613
642
"""Set a limit on the number of shares and/or dollar value of any single
614
643
order placed for sid. Limits are treated as absolute values and are
615
644
enforced at the time that the algo attempts to place an order for sid.
@@ -628,7 +657,7 @@ def set_max_order_size(asset=None, max_shares=None, max_notional=None):
628
657
The maximum value that can be ordered at one time.
629
658
"""
630
659
631
- def set_max_position_size (asset = None , max_shares = None , max_notional = None ):
660
+ def set_max_position_size (asset = None , max_shares = None , max_notional = None , on_error = 'fail' ):
632
661
"""Set a limit on the number of shares and/or dollar value held for the
633
662
given sid. Limits are treated as absolute values and are enforced at
634
663
the time that the algo attempts to place an order for sid. This means
0 commit comments