我有一个模块fi
,其中定义了以下类:
class Asset(metaclass=abc.ABCMeta):
pass
@abc.abstractmethod
def get_price(self, dt : datetime.date, **kwargs):
''' Nothing here yet
'''
class CashFlows(Asset):
def __init__(self, amounts : pandas.Series, probabilities : pandas.Series = None):
amounts = Asset.to_cash_flows()
然后我在其中有另一个类Bond(fi.Asset)
:
def to_cash_flows(self, notional : float = 100.0) -> fi.asset.CashFlows:
series = pandas.Series(list_of_data, indices_of_data)
return fi.CashFlows(series)
我致电TypeError: Can't instantiate abstract class CashFlows with abstract methods get_price
时收到错误to_cash_flows
。我已经看过this answer,但无法将其与我当前的问题联系起来。
谢谢
答案 0 :(得分:4)
您的CashFlows
课程需要定义get_price
的实施;它是一个抽象方法,具体的子类必须实现它。