context.i += 1
if context.i < 300:
return
# Compute averages
# data.history() has to be called with the same params
# from above and returns a pandas dataframe.
short_mavg = data.history(context.asset, 'price', bar_count=100, frequency="1d").mean()
long_mavg = data.history(context.asset, 'price', bar_count=300, frequency="1d").mean()
# Trading logic
if short_mavg > long_mavg:
# order_target orders as many shares as needed to
# achieve the desired number of shares.
order_target(context.asset, 100)
elif short_mavg < long_mavg:
order_target(context.asset, 0)
# Save values for later inspection
record(AAPL=data.current(context.asset, 'price'),
short_mavg=short_mavg,
long_mavg=long_mavg)
`
And I get the below error:
Traceback (most recent call last):
File "/Users/ryanalex/PycharmProjects/scientificProject/.venv/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3577, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
runfile('/Users/ryanalex/Dropbox/Python/Maschine_Learning_Jansen/zipline_tutorial.py', wdir='/Users/ryanalex/Dropbox/Python/Maschine_Learning_Jansen')
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/ryanalex/Dropbox/Python/Maschine_Learning_Jansen/zipline_tutorial.py", line 2, in
import zipline
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, *kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ryanalex/Dropbox/Python/Maschine_Learning_Jansen/zipline.py", line 12, in
from zipline.api import (
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'zipline.api'; 'zipline' is not a package
...
What steps have you taken to resolve this already?
I have tried
uninstalling and reinstalling
I tried on my Windows computer as well with the same result, also using PyCharm
I have tried different versions of zipline_reloaded
I tried importing zipline_reloaded instead of zipline
...
Anything else?
This may be a PyCharm issue. It feels like
...
Sincerely,
Real name is Ryan and I am reading your book on Machine Learning, it is a great book. Thank you for all you do within the community.
Dear Zipline Maintainers,
Before I tell you about my issue, let me describe my environment:
Environment
Now that you know a little about me, let me tell you about the issue I am having:
Description of Issue
I have tried to run several different zipline programs and recienve the same error. I did this also on my Windows machine with the same error.
Here is how you can reproduce this issue on your machine:
Reproduction Steps
I run the zipline tutorial: ` import zipline from zipline import order_target, record, symbol
def initialize(context): context.i = 0 context.asset = symbol('AAPL')
def handle_data(context, data):
Skip first 300 days to get full windows
` And I get the below error: Traceback (most recent call last): File "/Users/ryanalex/PycharmProjects/scientificProject/.venv/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3577, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in
runfile('/Users/ryanalex/Dropbox/Python/Maschine_Learning_Jansen/zipline_tutorial.py', wdir='/Users/ryanalex/Dropbox/Python/Maschine_Learning_Jansen')
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/ryanalex/Dropbox/Python/Maschine_Learning_Jansen/zipline_tutorial.py", line 2, in
import zipline
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, *kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ryanalex/Dropbox/Python/Maschine_Learning_Jansen/zipline.py", line 12, in
from zipline.api import (
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'zipline.api'; 'zipline' is not a package
...
What steps have you taken to resolve this already?
I have tried
...
Anything else?
This may be a PyCharm issue. It feels like ...
Sincerely, Real name is Ryan and I am reading your book on Machine Learning, it is a great book. Thank you for all you do within the community.