How to use prophet - 10 common examples

To help you get started, we’ve selected a few prophet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Emsu / prophet / tests / integration / test_examples.py View on Github external
price_generator = YahooData('Adj Close', 'prices', cache_path=CACHE_PATH)
    prophet.register_data_generators(price_generator)
    prophet.set_order_generator(OrderGenerator())
    backtest = prophet.run_backtest(start=datetime(2010, 1, 1),
                                    end=datetime(2014, 11, 21))

    prophet.register_portfolio_analyzers(default_analyzers)
    analysis = prophet.analyze_backtest(backtest)
    assert round(analysis['sharpe'], 10) == 1.0970973495
    assert round(analysis['average_return'], 10) == 0.0010547843
    assert round(analysis['cumulative_return'], 10) == 2.1688171559
    assert round(analysis['volatility'], 10) == 0.0152622562

    today = datetime(2014, 11, 10)
    expected_orders = Orders(Order(symbol='AAPL', shares=100))
    assert prophet.generate_orders(today) == expected_orders
github Emsu / prophet / tests / integration / test_examples.py View on Github external
def test_quickstart():
    prophet = Prophet()
    prophet.set_universe(['AAPL', 'XOM'])

    price_generator = YahooData('Adj Close', 'prices', cache_path=CACHE_PATH)
    prophet.register_data_generators(price_generator)
    prophet.set_order_generator(OrderGenerator())
    backtest = prophet.run_backtest(start=datetime(2010, 1, 1),
                                    end=datetime(2014, 11, 21))

    prophet.register_portfolio_analyzers(default_analyzers)
    analysis = prophet.analyze_backtest(backtest)
    assert round(analysis['sharpe'], 10) == 1.0970973495
    assert round(analysis['average_return'], 10) == 0.0010547843
    assert round(analysis['cumulative_return'], 10) == 2.1688171559
    assert round(analysis['volatility'], 10) == 0.0152622562

    today = datetime(2014, 11, 10)
github Emsu / prophet / tests / integration / test_examples.py View on Github external
def test_quickstart():
    prophet = Prophet()
    prophet.set_universe(['AAPL', 'XOM'])

    price_generator = YahooData('Adj Close', 'prices', cache_path=CACHE_PATH)
    prophet.register_data_generators(price_generator)
    prophet.set_order_generator(OrderGenerator())
    backtest = prophet.run_backtest(start=datetime(2010, 1, 1),
                                    end=datetime(2014, 11, 21))

    prophet.register_portfolio_analyzers(default_analyzers)
    analysis = prophet.analyze_backtest(backtest)
    assert round(analysis['sharpe'], 10) == 1.0970973495
    assert round(analysis['average_return'], 10) == 0.0010547843
    assert round(analysis['cumulative_return'], 10) == 2.1688171559
    assert round(analysis['volatility'], 10) == 0.0152622562

    today = datetime(2014, 11, 10)
    expected_orders = Orders(Order(symbol='AAPL', shares=100))
    assert prophet.generate_orders(today) == expected_orders
github Emsu / prophet / tests / integration / test_examples.py View on Github external
def test_quickstart():
    prophet = Prophet()
    prophet.set_universe(['AAPL', 'XOM'])

    price_generator = YahooData('Adj Close', 'prices', cache_path=CACHE_PATH)
    prophet.register_data_generators(price_generator)
    prophet.set_order_generator(OrderGenerator())
    backtest = prophet.run_backtest(start=datetime(2010, 1, 1),
                                    end=datetime(2014, 11, 21))

    prophet.register_portfolio_analyzers(default_analyzers)
    analysis = prophet.analyze_backtest(backtest)
    assert round(analysis['sharpe'], 10) == 1.0970973495
    assert round(analysis['average_return'], 10) == 0.0010547843
    assert round(analysis['cumulative_return'], 10) == 2.1688171559
    assert round(analysis['volatility'], 10) == 0.0152622562

    today = datetime(2014, 11, 10)
    expected_orders = Orders(Order(symbol='AAPL', shares=100))
    assert prophet.generate_orders(today) == expected_orders
github Emsu / prophet / tests / integration / test_examples.py View on Github external
def run(self, prices, timestamp, cash, **kwargs):
        symbol = "AAPL"
        orders = Orders()
        if (prices.loc[timestamp, symbol] * 100) < cash:
            orders.add_order(symbol, 100)
        return orders
github Emsu / prophet / prophet / app.py View on Github external
cash (int): Amount of starting cash
            portfolio (prophet.portfolio.Portfolio): Starting portfolio

        Return:
            prophet.backtest.BackTest
        """
        # Setup
        if not end:
            today = dt.date.today()
            end = dt.datetime.combine(today, dt.time())

        if not self._order_generator:
            raise ProphetException("Must set an order generator by calling"
                                   "set_order_generator.")

        timestamps = trading_days[(trading_days >= start) &
                                  (trading_days <= end)]
        effective_start = timestamps[0]

        data = self._generate_data(start=effective_start,
                                   end=end,
                                   lookback=lookback)

        # Run backtest
        return backtest(cash=cash,
                        data=data,
                        start=effective_start,
                        end=end,
                        slippage=slippage,
                        commission=commission,
                        portfolio=initial_portfolio,
                        order_generator=self._order_generator,
github Emsu / prophet / examples / quickstart.py View on Github external
from prophet.analyze import default_analyzers
from prophet.orders import Orders
from prophet.charting import visualize_backtest

class OrderGenerator(object):

    def run(self, prices, timestamp, cash, **kwargs):
        symbol = "AAPL"
        orders = Orders()
        if (prices.loc[timestamp, symbol] * 100) < cash:
            orders.add_order(symbol, 100)

        return orders


prophet = Prophet()
prophet.set_universe(['AAPL', 'XOM'])

price_generator = YahooData('Adj Close', 'prices')

prophet.register_data_generators(price_generator)
prophet.set_order_generator(OrderGenerator())
backtest = prophet.run_backtest(start=datetime(2010, 1, 1))

prophet.register_portfolio_analyzers(default_analyzers)
analysis = prophet.analyze_backtest(backtest)
print(analysis)
# +--------------------------------------+
# | sharpe            |    1.09754359611 |
# | average_return    | 0.00105478425027 |
# | cumulative_return |         2.168833 |
# | volatility        |  0.0152560508189 |
github Emsu / prophet / examples / tutorial / __main__.py View on Github external
from prophet.analyze import default_analyzers

from bollinger import BollingerData
from eventstudy import BollingerEventStudy
from eventstudy import OrderGenerator


# Based on Homework #7 for Computational Investing
# http://wiki.quantsoftware.org/index.php?title=CompInvesti_Homework_7
# Here we use 2 symbols and a benchmark to reduce data pulled
# but you can use the full sp5002012.txt file from QSTK
# You will have to adjust the portfolio analyzers
# The homework solution's analyzers start the analysis
# when the first trade is conducted instead of the entire
# duration of the backtest.
prophet = Prophet()
symbols = ["AAPL", "XOM", "SPX"]
prophet.set_universe(symbols)

prophet.register_data_generators(YahooCloseData(),
                                 BollingerData(),
                                 BollingerEventStudy())
prophet.set_order_generator(OrderGenerator())
backtest = prophet.run_backtest(start=dt.datetime(2008, 1, 1),
                                end=dt.datetime(2009, 12, 31), lookback=20)

prophet.register_portfolio_analyzers(default_analyzers)
analysis = prophet.analyze_backtest(backtest)
print(analysis)
# +----------------------------------------+
# | sharpe            |    -0.851247401074 |
# | average_return    | -2.04368321273e-07 |
github Emsu / prophet / examples / tutorial / __main__.py View on Github external
# You will have to adjust the portfolio analyzers
# The homework solution's analyzers start the analysis
# when the first trade is conducted instead of the entire
# duration of the backtest.
prophet = Prophet()
symbols = ["AAPL", "XOM", "SPX"]
prophet.set_universe(symbols)

prophet.register_data_generators(YahooCloseData(),
                                 BollingerData(),
                                 BollingerEventStudy())
prophet.set_order_generator(OrderGenerator())
backtest = prophet.run_backtest(start=dt.datetime(2008, 1, 1),
                                end=dt.datetime(2009, 12, 31), lookback=20)

prophet.register_portfolio_analyzers(default_analyzers)
analysis = prophet.analyze_backtest(backtest)
print(analysis)
# +----------------------------------------+
# | sharpe            |    -0.851247401074 |
# | average_return    | -2.04368321273e-07 |
# | cumulative_return |          -0.000103 |
# | volatility        |  3.81116761073e-06 |
# +----------------------------------------+


# Generate orders for your to execute today
# Using Nov, 10 2014 as the date because there might be no data for today's
# date (Market might not be open) and we don't want a examples to fail.
today = dt.datetime(2009, 12, 31)
print(prophet.generate_orders(today, lookback=20))
github Emsu / prophet / examples / quickstart.py View on Github external
if (prices.loc[timestamp, symbol] * 100) < cash:
            orders.add_order(symbol, 100)

        return orders


prophet = Prophet()
prophet.set_universe(['AAPL', 'XOM'])

price_generator = YahooData('Adj Close', 'prices')

prophet.register_data_generators(price_generator)
prophet.set_order_generator(OrderGenerator())
backtest = prophet.run_backtest(start=datetime(2010, 1, 1))

prophet.register_portfolio_analyzers(default_analyzers)
analysis = prophet.analyze_backtest(backtest)
print(analysis)
# +--------------------------------------+
# | sharpe            |    1.09754359611 |
# | average_return    | 0.00105478425027 |
# | cumulative_return |         2.168833 |
# | volatility        |  0.0152560508189 |
# +--------------------------------------+

# Generate orders for you to execute today
# Using Nov, 10 2014 as the date because there might be no data for today's
# date (Market might not be open) and we don't want examples to fail.
today = datetime(2014, 11, 10)
print(prophet.generate_orders(today))
# Orders[Order(symbol='AAPL', shares=100)]