Skip to content

Any way to get the entire time series matrix including signals, trades and position? #1024

Answered by peacerider
felonfusk asked this question in Q&A
Discussion options

You must be logged in to vote

Is this data useful for you?

*output._equity_curve
*output._trades

from backtesting import Backtest, Strategy
from backtesting.lib import crossover

from backtesting.test import SMA, GOOG


class SmaCross(Strategy):
    n1 = 10
    n2 = 20

    def init(self):
        close = self.data.Close
        self.sma1 = self.I(SMA, close, self.n1)
        self.sma2 = self.I(SMA, close, self.n2)

    def next(self):
        if crossover(self.sma1, self.sma2):
            self.buy()
        elif crossover(self.sma2, self.sma1):
            self.sell()


bt = Backtest(GOOG, SmaCross,
              cash=10000, commission=.002,
              exclusive_orders=True)

output = bt.run()
bt.plot()

print(ou…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@felonfusk
Comment options

@felonfusk
Comment options

@peacerider
Comment options

Answer selected by felonfusk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants