以下代码在 python shell 中运行良好,显示提要对象的内容:
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
strategy.BacktestingStrategy.__init__(self, feed)
self.__instrument = instrument
def onBars(self, bars):
bar = bars[self.__instrument]
self.info(bar.getClose())
feed = yahoofeed.Feed()
feed.addBarsFromCSV("orcl","data/bistampTicker.csv")
myStrategy = MyStrategy(feed, "orcl")
myStrategy.run()
但是,它在 Django 视图中的执行会导致以下错误:
'function' object has no attribute 'BacktestingStrategy'
其中 BacktestingStrategy 是在 python 模块的 strategy 文件夹内的 __init__.py 文件中定义的类,位于 python 路径内。
我对这个问题的理解是 django 没有读取 __ init__.py 文件,因此没有正确导入模块(一个 pyalgotrade 模块)。
有没有办法告诉 Django 这样做?
在此先感谢,并对这个愚蠢的问题感到抱歉。
干杯