Skip to content

Assertion failure when panda backtesting for crypto asset #798

@rdv0011

Description

@rdv0011

A crash happens when the first order is made and the portfolio is updated:
lumibot/strategies/_strategy.py

def _update_portfolio_value(self):

price = self.broker.data_source.get_last_price(asset.symbol) <- crashes because asset is a tuple for the crypto asset

This is a possible patch to fix it:

diff lumibot/lumibot/strategies/_strategy.py /opt/homebrew/anaconda3/envs/traidingbot/lib/python3.12/site-packages/lumibot/strategies/_strategy.py
60d59
<     LOG_ERRORS_TO_CSV,
668d666
<                     asset_is_option = False
671,674c669,671
<                     elif asset.asset_type == "option":
<                         asset_is_option = True
< 
<                     if self.broker.option_source is not None and asset_is_option:
---
>                         price = self.broker.data_source.get_last_price(asset)
>                         prices[asset] = price
>                     elif asset.asset_type == "option" and self.broker.option_source is not None:
678c675
<                         price = self.broker.data_source.get_last_price(asset)
---
>                         price = self.broker.data_source.get_last_price(asset.symbol)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions