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

number of days in trade mistmached #1099

Open
sandeepbhutani304 opened this issue Dec 30, 2023 · 0 comments
Open

number of days in trade mistmached #1099

sandeepbhutani304 opened this issue Dec 30, 2023 · 0 comments

Comments

@sandeepbhutani304
Copy link

sandeepbhutani304 commented Dec 30, 2023

Expected Behavior

Number of days in _trades should be just 1 or 2 but are 389 or anything

Actual Behavior

if records count is 300 then difference is coming out as 389

Steps to Reproduce

I am simply buying at records number 10 and selling at record number 11... using a ii counter
code:

    # Define the two MA lags as *class variables*
    # for later optimization
    n1 = 10
    n2 = 20

    ii = 0

    boughtonce=False
    
    def init(self):
        # Precompute the two moving averages
        self.sma1 = self.I(SMA, self.data.Close, self.n1)
        self.sma2 = self.I(SMA, self.data.Close, self.n2)
    
    def next(self):
        # print(self.data.Close)
        global ggg

        self.ii += 1
        # if ggg == False:
        if self.ii == 10:
            self.buy()
            ggg = True
        
        if self.ii == 11:
            self.sell()

        return
GOOG = GOOG[:300]
print(GOOG)
bt = Backtest(GOOG, SmaCross, cash=1000, commission=0)
stats = bt.run()
print(stats, "\n", stats._trades)
`


Output:

`dtype: object
    Size  EntryBar  ExitBar  EntryPrice  ExitPrice      PnL  ReturnPct  EntryTime   ExitTime Duration
0     7        30      299       130.8     345.78  1504.86   1.643578 2004-10-01 2005-10-25 389 days

Additional info

  • Backtesting version: 0.3.3
  • bokeh.__version__:
  • OS: windows
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