爲什麼此代碼會給出以下錯誤?如何將數據框傳遞給對象的方法?
TypeError: simple_returns() takes 1 positional argument but 2 were given
import datetime as dt
import math
from matplotlib import style
import numpy as np
import pandas as pd
import pandas_datareader.data as web
start = dt.datetime(2000, 1, 1)
end = dt.datetime(2016, 12, 31)
df = web.DataReader('TSLA', 'yahoo', start, end)
class CalcReturns:
def simple_returns(self):
simple_ret = self.pct_change()
return simple_ret
def log_returns(self):
simple_ret = self.pct_change()
log_ret = np.log(1 + simple_ret)
return log_ret
myRet = CalcReturns()
c = df['Adj Close']
sim_ret = myRet.simple_returns(c)
print(sim_ret)
謝謝Parfait。你是對的。偉大的圖標! – Leigh