def run_strat(): # fetch the option chains from our data source d = op.get('data/VXX.csv', start=date(2016, 12, 1), end=date(2016, 12, 31), struct=vxx_struct, prompt=False) os = op.option_strategy.Vertical(option_type=op.OptionType.CALL, width=2) filters = [ op.filters.EntrySpreadPrice(ideal=1.0, lower=0.9, upper=1.10), op.filters.EntryDaysToExpiration(ideal=47, lower=40, upper=52), op.filters.EntryDayOfWeek(ideal=4), op.filters.ExitDaysToExpiration(ideal=1) ] # construct our strategy with our defined filter rules strategy = op.Strategy('Weekly Verticals', os, filters) # Create an instance of Optopsy with strategy settings, with default # initial capital of $10000 backtest = op.Optopsy(strategy, d) # Run over everything once backtest.run(progress_bar=False)
def test_init_strategy_with_filters(): filters = [ op.filters.EntrySpreadPrice(ideal=1.0, lower=0.9, upper=1.10), op.filters.ExitDaysToExpiration(ideal=1) ] dummy_strategy = op.OptionStrategy(name="Dummy Strategy") op.Strategy('Weekly Verticals', dummy_strategy, filters)
def test_invalid_opt_strategy(): with pytest.raises(ValueError): op.Strategy('test', op.Filter(), 'list of filters')
def test_strategy_with_invalid_filters(): filters = (op.filters.EntryDaysToExpiration(ideal=47, lower=40, upper=52)) dummy_strategy = op.OptionStrategy(name="Dummy Strategy") with pytest.raises(ValueError): op.Strategy('Weekly Verticals', dummy_strategy, filters)