Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8345973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:51:33+00:00 2026-06-09T06:51:33+00:00

I keep getting the same ValueError for the following code and I am having

  • 0

I keep getting the same ValueError for the following code and I am having a hard time understanding why the error is being generated. It is my understanding that this error is generated when the wrong value is passed into a function, however, I do not really understand what this error is telling me. I’ve spent time searching online and in the docs, but I am unable to understand what I am doing wrong. Simply, why is this error being generated?

My code:

import datetime
import ystockquote

def new_time(n):
    fmt = "%Y%m%d"
    end_date1 = datetime.datetime.strptime(n, fmt)
    sixty_day = datetime.timedelta(days=60)
    start_date  = end_date1 - sixty_day
    start_date1 = str(start_date)
    start_date2 = start_date1[:4] + start_date1[5:7] + start_date1[8:10]
    return start_date2

def average_atr():
    print "Enter your stock symbol: "
    symbol      = raw_input(" ")
    print "Enter the end date in (YYYYMMDD) format: "
    end_date    = raw_input(" ")
    start_date  = new_time(end_date)
    initial_list = ystockquote.get_historical_prices('symbol', 'start_date', 'end_date')

def start():
    average_atr()

start()

This is the relevant code for ystockquote:

def get_historical_prices(symbol, start_date, end_date):
    """
    Get historical prices for the given ticker symbol.
    Date format is 'YYYYMMDD'

    Returns a nested list.
    """
    url = 'http://ichart.yahoo.com/table.csv?s=%s&' % symbol + \
          'd=%s&' % str(int(end_date[4:6]) - 1) + \
          'e=%s&' % str(int(end_date[6:8])) + \
          'f=%s&' % str(int(end_date[0:4])) + \
          'g=d&' + \
          'a=%s&' % str(int(start_date[4:6]) - 1) + \
          'b=%s&' % str(int(start_date[6:8])) + \
          'c=%s&' % str(int(start_date[0:4])) + \
          'ignore=.csv'
    days = urllib.urlopen(url).readlines()
    data = [day[:-2].split(',') for day in days]
    return data

Please note that the ystockquote code above is not the complete code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:51:35+00:00Added an answer on June 9, 2026 at 6:51 am

    In the function average_atr(), change the following line:

    initial_list = ystockquote.get_historical_prices('symbol', 'start_date', 'end_date')
    

    to:

    initial_list = ystockquote.get_historical_prices(symbol, start_date, end_date)
    

    In your current version, instead of passing the variables into ystockquote.get_historical_prices(), you are passing literal strings with the variable names. This is resulting in str(int(end_date[4:6]) - 1) with the variable end_date having the value 'end_date', and 'end_date'[4:6] is 'da'.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having a hard time understanding custom events and I keep getting this same
I keep getting a Run Time error that says I am having an Exception
I am having some issues with my code, and keep getting the same error,
I keep getting the same error: Missing Operator. I have looked over this code
I keep getting the same vague error with this code: command.CommandText = INSERT INTO
I keep getting this error. I am using Mac. I generated a key and
I'm having trouble with python. I keep getting the same error: Traceback (most recent
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
I keep getting this error and have no idea why. I googled and scanned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.