Back to Community
UnicodeDecodeError:'ascii' codec can't decode byte 0xa0 in position 308: ordinal not in range(128) by handling csv file

Here is a small code to handle the equity put/call ratio csv file and there is no error.

Clone Algorithm
0
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
"""
This is a template algorithm on Quantopian for you to adapt and fill in.
"""
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import AverageDollarVolume
from quantopian.pipeline.filters.morningstar import Q1500US
from zipline.utils import tradingcalendar
from quantopian.pipeline.factors import CustomFactor
from quantopian.pipeline.filters import StaticAssets

import numpy as np
import pandas as pd
from pytz import timezone
import datetime
import math
import time
import re
import functools
import itertools
import talib

def initialize(context):
    """
    Called once at the start of the algorithm.
    """   
    
    context.stock = sid(8554) # SPY
    context.tema_period = 5
    
    context.pc_ratio_low = 0.45
    context.pc_ratio_high = 0.9
    
    context.slow_rainbow_period = 100
    
    # Rebalance every day, 1 hour after market open.
    schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(hours=1))
     
    # Record tracking variables at the end of each day.
    schedule_function(my_record_vars, date_rules.every_day(), time_rules.market_close())
    
    pcRatioUrl = 'http://www.cboe.com/publish/scheduledtask/mktdata/datahouse/equitypc.csv'
    fetch_csv(pcRatioUrl, 
              symbol= 'PC_RATIO', 
              skiprows=2,
              date_column='DATE')
    
def before_trading_start(context, data):
    """
    Called every day before market open.
    """
    log.info("\n--- New Day ---")
    
def my_assign_weights(context, data):
    """
    Assign weights to securities that we want to order.
    """
    pass
 
def my_rebalance(context,data):
    """
    Execute orders according to our schedule_function() timing. 
    """
    pass
 
def my_record_vars(context, data):
    """
    Plot variables at the end of each day.
    """
    pass

def handle_data(context,data):
    """
    Called every minute.
    """
    pass
There was a runtime error.
1 response

And here is the same code for handling VIX put/call ratio csv file. But I got error "UnicodeDecodeError:'ascii' codec can't decode byte 0xa0 in position 308: ordinal not in range(128) "

Line: 47 ininitialize
date_column='Date')

What could be the reason?

Thomas

Clone Algorithm
1
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
"""
This is a template algorithm on Quantopian for you to adapt and fill in.
"""
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import AverageDollarVolume
from quantopian.pipeline.filters.morningstar import Q1500US
from zipline.utils import tradingcalendar
from quantopian.pipeline.factors import CustomFactor
from quantopian.pipeline.filters import StaticAssets

import numpy as np
import pandas as pd
from pytz import timezone
import datetime
import math
import time
import re
import functools
import itertools
import talib

def initialize(context):
    """
    Called once at the start of the algorithm.
    """   
    
    context.stock = sid(8554) # SPY
    context.tema_period = 5
    
    context.pc_ratio_low = 0.45
    context.pc_ratio_high = 0.9
    
    context.slow_rainbow_period = 100
    
    # Rebalance every day, 1 hour after market open.
    schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(hours=1))
     
    # Record tracking variables at the end of each day.
    schedule_function(my_record_vars, date_rules.every_day(), time_rules.market_close())
    
    pcRatioUrl = 'http://www.cboe.com/publish/scheduledtask/mktdata/datahouse/vixpc.csv'    
    fetch_csv(pcRatioUrl, 
              symbol= 'PC_RATIO', 
              skiprows=1,
              date_column='Date')
    
def before_trading_start(context, data):
    """
    Called every day before market open.
    """
    log.info("\n--- New Day ---")
    
def my_assign_weights(context, data):
    """
    Assign weights to securities that we want to order.
    """
    pass
 
def my_rebalance(context,data):
    """
    Execute orders according to our schedule_function() timing. 
    """
    pass
 
def my_record_vars(context, data):
    """
    Plot variables at the end of each day.
    """
    pass

def handle_data(context,data):
    """
    Called every minute.
    """
    pass
There was a runtime error.