question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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] image

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
rubikcommented, Jul 2, 2017

@pmorissette I am getting the same error… With bt version (0, 2, 5):

Exception: Cannot allocate capital to weights because price is 0 as of 2016-04-25 00:00:00

EDIT: Found the problem: the weights dataframe had a column name that didn’t match the one in the price dataframe. So bt was getting confused.

0reactions
tlfmcoopercommented, Apr 17, 2022

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found