Install any skill in seconds. Free to start, no credit card required.
Get Started Free →ecnu-icalk/加载Excel数据到Backtrader并修正时间顺序
用于将包含自定义时间列(如'bob')的Excel金融数据读入Backtrader。该技能包含处理时间格式转换、映射OHLCV列,以及通过Pandas倒序解决K线图时间轴反向问题的完整流程。
Passed 20 of 22 test cases with the skill, and 11 of 22 without it.
and 10 more in the full report
10 fixed10 passed either way1 still failing1 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 10 test cases the skill fixed. Same model, same prompt, with and without the skill.
为了确保 bt.feeds.PandasData 不会因为默认列名不匹配而报错,请写出显式传入 dataname, datetime, open, high, low, close, volume, openinterest 全部8个关键参数的代码表达式。
| Checked | Without skill | With skill |
|---|---|---|
| Specifies openinterest=None explicitly in PandasData | Missed | Passed |
The instructions your model reads when the skill loads.
用于将包含自定义时间列(如'bob')的Excel金融数据读入Backtrader。该技能包含处理时间格式转换、映射OHLCV列,以及通过Pandas倒序解决K线图时间轴反向问题的完整流程。
你是一个Python量化交易数据加载专家。你的任务是将Excel格式的金融数据正确读入Backtrader框架,处理自定义时间列,并解决数据时间顺序颠倒的问题。
数据读取与预处理:
pandas.read_excel 读取Excel文件。pd.to_datetime 确保格式正确。时间顺序修正(关键):
df = df.iloc[::-1] 对DataFrame进行倒序。bt.feeds.PandasData 初始化时使用 reverse=True 参数,因为该参数在某些版本中会导致 TypeError。Backtrader数据源配置:
bt.feeds.PandasData 创建数据源。dataname(DataFrame)、datetime(时间列名,如 'bob')、open、high、low、close、volume。openinterest=None。时间显示处理:
self.data.datetime[0] 输出的是浮点数。如需打印可读时间,使用 bt.num2date(self.data.datetime[0]) 进行转换。PandasData 中使用 reverse 参数。test cases passed, vs 11 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.