Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datecode not correct for "stocks".csv . (unsupported operand for "-") #3

Open
minertom opened this issue Dec 28, 2021 · 0 comments
Open

Comments

@minertom
Copy link

minertom commented Dec 28, 2021

This is probably an easy fix to correct.

In the "cvxpy-stocks.ipynb" notebook file, which I have downloaded locally, I am using the stocks file "bigmac.csv", to import my stock porfolio.

The line:
df_returns = df_stocks.set_index('date').diff()

Returns the error
TypeError: unsupported operand type(s) for -: 'str' and 'str'

I did try different permutations of the code, and interestingly, one version worked and another one did not.

The code in the example is close to this:
df_stocks = pd.read_csv("bigmac.csv").iloc[500:1800]
df_returns = df_stocks.set_index('date').diff()
mean_stock = df_returns.mean().values

It results in the error
TypeError: unsupported operand type(s) for -: 'str' and 'str'

However, the following code works:
df_stocks = pd.read_csv("bigmac.csv").iloc[500:1800]
df_returns = df_stocks.set_index('date')
differences = df_returns.diff' #**Note that diff here has no () following**
mean_stock = df_returns.mean()
values = mean_stock.values
print(values)

And the results are
[2029.88108208 723.91574523 3.5758786 ]

So, what is the difference between the two versions and why does yours work?

Thank You
Tom Cipollone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant