Open trevor-richardson opened 4 years ago
You can use the csvdir.py and extensions.py files to register your bundle if you have personal data and your algo.
@cemal95 my bundle is already registered. I used the extensions.py file to register it. Is there anyway to check if it is registered correctly besides what I show above which is the output from zipline bundles?
currently I dont know how to check. Did you make sure that your data is in the right file, sometimes they forget to provide the right path? It says in the blog to use this command to check if it is regestered: !zipline bundles
Maybe show your code?
@cemal95 I didn't write any code. I am using the code inside /zipline/examples/buyapple.py (which is provided by zipline). The repo is inside my anaconda environment folder. I ran the following command which should execute that strategy on my bundle. Here is the command:
zipline run -f
Hey sorry for the late reply, I ran the example. I used the bundle='quandl'. And added the run_algorithm() function and it worked. Did you check the data maybe, did you download it?
Also, the example only has specific dates on it, the algo runs in the year 2014. If you look at the last method. So maybe thats why, you provided the data maybe, but the time is wrong?
The first three lines of the csv file I'm using as a custom bundle is printed out above. That custom bundle has data from 2017-2019. This has been confirmed. I really appreciate your help but I don't think I'm conveying the problem to you properly....we can just close this (unanswered). This isn't progressing for me. I can write the python script myself to backtest (simple loop over the data accounting for dates and such). Writing backtest myself (super simple) will be faster than debugging I think. Thanks!
@cemal95 I really like the code you pasted! Thanks for helping out on this journey!
My pleasure man, also on my THESIS repo, I have a short intro on how to use it on jupyter notebook. Also gonna upload my thesis algos.
I still haven't figured out how to use custom bundles but I thought you should know your sample code helped me get the initial algorithm running with quandl data! Call this effectively closed. Two weird things. I had to edit benchmarks.py in the /zipline/data/ filepath so that json errors weren't occuring. they talk about this issue on other issues pages sorry I can't remember which one exactly and I had to add the quandl api key to export in .bashrc. It has been a journey to say the least. Not like downloading pytorch or matplotlib which just work.... I will definitely check out your thesis repo. Thanks again!
Alrighty, cool man. Wish you all the best bro. Please let me know if something can be done to improve on something :)
Hello, guys Im doing my first code, unfortunately Im having a lot problems with my code. I already bundle my data in custom-bundle
#%%
import pandas as pd
import zipline
import pytz
import numpy as np
from analysis import create_benchmark, analyze
from zipline.api import order_percent, symbols, order, record, order_target_percent, symbol, schedule_function, date_rules, time_rules
from zipline.finance import commission
from datetime import datetime
from matplotlib import pyplot as plt, ticker, rc
import trading_calendars as tc
#%%
def initialize(context):
context.set_commission(commission.PerShare(cost=0.0, min_trade_cost=0))
context.assets= symbols('HGRE11','KNRI11','BPFF11','XPCM11','MXRF11')
context.n_assets=len(context.assets)
context.has_position= False
def handle_data(context, data):
if not context.has_position:
for asset in context.assets:
if data.can_trade(asset):
order_percent(asset, 1/context.n_assets)
context.has_position= True
result = zipline.run_algorithm(
start=start, # Set start
end=end, # Set end
initialize=initialize, # Define startup function
capital_base=100000, # Set initial capital
data_frequency = 'daily', # Set data frequency
bundle='custom-bundle', # Select bundle
trading_calendar= tc.get_calendar('BVMF'),
benchmark_returns=bench_series)
fig, ax =plt.subplots(1, 1, sharex=True, figsize=[16,9])
#Portafolio value
result.portfolio_value.plot(ax=ax[0])
ax[0].set_ylabel('Portafolio value in$')
plt.legend()
plt.show()
However, I got zero values in the result file. Im using jupyter to run Zipline. Any clue about this issue?
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
The intro tutorial run on a custom bundle doesn't work. I had to make a custom bundle because quandl won't accept my emails (it says my work email is not a work email). I followed this tutorial to set up my custom bundle -- https://towardsdatascience.com/introduction-to-backtesting-trading-strategies-7afae611a35e
Here are the first couple of lines from csv file cat to terminal. /AlgorithmicTrading$ cat aapl_daily/AAPL.csv date,open,high,low,close,volume,dividend,split 2017-01-03,115.80000305175781,116.33000183105469,114.76000213623047,116.1500015258789,28781900,0,0 2017-01-04,115.8499984741211,116.51000213623047,115.75,116.0199966430664,21118100,0,0
I know have the following bundles: apple-prices-2017-2019 2020-06-05 12:49:38.522678 apple-prices-2017-2019 2020-06-05 11:47:48.113717 apple-prices-2017-2019 2020-06-05 11:37:22.842459 apple-prices-2017-2019 2020-06-05 11:08:31.692111 ayx-prices-2019-2020 2020-06-04 13:17:20.079053 ayx-prices-2019-2020 2020-06-04 13:16:18.612500 ayx-prices-2019-2020 2020-06-04 12:45:41.304859 csvdir
quandl
quantopian-quandl
I run the following command on your buyapple example
zipline run -f/anaconda3/pkgs/zipline-1.3.0-np114py35_0/lib/python3.5/site-packages/zipline/examples/buyapple.py --bundle apple-prices-2017-2019 --start 2017-1-1 --end 2018-1-1 -o backtest.pickle
Almost all of the values in the resulting pickle are zero. And the profit is a flat line
Here is how you can reproduce this issue on your machine:
Reproduction Steps
Made a new conda environment. Installed zipline registered new bundle run zipline run command visualize that nothing happened except for tracking stock price (attached image shows this) ...
What steps have you taken to resolve this already?
I've tried python 3.5 and 2.7. I've tried jupyter notebook. I've tried following this peron's exact blog https://towardsdatascience.com/introduction-to-backtesting-trading-strategies-7afae611a35e
I cannot seem to get the backtest to work using any intro strategies.
Thank you!
...
Sincerely, Trevor Richardson