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

Chapter 8 02_backtesting_with_zipline #305

Closed
lyubomir-vasilev opened this issue Aug 27, 2023 · 1 comment
Closed

Chapter 8 02_backtesting_with_zipline #305

lyubomir-vasilev opened this issue Aug 27, 2023 · 1 comment

Comments

@lyubomir-vasilev
Copy link

I am using the code from Chapter 8 of the ML4T book by Stefan Jansen. The file I am using is 02_backtesting_with_zipline

Unfortunately, when running this code:

start = time()
results = run_algorithm(start=start_date,
                       end=end_date,
                       initialize=initialize,
                       before_trading_start=before_trading_start,
                       capital_base=1e6,
                       data_frequency='daily',
                       bundle='quandl',
                       custom_loader=signal_loader) # need to modify zipline

print('Duration: {:.2f}s'.format(time() - start))
```
`
I get this error:
```
``AttributeError                            Traceback (most recent call last)
c:\Lyubo\Python lessons\Machine-Learning-for-Algorithmic-Trading-Second-Edition-master\08_ml4t_workflow\04_ml4t_workflow_with_zipline\02_backtesting_with_zipline.ipynb Cell 55 in ()
      1 start = time()
----> 2 results = run_algorithm(start=start_date,
      3                        end=end_date,
      4                        initialize=initialize,
      5                        before_trading_start=before_trading_start,
      6                        capital_base=1e6,
      7                        data_frequency='daily',
      8                        bundle='quandl',
      9                        custom_loader=signal_loader) # need to modify zipline
     11 print('Duration: {:.2f}s'.format(time() - start))

File c:\ProgramData\anaconda3\envs\py38class\lib\site-packages\zipline\utils\run_algo.py:397, in run_algorithm(start, end, initialize, capital_base, handle_data, before_trading_start, analyze, data_frequency, bundle, bundle_timestamp, trading_calendar, metrics_set, benchmark_returns, default_extension, extensions, strict_extensions, environ, custom_loader, blotter)
    393 load_extensions(default_extension, extensions, strict_extensions, environ)
    395 benchmark_spec = BenchmarkSpec.from_returns(benchmark_returns)
--> 397 return _run(
    398     handle_data=handle_data,
    399     initialize=initialize,
    400     before_trading_start=before_trading_start,
    401     analyze=analyze,
    402     algofile=None,
    403     algotext=None,
    404     defines=(),
...
   5987 ):
   5988     return self[name]
-> 5989 return object.__getattribute__(self, name)

AttributeError: 'Series' object has no attribute 'append'
```
``

I followed the link to the file that gives the error:
```
File c:\ProgramData\anaconda3\envs\py38class\lib\site-packages\zipline\utils\run_algo.py:397, in run_algorithm(start, end, initialize, capital_base, handle_data, before_trading_start, analyze, data_frequency, bundle, bundle_timestamp, trading_calendar, metrics_set, benchmark_returns, default_extension, extensions, strict_extensions, environ, custom_loader, blotter)


However, I can't see append anywhere in the function itself, so I guess the funciton is dependent on another function in a different package. 

Does anyone know how I can fix this? 





I tried to change the code in the source and basically changed the code of any .py file in the pacakge which has append in it but that didn't work either. 


@stefan-jansen
Copy link
Owner

stefan-jansen commented Sep 2, 2023

.append() has been removed in pandas 2.0, please adjust the code to use pd.concat instead docs. A simple word search in the referenced file surfaces two instances where .append() is used.

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

2 participants