nickmccullum / algorithmic-trading-python

The repository for freeCodeCamp's YouTube course, Algorithmic Trading in Python
2.43k stars 2.42k forks source link

Problem with 'None' values in One-Year, Six-Month, Three-Month, One-Month Price Returns #2

Closed brucemontegani closed 3 years ago

brucemontegani commented 3 years ago

If any of the values in the One-Year, Six-Month, Three-Month, One-Month Price Returns is 'None' then the 'percentileofscore' function will error because it cannot match a float against a NoneType.

To fix this I added the following in the creation of the data series for each price return column. xxx is the time period:

float(0 if data[symbol]['stats']['xxxChangePercent'] is None else data[symbol]['stats']['xxxChangePercent'])

I am not sure if there is a better solution.

pawlmi commented 3 years ago

That works for me, thanks. there's also another recent solution added in Issues.

subnivean commented 3 years ago

As I said in #3:

This line before the loop will clear out any rows that contain null data in any column:

hqm_dataframe.dropna(inplace=True)
toddabraham commented 3 years ago

@subnivean solution seems to be the most straightforward fix to this issue.

nickmccullum commented 3 years ago

@subnivean has solved this, so i am closing the issue.