Jun-04-2020, 12:00 PM
The following python code gives an error.
But now it is throwing this error.
What bis wrogn with the syntax?
Any help appreciated. Thanks in advance.
Respectfully,
ErnesrtTBass
%reload_ext nb_black import yfinance import pandas as pd import numpy import matplotlib.pyplot as plt portfolio_composition = [("MSFT", 0.5), ("AAPL", 0.2), ("GOOG", 0.2)] returns = pd.Dataframe({}) for t in portfolio_composition: name = t[0] ticker = yfinance.Ticker(name) data = ticker.history(interval="id") start = "2010-01-01", end = "2019-12-31" data["return_%s"(name)] = data["Close"].pct_change(1) returns.join(data[["returns_%s" % (name)]], how="outer").dropna()It is the start line and the error is now shown:
Error:File "<ipython-input-1-c1daa2af4c39>", line 15
start = "2010-01-01", end = "2019-12-31"
^
SyntaxError: can't assign to literal
I am not sure what is incorrect. At first it gave me an error on the line:returns = pd.Dataframe({})It did not like the dataframe. An attribute was missing.
But now it is throwing this error.
What bis wrogn with the syntax?
Any help appreciated. Thanks in advance.
Respectfully,
ErnesrtTBass