Exemplo n.º 1
0
    def __init__(self,
                 balance,
                 tickers=None,
                 base_model=LinearRegression(),
                 n_prev=2,
                 wait=100,
                 steps_ahead=100,
                 k=5,
                 envelope='proportional',
                 log=False,
                 commission=.0002,
                 flat_rate=8):

        if tickers is None:
            tickers = s_and_p_names('2014-1-1', '2015-11-02')

        super(TSEBuyAndHoldStrategy, self).__init__(balance,
                                                    tickers,
                                                    log=log,
                                                    commission=commission,
                                                    wait=wait,
                                                    flat_rate=flat_rate)

        self.model = TimeSeriesRegressor(base_model, n_ahead=1, n_prev=n_prev)
        self.steps_ahead = steps_ahead
        self.k = k
        self.envelope = envelope
Exemplo n.º 2
0
 def __init__(self, balance, tickers=None, wait=100, k=5, envelope='proportional',
          log=False, commission=.0002, flat_rate=8):
     if tickers is None:
         tickers = s_and_p_names('2014-1-1', '2015-11-02')
     super(BestChangeBuyAndHoldStrategy, self).__init__(balance, tickers,
                                                 log=log, commission=commission, wait=wait, flat_rate=flat_rate)
     self.k = k
     self.envelope = envelope
Exemplo n.º 3
0
    def __init__(self, balance, tickers=None, base_model=LinearRegression(),
                 n_prev=2, wait=100, steps_ahead=100, k=5, envelope='proportional',
                 log=False, commission=.0002, flat_rate=8):

        if tickers is None:
            tickers = s_and_p_names('2014-1-1', '2015-11-02')

        super(TSEBuyAndHoldStrategy, self).__init__(balance, tickers,
                                                    log=log, commission=commission, wait=wait, flat_rate=flat_rate)

        self.model = TimeSeriesRegressor(base_model, n_ahead=1, n_prev=n_prev)
        self.steps_ahead = steps_ahead
        self.k = k
        self.envelope = envelope
Exemplo n.º 4
0
def buy_and_hold_spread(k=5, wait=100, start="2014-1-1", end="2015-11-02", iterations=100):
    sp500_names = s_and_p_names(start, end)
    out = []
    if iterations == 'full':
        for tickers in itertools.combinations(sp500_names, k):
            tickers = list(tickers)
            bs = BuyAndHoldStrategy(10000, tickers, wait=wait)
            out.append(backtest(bs, start=start, end=end, correct=False))
    else:
        for i in range(iterations):
            tickers = random.sample(sp500_names, k)
            bs = BuyAndHoldStrategy(10000, tickers, wait=wait)
            out.append(backtest(bs, start=start, end=end, correct=False))

    return out
Exemplo n.º 5
0
def buy_and_hold_spread(k=5,
                        wait=100,
                        start="2014-1-1",
                        end="2015-11-02",
                        iterations=100):
    sp500_names = s_and_p_names(start, end)
    out = []
    if iterations == 'full':
        for tickers in itertools.combinations(sp500_names, k):
            tickers = list(tickers)
            bs = BuyAndHoldStrategy(10000, tickers, wait=wait)
            out.append(backtest(bs, start=start, end=end, correct=False))
    else:
        for i in range(iterations):
            tickers = random.sample(sp500_names, k)
            bs = BuyAndHoldStrategy(10000, tickers, wait=wait)
            out.append(backtest(bs, start=start, end=end, correct=False))

    return out
Exemplo n.º 6
0
 def __init__(self,
              balance,
              tickers=None,
              wait=100,
              k=5,
              envelope='proportional',
              log=False,
              commission=.0002,
              flat_rate=8):
     if tickers is None:
         tickers = s_and_p_names('2014-1-1', '2015-11-02')
     super(BestChangeBuyAndHoldStrategy,
           self).__init__(balance,
                          tickers,
                          log=log,
                          commission=commission,
                          wait=wait,
                          flat_rate=flat_rate)
     self.k = k
     self.envelope = envelope