algorithmic-trading-with-python icon indicating copy to clipboard operation
algorithmic-trading-with-python copied to clipboard

4.7 simple_simulator_usage.py: assert error

Open Kerberos007 opened this issue 4 years ago • 5 comments

I bought the book.

trying to reproduce all the simulator results.

everything looked good with position class & portfolio class, until I encountered the below assertion error, when running the simple_simulator_usage.py.

using all of the csv files you provided. can't continue with this error. I have not even tried my own portfolio simulation yet. Is this a known issue? thanks in advance,

in _compute_equity_series(self) 64 c_series = self.cash_series 65 p_series = self.portfolio_value_series ---> 66 assert all(c_series.index == p_series.index), 'portfolio_series has dates not in cash_series' 67 self._equity_series = c_series + p_series

ValueError: Lengths must match.,

Kerberos007 avatar Feb 06 '21 01:02 Kerberos007

printed below debug info: c_series index and p_series index were out of sync: len(c_series) = 646 len(p_series) = 2446

=================== c_series = 2010-02-03 0.000000 2010-02-04 0.000000 2010-03-15 0.000000 2010-03-23 12154.805956 2010-03-25 0.000000 ...
2019-12-11 0.000000 2019-12-12 0.000000 2019-12-17 0.000000 2019-12-19 0.000000 2019-12-31 49087.152584 Length: 646, dtype: float64

p_series = 2010-02-03 9995.002499 2010-02-04 9697.378387 2010-02-05 9860.704993 2010-02-08 9640.714054 2010-02-09 9625.159139 ...
2019-12-24 49012.704994 2019-12-26 49390.718144 2019-12-27 49147.709690 2019-12-30 48934.702281 2019-12-31 0.000000 Length: 2446, dtype: float64

Kerberos007 avatar Feb 06 '21 02:02 Kerberos007

Hi @Kerberos007, please try running the corresponding code in this file: https://github.com/chrisconlan/algorithmic-trading-with-python/blob/master/src/simulate_portfolio.py

chrisconlan avatar Feb 08 '21 17:02 chrisconlan

It is the similar to listing 4.7 but does not throw the error you described.

chrisconlan avatar Feb 08 '21 17:02 chrisconlan

Thanks.

I got the same error.

ValueError: Lengths must match.

c_series index and p_series index were out of sync:

len(c_series) = 646 len(p_series) = 2446

Kerberos007 avatar Feb 10 '21 04:02 Kerberos007

I am trying to adapt the same code to my FOREX trades and I am getting all sorts of errors too. "AttributeError: 'NoneType' object has no attribute 'strftime'"

I have change the datetypes and all but still no show. either I get 'str' object has no attribute 'strftime' or I get the above.

image

theAfricanQuant avatar Sep 15 '21 08:09 theAfricanQuant