Exception: Cannot allocate capital to close-002142 because price is 0 as of 2008-12-03 00:00:00
See original GitHub issue[issue] When executing the code “bt.run(strategy2)” , It raise the “Exception: Cannot allocate capital to close-002142 because price is 0 as of 2008-12-03 00:00:00” , but the price of ‘close-002142’ is not zero as of 2008-12-03. Then I debug the code, but it is blocked when it call “target.rebalance(item[1], child=item[0], base=base)” (shown as picture). [question] Could you tell me which function`s the ‘target.rebalance’ calling ?
[The Coding] class Rebalance(Algo):
"""
Rebalances capital based on temp['weights']
Rebalances capital based on temp['weights']. Also closes
positions if open but not in target_weights. This is typically
the last Algo called once the target weights have been set.
I got the error :
Exception: Cannot allocate capital to close-002142 because price is 0 as of 2008-12-03 00:00:00
Requires:
* weights
"""
def __init__(self):
super(Rebalance, self).__init__()
def __call__(self, target):
if 'weights' not in target.temp:
return True
targets = target.temp['weights']
# de-allocate children that are not in targets
not_in = [x for x in target.children if x not in targets]
for c in not_in:
target.close(c)
# save value because it will change after each call to allocate
# use it as base in rebalance calls
base = target.value
for item in iteritems(targets):
~~target.rebalance(item[1], child=item[0], base=base)~~
return True
[picture]
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pmorissette I am getting the same error… With
bt
version(0, 2, 5)
:EDIT: Found the problem: the
weights
dataframe had a column name that didn’t match the one in the price dataframe. Sobt
was getting confused.@pmorissette You have to make sure that the signal data frame and the time series data frame have the same column name For instance, let’s say you have an apple dataframe with close price only. You could rename the dataframe by changing close to appl_whatever_strategy. You might have a signal dataframe with maybe a column name signal. You need to rename that column the appl_whatever_strategy as well and it wil work!