jeudi 20 avril 2017

How to pass a dataframe to the method of an object?

Why does this code give the following error: 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 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)


0 commentaires:

Enregistrer un commentaire