获取JSONDecodeError:期望值:使用Python + Zipline + Docker + Jupyter的第1行第1列(字符0) [英] Getting JSONDecodeError: Expecting value: line 1 column 1 (char 0) with Python + Zipline + Docker + Jupyter

查看:168
本文介绍了获取JSONDecodeError:期望值:使用Python + Zipline + Docker + Jupyter的第1行第1列(字符0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Docker安装了Zipline和Jupyter:



同样,当我尝试运行程序时会发生这种情况。



可能是什么问题?



TIA



附录:

strong>
我也同样尝试过:
https://docs.google.com/document/d/1mvZO_JDirbJNXJfM0bTS9uMipHE5cfSGFj0sUpJIcsw/edit?usp=sharing

解决方案

<我知道这个问题已经解决了,但是我尝试了他们在github问题上提供的内容,但并没有帮助我,所以我愿意向我展示如何解决我的问题。


问题出在zipline的Benchmark.py文件(以及其他几个文件)中,该文件尝试从iex获取数据,但由于其功能更改而失败。

p>

我将向您展示如何运行示例代码:


(我假设您已经安装了zipline并运行了苹果的购买示例代码)


1.benchmark.py:查看计算机中的zipline文件夹(已下载的内容或安装的pip / conda)。打开Benchmark.py(首先找到它)并进行编辑,然后将整个代码更改为:

  import numpy as np 
import将pandas作为pd
导入pandas_datareader.data作为pd_reader
def get_benchmark_returns(symbol,first_date,last_date):
data = pd_reader.DataReader(
符号,
'yahoo' ,
first_date,
last_date


data = data ['Close']

data [pd.Timestamp('2008- 12-15')] = np.nan
data [pd.Timestamp('2009-08-11')] = np.nan
data [pd.Timestamp('2012-02-02' )] = np.nan

data = data.fillna(method ='ffill')

return data.sort_index()。tz_localize('UTC')。pct_change( 1).iloc [1:]

此代码摘自shlomikushchi github页面关于此问题。


2。接下来,打开文件:loaders.py,该文件也位于zipline中:


其中有一行调用函数:
(在代码中查找)


data = get_benchmark_returns(symbol


将其更改为:

  data = get_benchmark_returns(symbol,first_date,last_date)

3.open trading.py,也位于zipline文件夹中,在此行之后的
处:

  class SimulationParameters(object):
def __init __(self,start_session,end_session,
trading_calendar,
capital_base = DEFAULT_CAPITAL_BASE,
mission_rate ='daily',
data_frequency ='daily',
arena ='backtest'):

输入这些行:

  start_session = pd.Timestamp(start_session).tz_localize(tz ='US / Central')
end_session = pd.Timest amp(end_session).tz_localize(tz ='US / Central')

现在,当您在此处:


https://www.zipline.io /beginner-tutorial.html


I installed Zipline and Jupyter using Docker: https://github.com/quantopian/zipline/blob/master/Dockerfile

I am now trying to run the following Zipline code under Jupyter

%%zipline --bundle quantopian-quantl --start 2008-1-1 --end 2012-1-1 -o strat.pickle

from zipline.api import symbol, order, record

def initialize(context):
    pass

def handle_data(context, data):
    order(symbol('AAPL'), 10)
    record(AAPL=data[symbol('AAPL')].price)

The error message I am getting is:

**JSONDecodeError: Expecting value: line 1 column 1 (char 0)**

Here is the picture of the error:

Again, this takes place when I try to run the program.

What could the problem be? Any help, hints or advice is ~greatly~ appreciated!

TIA

Addendum: I have also tried this as well: https://docs.google.com/document/d/1mvZO_JDirbJNXJfM0bTS9uMipHE5cfSGFj0sUpJIcsw/edit?usp=sharing

解决方案

I know this question is sort of solved, but I tried what they are offering on the github issues and it did not help me, so I desided to show how I fixed my problem. Maybe it will help you.

The problem is in the benchmark.py file (and several others) of zipline where it tries to get data from iex and fails because their function changed.

I will show you what I did in order to get the sample code running:

(I assume you already have zipline installed and runnig ther apple buying sample code)

1.benchmark.py: look into your zipline folder in your computer (what you have downloaded or pip/conda installed). Open benchmark.py (find it first) and edit it, change the whole code there to this:

import numpy as np
import pandas as pd
import pandas_datareader.data as pd_reader
def get_benchmark_returns(symbol, first_date, last_date):
    data = pd_reader.DataReader(
        symbol,
        'yahoo',
        first_date,
        last_date
    )

    data = data['Close']

    data[pd.Timestamp('2008-12-15')] = np.nan
    data[pd.Timestamp('2009-08-11')] = np.nan
    data[pd.Timestamp('2012-02-02')] = np.nan

    data = data.fillna(method='ffill')

    return data.sort_index().tz_localize('UTC').pct_change(1).iloc[1:]

this code was taken from the answer of shlomikushchi github page about the issue. Here shlomikushchi switched the data source from iex to pandas, yahoo.

2.Next, open the file: loaders.py , also somewhere in zipline:

there is a row there in which they call the function: (look for this in the code)

data = get_benchmark_returns(symbol

change it to :

 data = get_benchmark_returns(symbol,first_date, last_date)

3.open trading.py , also somewhere in the zipline folder, after this line:

class SimulationParameters(object):
def __init__(self, start_session, end_session,
             trading_calendar,
             capital_base=DEFAULT_CAPITAL_BASE,
             emission_rate='daily',
             data_frequency='daily',
             arena='backtest'):

enter those lines:

start_session = pd.Timestamp(start_session).tz_localize(tz='US/Central')
    end_session = pd.Timestamp(end_session).tz_localize(tz='US/Central')

now it should work when you run the code in here:

https://www.zipline.io/beginner-tutorial.html

这篇关于获取JSONDecodeError:期望值:使用Python + Zipline + Docker + Jupyter的第1行第1列(字符0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆