Skip to content

Nan as result #421

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

Closed
savioz opened this issue Jul 28, 2021 · 3 comments
Closed

Nan as result #421

savioz opened this issue Jul 28, 2021 · 3 comments
Labels
invalid This is not a (valid) bug report

Comments

@savioz
Copy link

savioz commented Jul 28, 2021

Expected Behavior

I passed 3 buy orders and the result shows only NAN

<Order size=0.1, sl=35376.898, tp=37611.2284, contingent=0>
<Order size=0.1, sl=34925.7335, tp=37131.5693, contingent=0>
<Order size=0.1, sl=35910.0, tp=38178.0, contingent=0>
Start                     2021-07-27 00:00:00
End                       2021-07-28 08:25:00
Duration                      1 days 08:25:00
Exposure Time [%]                         0.0
Equity Final [$]                     100000.0
Equity Peak [$]                      100000.0
Return [%]                                0.0
Buy & Hold Return [%]                6.744267
Return (Ann.) [%]                         0.0
Volatility (Ann.) [%]                     NaN
Sharpe Ratio                              NaN
Sortino Ratio                             NaN
Calmar Ratio                              NaN
Max. Drawdown [%]                        -0.0
Avg. Drawdown [%]                         NaN
Max. Drawdown Duration                    NaN
Avg. Drawdown Duration                    NaN
# Trades                                    0
Win Rate [%]                              NaN
Best Trade [%]                            NaN
Worst Trade [%]                           NaN
Avg. Trade [%]                            NaN
Max. Trade Duration                       NaN
Avg. Trade Duration                       NaN
Profit Factor                             NaN
Expectancy [%]                            NaN
SQN                                       NaN
_strategy                              System
  • Backtesting version: 0.?.?
@kernc
Copy link
Owner

kernc commented Jul 28, 2021

Can you provide sample code in order for someone to be able to reproduce the issue?

@savioz
Copy link
Author

savioz commented Jul 28, 2021

I am using anaconda python

my main function. :

df2 = pd.read_excel("test.xlsx")

df2 = df2.rename(columns={"open": "Open", "high": "High",
"low": "Low", "close": "Close", "v": "Volume"})

bt = Backtest(df2, Strat1,
cash=100000, commission=.003,
exclusive_orders=True)

output = bt.run()

---- and the strategy -----

class Strat1(Strategy):
def next(self):
psar = self.data.psar[-1]
ppsar = self.data.psar[-2]
price = self.data.Close[-1]
pprice = self.data.Close[-2]

  tpPercentage = 5 #3 
  slPercentage = 5 #5
  if ppsar > pprice and psar < price:
                     tp = price + (price * tpPercentage/100)  
                      sl = price - (price * slPercentage/100) 
                      p = self.buy(size=0.1, sl=sl, tp=tp)

@kernc
Copy link
Owner

kernc commented Feb 2, 2025

cash=100000
self.buy(size=0.1, ...) → 10_000
price ~= 35k

Can't buy any whole units of bitcoin with just $10k.

@kernc kernc closed this as completed Feb 2, 2025
@kernc kernc added the invalid This is not a (valid) bug report label Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This is not a (valid) bug report
Projects
None yet
Development

No branches or pull requests

2 participants