chrisconlan / algorithmic-trading-with-python

Source code for Algorithmic Trading with Python (2020) by Chris Conlan
Other
2.75k stars 501 forks source link

4.7 simple_simulator_usage.py: assert error #7

Open Kerberos007 opened 3 years ago

Kerberos007 commented 3 years ago

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 commented 3 years ago

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

chrisconlan commented 3 years ago

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 commented 3 years ago

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

Kerberos007 commented 3 years ago

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

theAfricanQuant commented 3 years ago

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