python - Python 错误:预期的 str、字节或 os.PathLike 对象,而不是 _io.TextIOWrapper
问题描述
我认为错误来自加载的 csv 文件。
我使用的代码是
data = pd.read_csv(r'C:\Users\CCHHR\Advanced-Trading-Analysis-Data.csv')
def TrendStrategyRun1(nfastSMA, nslowSMA, chart):
instruments = ['SPY']
feed = csvfeed.GenericBarFeed(bar.Frequency.DAY)
feed.addBarsFromCSV(
instruments[0],
data,
skipMalformedBars=True
)
trendStrategy1 = TrendStrategy(
feed,
instrument[0],
nfastSMA,
nslowSMA
)
trendStrategy1.getBroker().setCommission(
broker.backtesting.FixedPerTrade(6)
)
retAnalyzer = ret.Returns(maxLen=2518)
trendStrategy1.attachAnalyzer(retAnalyzer)
plt = plotter.StrategyPlotter(
trendStrategy1,
plotPortfolio=False
)
plt.getInstrumentSubplot('SPY').addDataSeries(
'Fast SMA',
trendStrategy1.getfastSMA()
)
plt.getInstrumentSubplot('SPY').addDataSeries(
'Slow SMA',
trendStrategy1.getslowSMA()
)
trendStrategy1.run()
datesReturns = retAnalyzer.getReturns().getDateTimes()[:]
dailyReturns = retAnalyzer.getReturns()[:]
dailyReturns = pd.DteFrame(dailyReturns).set_index(
pd.DatetimeIndex(datesReturns)
)
if chart == True:
plt.plot(
fromDateTime=dt.datetime(2016, 1, 1),
toDateTime=dt.datetime(2016, 12, 31)
)
return dailyReturns
TrendStrategyRun1(5, 20, True)
我收到以下错误消息
expected str, bytes or os.PathLike object, not _io.TextIOWrapper
有人可以告诉我错误来自哪里吗?
非常感谢
解决方案
推荐阅读
- flutter - 如何使用颤振从谷歌驱动器获取所有视频文件?
- intellij-idea - 关闭项目后 IntelliJ 内容根目录重置
- android - 颤振位置
- python - 如何找到使用 Pandas 最频繁和最不频繁的计数?
- kotlin - 从字符串拆分空间在 Kotlin 中不起作用
- pdf - 数字签名证书推荐
- python - 缓存 Django 页面以快速加载
- python - 如何在一行中编写嵌套的 if-elif-else 条件?
- git - Git - 从提交到主文件中永久排除文件(删除)
- symfony - 如何在我的项目 symfony 4 中卸载包 lexik / jwt-authentication-bundle