Skip to content

Bug in Python for Finance #2

Description

@charliemcelfresh

Hi Derek, thanks for your awesome videos!

In Python for Finance
https://www.youtube.com/watch?v=nNkKTJTu-mU&list=PLGLfVvz_LVvTHOWIEBAl-YOr_FC8lRmWX

your output shows that Amazon's stock price rose by ~18% in 2020; I think by your calculation in

def get_return_defined_time:

the number should be 0.6166401575831238

The bug is in your date formatting. Where you compare a date formatted like this:

start = f"{syear}-{smonth}-{sday}"

which look like this:

2020-1-1

with dates in your dataframes that look like this:

2020-01-01

your date comparison fails much of the time.

I think if you change your date formatting from this:

start = f"{syear}-{smonth}-{sday}"

to this

start = dt.datetime(syear, smonth, sday).strftime("%Y-%m-%d")

you will be good to go!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions