在这个项目中,我有两个类:
class StockEntity:
def __init__(self, ticker, exchange = 'NASDAQ'):
self.ticker = ticker
self.exchange = exchange
# Get the history
ticker = yf.Ticker(self.ticker)
self.stock_hist = ticker.history(period = "max")
class Curve(StockEntity):
def __init__(self, ticker, startdate, type_of_curve, hierarchy_order):
self.ticker = StockEntity.ticker
self.startdate = startdate
self.type_of_curve = type_of_curve
self.hierarchy_order = hierarchy_order
self.stock_hist = StockEntity.stock_hist
这里的概念是,StockEntity的每个实例都有一个股票代码和股票交易数据的历史记录。
所以我会说AAPL = StockEntity('AAPL')。这很好用。如果我想制作交易数据的图表,我可以简单地使用AAPL.stock_hist中的值,它为我提供了一个可处理的数据框架。
现在,对于每个股票,我还希望能够根据计算创建曲线。
所以我创建了另一个类Curve,在那里我传递了一个StockEntity对象作为属性,其想法是,虽然我需要Curve类的对象来让' AAPL‘本身成为一个对象(一个对象的实例),但使用位于AAPL对象中的相同数据是有意义的。
然而,当我这样做的时候:
AAPL = StockEntity('AAPL')
然后做
AAPL_curve =曲线(AAPL,'2020-01-01','S',1)我收到一个错误,说"AttributeError:类型对象'Stock_entity‘没有’ticker‘属性“
哈?
如果我输入'AAPL.ticker‘,它会像预期的那样返回'AAPL’!因此,毫无疑问,该属性是存在的。
这里我漏掉了什么?我是不是做错了?
发布于 2020-06-16 21:19:41
class Curve():
def __init__(self, stock, startdate, type_of_curve, hierarchy_order):
self.ticker = stock.ticker
self.startdate = startdate
self.type_of_curve = type_of_curve
self.hierarchy_order = hierarchy_order
self.stock_hist = stock.stock_hist
尝试将股票实体作为属性进行传递?
https://stackoverflow.com/questions/62403407
复制相似问题