コード例 #1
0
ファイル: test_data.py プロジェクト: moue/optopsy
def test_duplicate_idx_in_struct():
    with pytest.raises(ValueError):
        op.get(os.path.join(os.path.dirname(__file__), 'test_data', 'daily'),
               start=date(2016, 1, 5),
               end=date(2016, 1, 6),
               struct=invalid_struct,
               prompt=False)
コード例 #2
0
ファイル: test_data.py プロジェクト: tpopenfoose/optopsy
def test_duplicate_idx_in_struct(mock_file_dir, invalid_struct):
    with pytest.raises(ValueError):
        op.get(mock_file_dir,
               start=date(2016, 1, 5),
               end=date(2016, 1, 6),
               struct=invalid_struct,
               prompt=False)
コード例 #3
0
ファイル: test_data.py プロジェクト: moue/optopsy
def test_invalid_fields():
    with pytest.raises(ValueError):
        op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                            'test_dod_a.csv'),
               start=date(2016, 1, 1),
               end=date(2016, 12, 31),
               struct=invalid_fields)
コード例 #4
0
ファイル: test_data.py プロジェクト: tpopenfoose/optopsy
def test_invalid_idx(mock_file_dir, invalid_idx):
    with pytest.raises(ValueError):
        op.get(mock_file_dir,
               start=date(2016, 1, 1),
               end=date(2016, 12, 31),
               struct=invalid_idx,
               prompt=False)
コード例 #5
0
ファイル: test_data.py プロジェクト: tpopenfoose/optopsy
def test_valid_fields(mock_daily_file, cboe_struct):
    try:
        op.get(mock_daily_file,
               start=date(2016, 1, 4),
               end=date(2016, 1, 5),
               struct=cboe_struct,
               prompt=False)
    except ValueError:
        pytest.fail('ValueError raised')
コード例 #6
0
ファイル: test_data.py プロジェクト: moue/optopsy
def test_valid_fields():
    try:
        op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                            'test_dod_a.csv'),
               start=date(2016, 1, 1),
               end=date(2016, 12, 31),
               struct=valid_fields,
               prompt=False)
    except ValueError:
        pytest.fail('ValueError raised')
コード例 #7
0
ファイル: test_data.py プロジェクト: tpopenfoose/optopsy
def test_invalid_start_end_fields(mock_file_dir, invalid_fields):
    start = date(2016, 1, 1)
    end = date(2015, 1, 1)

    with pytest.raises(ValueError):
        op.get(mock_file_dir,
               start=start,
               end=end,
               struct=invalid_fields,
               prompt=False)
コード例 #8
0
ファイル: test_data.py プロジェクト: moue/optopsy
def test_invalid_start_end_fields():
    start = date(2016, 1, 1)
    end = date(2015, 1, 1)

    with pytest.raises(ValueError):
        op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                            'test_dod_a.csv'),
               start=start,
               end=end,
               struct=invalid_fields,
               prompt=False)
コード例 #9
0
ファイル: conftest.py プロジェクト: moue/optopsy
def data_dod_greeks():
    return op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                               'test_dod_a_daily.csv'),
                  start=date(2016, 1, 1),
                  end=date(2016, 1, 5),
                  struct=dod_struct_with_opt_sym_greeks,
                  prompt=False)
コード例 #10
0
ファイル: conftest.py プロジェクト: moue/optopsy
def data_dod_underlying():
    return op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                               'test_dod_a_daily.csv'),
                  start=date(2016, 1, 1),
                  end=date(2016, 1, 5),
                  struct=dod_struct_underlying,
                  prompt=False)
コード例 #11
0
ファイル: conftest.py プロジェクト: moue/optopsy
def data_hod_sym():
    return op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                               'test_hod_vxx_daily.csv'),
                  start=date(2016, 12, 1),
                  end=date(2016, 12, 1),
                  struct=hod_struct_with_sym,
                  prompt=False)
コード例 #12
0
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)
コード例 #13
0
def run_strat():
    # fetch the pre-formatted option spread data generated by option
    data = op.get(
        '../data/A.csv',
        start=date(
            2016, 1, 1
        ),  # using a date function here to avoid entering the wrong date format
        end=date(2016, 12, 31),
        struct=struct)
コード例 #14
0
ファイル: test_data.py プロジェクト: yzk19930501/optopsy
def test_invalid_idx():
    invalid_idx = (('symbol', -1), ('quote_date', -2))

    with pytest.raises(ValueError):
        data = op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                                   'test_dod_a.csv'),
                      start=date(2016, 1, 1),
                      end=date(2016, 12, 31),
                      struct=invalid_idx)
コード例 #15
0
ファイル: test_data.py プロジェクト: yzk19930501/optopsy
def test_invalid_start_end_fields():
    start = date(2016, 1, 1)
    end = date(2015, 1, 1)

    invalid_fields = (('symbol', -1), ('invalid', -1))

    with pytest.raises(ValueError):
        data = op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                                   'test_dod_a.csv'),
                      start=start,
                      end=end,
                      struct=invalid_fields)
コード例 #16
0
ファイル: main.py プロジェクト: sovannit/optopsy
def start():
    """
    Main function of program.
    """
    # program timer
    program_starts = time.time()

    # Analyse VXX vertical spreads
    option_chains = op.get("VXX", start="2016-01-29", end="2016-03-12")
    option_strategy = op.OptionStrategies.iron_condor(option_chains, op.Period.SEVEN_WEEKS, 5, 2, 2)

    program_ends = time.time()
    print("The simulation ran for {0} seconds.".format(round(program_ends - program_starts, 2)))
コード例 #17
0
ファイル: test_data.py プロジェクト: yzk19930501/optopsy
def test_valid_fields():
    valid_fields = (('symbol', 0), ('underlying_price',
                                    1), ('option_type', 4), ('expiration', 5),
                    ('quote_date', 6), ('strike', 7), ('bid', 9), ('ask', 10),
                    ('volume', 11), ('oi', 12), ('iv', 14), ('delta', 17),
                    ('gamma', 18), ('theta', 19), ('vega', 20))

    try:
        data = op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                                   'test_dod_a.csv'),
                      start=date(2016, 1, 1),
                      end=date(2016, 12, 31),
                      struct=valid_fields)
    except ValueError:
        pytest.fail('ValueError raised')
コード例 #18
0
ファイル: test_data.py プロジェクト: yzk19930501/optopsy
def test_data_dod_import():
    cols = list(zip(*dod_struct))[0]
    test_df = pd.DataFrame(dod_test_data, columns=cols)
    test_df['expiration'] = pd.to_datetime(test_df.expiration,
                                           format='%Y-%m-%d')
    test_df['quote_date'] = pd.to_datetime(test_df.quote_date,
                                           format='%Y-%m-%d')
    test_df.set_index(['quote_date'], inplace=True)

    data = op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                               'test_dod_a.csv'),
                  start=date(2016, 1, 1),
                  end=date(2016, 12, 31),
                  struct=dod_struct)

    assert test_df.equals(data)
コード例 #19
0
def store_and_get_data(file_name):
    # absolute file path to our input file
    curr_file = os.path.abspath(os.path.dirname(__file__))
    file = os.path.join(curr_file, "data", f"{file_name}.pkl")

    # check if we have a pickle store
    if os.path.isfile(file):
        print("pickle file found, retrieving...")
        return pd.read_pickle(file)
    else:
        print("no picked file found, retrieving csv data...")

        csv_file = os.path.join(curr_file, "data", f"{file_name}.csv")
        data = op.get(csv_file, SPX_FILE_STRUCT, prompt=False)

        print("storing to pickle file...")
        pd.to_pickle(data, file)
        return data
コード例 #20
0
ファイル: test_data.py プロジェクト: moue/optopsy
def test_data_cboe_import():
    cols = list(zip(*cboe_struct))[0]
    test_df = pd.DataFrame(cboe_test_data, columns=cols)
    test_df['expiration'] = pd.to_datetime(test_df.expiration,
                                           infer_datetime_format=True,
                                           format='%Y-%m-%d')
    test_df['quote_date'] = pd.to_datetime(test_df.quote_date,
                                           infer_datetime_format=True,
                                           format='%Y-%m-%d')
    test_df.set_index('quote_date', inplace=True, drop=False)

    data = op.get(os.path.join(os.path.dirname(__file__), 'test_data',
                               'test_cboe_spx.csv'),
                  start=date(2016, 1, 1),
                  end=date(2016, 12, 31),
                  struct=cboe_struct,
                  prompt=False)

    pt.assert_frame_equal(test_df, data)
コード例 #21
0
def test_data_import(mock_daily_file, cboe_struct):
    data = op.get(mock_daily_file, struct=cboe_struct, prompt=False)
    assert data.shape == (2, 15)
コード例 #22
0
def test_data_import_bulk(mock_daily_dir, cboe_struct):
    data = op.get(mock_daily_dir, struct=cboe_struct, prompt=False)
    assert data.shape == (6, 13)
コード例 #23
0
ファイル: test_data.py プロジェクト: tpopenfoose/optopsy
def test_invalid_fields(mock_file_dir, invalid_fields):
    with pytest.raises(ValueError):
        op.get(mock_file_dir,
               start=date(2016, 1, 1),
               end=date(2016, 12, 31),
               struct=invalid_fields)
コード例 #24
0
def test_invalid_fields(mock_file_dir, invalid_fields):
    with pytest.raises(ValueError):
        op.get(mock_file_dir, struct=invalid_fields)
コード例 #25
0
def test_invalid_idx(mock_file_dir, invalid_idx):
    with pytest.raises(ValueError):
        op.get(mock_file_dir, struct=invalid_idx, prompt=False)
コード例 #26
0
def test_invalid_path_data_import(mock_daily_dir, cboe_struct):
    with pytest.raises(ValueError):
        op.get(mock_daily_dir, struct=cboe_struct, prompt=False)
コード例 #27
0
def test_valid_fields(mock_daily_file, cboe_struct):
    try:
        op.get(mock_daily_file, struct=cboe_struct, prompt=False)
    except ValueError:
        pytest.fail("ValueError raised")