Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about the error when run the startTrading() function #2

Open
Erica-Ko opened this issue Feb 26, 2021 · 0 comments
Open

Question about the error when run the startTrading() function #2

Erica-Ko opened this issue Feb 26, 2021 · 0 comments

Comments

@Erica-Ko
Copy link

I tried to test the new strategy and when I run the code of results = tradingSystem.startTrading(), It prompts out the error message.

I am not going to post the full code here because it is quite long. I would like to know which direction should I go for solving the problem. If there is really a need for the full code, please let me know. Thank you for your help.

The following is the error message:

Processing data for stock: AAPL
Processing data for stock: MSFT
20% done...
40% done...
60% done...
80% done...
Logging all the available market metrics in tensorboard
Logging all the available instrument metrics in tensorboard
2017-01-02 00:00:00
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-c0f85326750e> in <module>()
      2 tsParams = MyTradingParams(tf)
      3 tradingSystem = TradingSystem(tsParams)
----> 4 results = tradingSystem.startTrading()

6 frames
/root/.local/lib/python3.7/site-packages/backtester/trading_system.py in startTrading(self, onlyAnalyze, shouldPlot, makeInstrumentCsvs, createResultDict, logFileName)
    142                 except StopIteration:
    143                     isClose = True
--> 144                 self.updateFeaturesAndExecute(currentTimeUpdate, isClose, onlyAnalyze, global_step=global_step)
    145 
    146             if not onlyAnalyze and self.portfolioValue < 0:

/root/.local/lib/python3.7/site-packages/backtester/trading_system.py in updateFeaturesAndExecute(self, timeOfUpdate, isClose, onlyAnalyze, global_step)
     83         print(timeOfUpdate)
     84         self.totalUpdates = self.totalUpdates + 1
---> 85         self.updateFeatures(timeOfUpdate)
     86         if not onlyAnalyze:
     87             start = time.time()

/root/.local/lib/python3.7/site-packages/backtester/trading_system.py in updateFeatures(self, timeOfUpdate)
    109         # if self.totalUpdates > 0:
    110         # Dont call for the first time
--> 111         self.instrumentManager.updateFeatures(timeOfUpdate)
    112         end = time.time()
    113         diffms = (end - start) * 1000

/root/.local/lib/python3.7/site-packages/backtester/instruments_manager.py in updateFeatures(self, timeOfUpdate)
    237 
    238     def updateFeatures(self, timeOfUpdate):
--> 239         self.updateInstrumentFeatures(timeOfUpdate)
    240 
    241         currentMarketFeatures = {}

/root/.local/lib/python3.7/site-packages/backtester/instruments_manager.py in updateInstrumentFeatures(self, timeOfUpdate)
    229                                                          featureParams=featureParams,
    230                                                          featureKey=featureKey,
--> 231                                                          instrumentManager=self)
    232             self.__lookbackInstrumentFeatures.addFeatureValueForAllInstruments(timeOfUpdate, featureKey, featureVal)
    233             end = time.time()

/root/.local/lib/python3.7/site-packages/backtester/features/profitloss_feature.py in computeForInstrument(cls, updateNum, time, featureParams, featureKey, instrumentManager)
     22         currentPrice = priceDict.iloc[-1]
     23         changeInPosition = currentPosition - previousPosition
---> 24         tradePrice = pd.Series([instrumentManager.getInstrument(x).getLastTradePrice() for x in priceDict.columns], index=priceDict.columns)
     25         tradeLoss = pd.Series([instrumentManager.getInstrument(x).getLastTradeLoss() for x in priceDict.columns], index=priceDict.columns)
     26         pnl = (previousPosition * (currentPrice - previousPrice)) + (changeInPosition * (currentPrice - tradePrice)) - fees - tradeLoss

/root/.local/lib/python3.7/site-packages/backtester/features/profitloss_feature.py in <listcomp>(.0)
     22         currentPrice = priceDict.iloc[-1]
     23         changeInPosition = currentPosition - previousPosition
---> 24         tradePrice = pd.Series([instrumentManager.getInstrument(x).getLastTradePrice() for x in priceDict.columns], index=priceDict.columns)
     25         tradeLoss = pd.Series([instrumentManager.getInstrument(x).getLastTradeLoss() for x in priceDict.columns], index=priceDict.columns)
     26         pnl = (previousPosition * (currentPrice - previousPrice)) + (changeInPosition * (currentPrice - tradePrice)) - fees - tradeLoss

AttributeError: 'NoneType' object has no attribute 'getLastTradePrice
@Erica-Ko Erica-Ko changed the title Question about the error Question about the error when run the startTrading() function Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant