Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.7 simple_simulator_usage.py: assert error #7

Open
Kerberos007 opened this issue Feb 6, 2021 · 5 comments
Open

4.7 simple_simulator_usage.py: assert error #7

Kerberos007 opened this issue Feb 6, 2021 · 5 comments

Comments

@Kerberos007
Copy link

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

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

@Kerberos007
Copy link
Author

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
Copy link

theAfricanQuant commented Sep 15, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants