finrl-meta
d:\AI\FinRL-Meta\meta\env_stock_trading\env_stocktrading_China_A_shares.py
File d:\AI\FinRL-Meta\meta\env_stock_trading\env_stocktrading_China_A_shares.py:513, in StockTradingEnv.initial_buy_(self)
511 buy_nums_each_tic = [int(market_values_each_tic // p) for p in prices]
512 if self.hundred_each_trade:
–> 513 buy_nums_each_tic = buy_nums_each_tic // 100 * 100
515 buy_amount = sum(np.array(prices) * np.array(buy_nums_each_tic))
517 state = (
518 [self.initial_amount - buy_amount]
519 + prices
(…)
524 )
525 )

TypeError: unsupported operand type(s) for //: ‘list’ and ‘int’
应该使用列表推导式

File d:\AI\FinRL-Meta\meta\env_stock_trading\env_stocktrading_China_A_shares.py:433, in StockTradingEnv._get_date(self)
431 def _get_date(self):
432 if len(self.df.tic.unique()) > 1:
–> 433 date = self.data.date.unique()[0]
434 else:
435 date = self.data.date

File d:\Python\Python311\Lib\site-packages\pandas\core\generic.py:6299, in NDFrame.getattr(self, name)
6292 if (
6293 name not in self._internal_names_set
6294 and name not in self._metadata
6295 and name not in self._accessors
6296 and self._info_axis._can_hold_identifiers_and_holds_name(name)
6297 ):
6298 return self[name]
-> 6299 return object.getattribute(self, name)

AttributeError: ‘DataFrame’ object has no attribute ‘date’
查看了原df,应该改成time,推荐loc


AttributeError Traceback (most recent call last)
Cell In[25], line 6
4 trade.to_csv(“trade.csv”, index=False)
5 plotter = ReturnPlotter(df_account_value, trade, TRADE_START_DATE, TRADE_END_DATE)
—-> 6 plotter.plot()

File d:\AI\FinRL-Meta\meta\data_processors\tushare.py:222, in ReturnPlotter.plot(self, baseline_ticket)
218 days_per_tick = (
219 60 # you should scale this variable accroding to the total trading days
220 )
221 time = list(range(len(ours)))
–> 222 datetimes = self.df_account_value.time.tolist()
223 ticks = [tick for t, tick in zip(time, datetimes) if t % days_per_tick == 0]
224 plt.title(“Cumulative Returns”)

File d:\Python\Python311\Lib\site-packages\pandas\core\generic.py:6299, in NDFrame.getattr(self, name)
6292 if (
6293 name not in self._internal_names_set
6294 and name not in self._metadata
6295 and name not in self._accessors
6296 and self._info_axis._can_hold_identifiers_and_holds_name(name)
6297 ):
6298 return self[name]
-> 6299 return object.getattribute(self, name)

AttributeError: ‘DataFrame’ object has no attribute ‘time’
time改成date