예제 #1
0
def test_quickstart():
    prophet = Prophet()
    prophet.set_universe(['AAPL', 'XOM'])

    prophet.register_data_generators(YahooCloseData(cache_path=CACHE_PATH))
    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.1083876014
    assert round(analysis['average_return'], 10) == 0.0010655311
    assert round(analysis['cumulative_return'], 10) == 2.2140809296
    assert round(analysis['volatility'], 10) == 0.0152607097

    today = datetime(2014, 11, 10)
    expected_orders = Orders(Order(symbol='AAPL', shares=100))
    assert prophet.generate_orders(today) == expected_orders
예제 #2
0
def test_quickstart():
    prophet = Prophet()
    prophet.set_universe(['AAPL', 'XOM'])

    prophet.register_data_generators(YahooCloseData(cache_path=CACHE_PATH))
    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
예제 #3
0
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.0967430073
    assert round(analysis['average_return'], 10) == 0.0010501702
    assert round(analysis['cumulative_return'], 10) == 2.1604345132
    assert round(analysis['volatility'], 10) == 0.0152004028

    today = datetime(2014, 11, 10)
    expected_orders = Orders(Order(symbol='AAPL', shares=100))
    assert prophet.generate_orders(today) == expected_orders
예제 #4
0
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.1083876014
    assert round(analysis['average_return'], 10) == 0.0010655311
    assert round(analysis['cumulative_return'], 10) == 2.2140809296
    assert round(analysis['volatility'], 10) == 0.0152607097

    today = datetime(2014, 11, 10)
    expected_orders = Orders(Order(symbol='AAPL', shares=100))
    assert prophet.generate_orders(today) == expected_orders
예제 #5
0
파일: quickstart.py 프로젝트: Afey/prophet
        self._data = dict()

    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'])

prophet.register_data_generators(YahooCloseData())
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.
예제 #6
0
class OrderGenerator(object):
    def run(self, prices, timestamp, cash, **kwargs):
        # Lets buy lots of Apple!
        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"])
prophet.register_data_generators(YahooCloseData())
prophet.set_order_generator(OrderGenerator())
prophet.register_portfolio_analyzers(default_analyzers)

backtest = prophet.run_backtest(start=dt.datetime(2010, 1, 1))
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.