Package: optopsy
OptopsyOptopsy is a nimble backtesting and statistics library for option strategies, it is designed to answer questions like
"How do straddles perform on the SPX?" or "Which strikes and/or expiration dates should I choose to make the most potential profit?"Use cases for Optopsy:Generate option strategies from raw option chain datasets for your own analysisDiscover performance statistics onpercentage changefor various options strategies on a given stockRun backtests on option strategies based on entry conditions generated from Optopsy (Planned)Supported Option StrategiesCalls/PutsStraddles/StranglesVertical Call/Put SpreadsButterflies (Planned)Iron Condors (Planned)Many more to followDocumentationPlease see thewikifor API reference.UsageUse Your DataUse data from any source, just provide a Pandas dataframe with the required columns when calling optopsy functions.DependenciesYou will need Python 3.6 or newer and Pandas 0.23.1 or newer and Numpy 1.14.3 or newer.Installationpip install optopsy==2.0.1ExampleLet's see how long calls perform on the SPX on a small demo dataset on the SPX:
Download the following data sample from DeltaNeutral:http://www.deltaneutral.com/files/Sample_SPX_20151001_to_20151030.csvThis dataset is for the month of October in 2015, lets load it into Optopsy. First create a small helper function
that returns a file path to our file. We will store it under a folder named 'data', in the same directory as the working python file.def filepath():
    curr_file = os.path.abspath(os.path.dirname(__file__))
    return os.path.join(curr_file, "./data/Sample_SPX_20151001_to_20151030.csv")Next lets use this function to pass in the file path string into Optopsy'scsv_data()function, we will map the column
indices using the defined function parameters. We are omitting thestart_dateandend_dateparameters in this call because
we want to include the entire dataset. The numeric values represent the column number as found in the sample file, the
numbers are 0-indexed:import optopsy as op

spx_data = op.csv_data(
    filepath(),
    underlying_symbol=0,
    underlying_price=1,
    option_type=5,
    expiration=6,
    quote_date=7,
    strike=8,
    bid=10,
    ask=11,
)Thecsv_data()function is a convenience function. Under the hood it uses Panda'sread_csv()function to do the import.
There are other parameters that can help with loading the csv data, consult the code/future documentation to see how to use them.Optopsy is a small simple library that offloads the heavy work of backtesting option strategies, the API is designed to be simple
and easy to implement into your regular Panda's data analysis workflow. As such, we just need to call thelong_calls()function
to have Optopsy generate all combinations of a simple long call strategy for the specified time period and return a DataFrame. Here we
also use Panda'sround()function afterwards to return statistics within two decimal places.long_calls_spx_pct_chgs = op.long_calls(spx_data).round(2)The function will returned a Pandas DataFrame containing the statistics on thepercentange changesof running long calls in allvalidcombinations on the SPX:dte_rangeotm_pct_rangecountmeanstdmin25%50%75%max0(0, 7](-0.5, -0.45]1550.030.02-0.020.010.020.040.111(0, 7](-0.45, -0.4]2010.040.03-0.020.010.030.060.122(0, 7](-0.4, -0.35]2470.040.03-0.020.020.040.070.133(0, 7](-0.35, -0.3]2960.050.04-0.020.020.040.080.154(0, 7](-0.3, -0.25]3290.050.05-0.030.020.050.090.175(0, 7](-0.25, -0.2]3520.060.05-0.030.020.050.10.26(0, 7](-0.2, -0.15]3830.080.07-0.040.030.070.130.267(0, 7](-0.15, -0.1]4170.110.09-0.060.040.090.170.378(0, 7](-0.1, -0.05]4610.180.16-0.120.070.150.280.699(0, 7](-0.05, -0.0]5050.641.03-10.140.370.877.6210(0, 7](-0.0, 0.05]2692.348.65-1-1-0.891.166811(0, 7](0.05, 0.1]2-10-1-1-1-1-112(7, 14](-0.5, -0.45]700.060.030.020.030.070.080.1213(7, 14](-0.45, -0.4]1650.090.040.020.060.080.10.1714(7, 14](-0.4, -0.35]1970.090.040.020.070.090.120.1915(7, 14](-0.35, -0.3]2350.110.040.020.090.10.130.2116(7, 14](-0.3, -0.25]2650.130.050.030.10.120.150.2517(7, 14](-0.25, -0.2]2800.150.060.030.110.140.180.318(7, 14](-0.2, -0.15]3070.180.080.040.140.180.230.3819(7, 14](-0.15, -0.1]3320.250.110.050.180.240.310.5420(7, 14](-0.1, -0.05]3700.40.180.070.290.390.520.9721(7, 14](-0.05, -0.0]4041.020.68-0.460.580.861.324.422(7, 14](-0.0, 0.05]3881.524.45-1-0.99-0.732.653223(7, 14](0.05, 0.1]36-0.930.06-1-1-0.94-0.87-0.8324(14, 21](-0.5, -0.45]60.10.010.090.090.10.10.125(14, 21](-0.45, -0.4]660.140.040.090.110.140.170.2326(14, 21](-0.4, -0.35]910.160.040.10.120.160.20.2527(14, 21](-0.35, -0.3]1350.180.050.110.130.170.210.2828(14, 21](-0.3, -0.25]1490.20.050.120.150.20.250.3329(14, 21](-0.25, -0.2]1600.240.060.140.180.230.290.430(14, 21](-0.2, -0.15]1740.30.080.170.230.290.350.5131(14, 21](-0.15, -0.1]1870.40.110.220.30.380.480.732(14, 21](-0.1, -0.05]2110.630.190.320.470.60.751.1633(14, 21](-0.05, -0.0]2291.390.530.5811.31.733.134(14, 21](-0.0, 0.05]2522.582.92-1-12.724.5610.135(14, 21](0.05, 0.1]93-0.820.92-1-1-1-16.3936(21, 28](-0.5, -0.45]10.11nan0.110.110.110.110.1137(21, 28](-0.45, -0.4]210.150.030.110.120.150.170.2338(21, 28](-0.4, -0.35]390.20.060.120.160.180.240.3239(21, 28](-0.35, -0.3]610.210.060.130.170.20.260.3540(21, 28](-0.3, -0.25]750.250.080.140.20.240.310.4141(21, 28](-0.25, -0.2]790.30.090.170.230.270.370.4942(21, 28](-0.2, -0.15]870.370.110.20.290.340.450.6243(21, 28](-0.15, -0.1]930.480.150.260.370.460.580.8544(21, 28](-0.1, -0.05]1050.740.240.360.560.710.891.3945(21, 28](-0.05, -0.0]1141.450.540.621.051.341.733.2846(21, 28](-0.0, 0.05]1252.973.38-11.292.584.2117.1547(21, 28](0.05, 0.1]850.825.3-1-1-1-119.548(28, 35](-0.4, -0.35]50.310.010.30.30.310.320.3249(28, 35](-0.35, -0.3]70.340.010.320.330.350.350.3650(28, 35](-0.3, -0.25]120.390.020.360.370.390.40.4251(28, 35](-0.25, -0.2]130.460.020.420.440.450.470.4952(28, 35](-0.2, -0.15]140.550.040.50.530.550.580.6253(28, 35](-0.15, -0.1]150.730.070.630.670.720.770.8454(28, 35](-0.1, -0.05]171.060.140.860.941.051.171.3255(28, 35](-0.05, -0.0]191.950.441.361.581.872.262.7956(28, 35](-0.0, 0.05]205.722.232.943.855.237.339.9757(28, 35](0.05, 0.1]213.535.47-1-1-110.3811.32There are more customization options for Optopsy's strategy functions, consult the codebase/future documentation to see how it can be used to adjust the results, such as increasing/decreasing
the intervals and other data to be returned.The library is currently under development, as such expect changes to the API in the future.