Closed Daiiszuki closed 1 year ago
I tried to implement https://github.com/AI4Finance-Foundation/FinRL-Meta/blob/master/tutorials/2-Advance/FinRL_PortfolioAllocation_Explainable_DRL.ipynb for crypto portfolio allocation, but got
AttributeError Traceback (most recent call last) [<ipython-input-103-4fbf8c9df76f>](https://localhost:8080/#) in <module> 12 13 ---> 14 cryptoEnv =cryptoPortfolioAllocationEnvironment(path=PATH, **envKwargs) 1 frames [<ipython-input-102-10be5fc69e51>](https://localhost:8080/#) in <listcomp>(.0) 39 self.frame = self.dataFrame.loc[self.dateIncriment, :] 40 self.covarianceList = self.frame['covarianceList'][0] ---> 41 self.stateVar = np.append(np.array(self.covarianceList),[self.frame[indic].values.tolist() for indic in self.indicatorList],axis=0) 42 #self.state = np.append(np.array(self.covs), [self.data[tech].values.tolist() for tech in self.tech_indicator_list ], axis=0) 43 AttributeError: 'numpy.float64' object has no attribute 'values'`
The data is in a csv as follows;
and my environment:
class cryptoPortfolioAllocationEnvironment(gym.Env): metadata = {'render.modes': ['human']} def __init__(self, path, cryptoDimension, maxCryptos, startingCapital, transactionFeePercentage, agentRewardFactor, stateSpace, actionSpace, indicatorList, turbulance=None, lookbackPeriod=252, dateIncriment = 0): self.dateIncriment = dateIncriment self.lookbackPeriod = lookbackPeriod self.dataFrame = panda.read_csv(path) self.cryptoDimension = cryptoDimension self.maxCryptos = maxCryptos self.startingCapital = startingCapital self.transactionFeePercentage = transactionFeePercentage self.agentRewardFactor = agentRewardFactor self.stateSpace = stateSpace self.actionSpace = actionSpace self.indicatorList = indicatorList self.turbulance=None self.actionSpace = spaces.Box(low = 0, high = 1, shape=(self.actionSpace,)) print(actionSpace) self.observationSpace = spaces.Box( low=np.inf, high = np.inf, shape = ( self.stateSpace+ len(indicatorList), stateSpace)) self.frame = self.dataFrame.loc[self.dateIncriment, :] self.covarianceList = self.frame['covarianceList'][0] self.stateVar = np.append(np.array((self.covarianceList),[self.frame[indic].values.toList() for indic in self.indicatorList],axis=0)) self.term =False self.turbulance=turbulance self.portfolioValue = self.startingCapital self.portfolioHistory = [self.startingCapital] self.portFolioReturnHistory = [0] self.actionHistory = [[[1/cryptoDimension] * cryptoDimension]] self.dateHistory = [self.frame.date.unique()[0]]
The error occurs with the following params;
envKwargs = { "maxCryptos": 5, "startingCapital": 1000000, "transactionFeePercentage": 0.001, "stateSpace": stateSpace, "cryptoDimension": cryptoDimension, "indicatorList": INDICATOR_LIST, "actionSpace": cryptoDimension, "agentRewardFactor": 1e-4 } cryptoEnv =cryptoPortfolioAllocationEnvironment(path=PATH, **envKwargs)
Changing
self.frame = self.dataFrame.loc[self.dateIncriment, :]
to self.frame = self.dataFrame.loc[[self.dateIncriment]]
self.frame = self.dataFrame.loc[[self.dateIncriment]]
achieves the same result and ensures that a series is returned
I tried to implement https://github.com/AI4Finance-Foundation/FinRL-Meta/blob/master/tutorials/2-Advance/FinRL_PortfolioAllocation_Explainable_DRL.ipynb for crypto portfolio allocation, but got
The data is in a csv as follows;
and my environment:
The error occurs with the following params;