michaelchu / optopsy Goto Github PK
View Code? Open in Web Editor NEWA nimble options backtesting library for Python
Home Page: https://github.com/michaelchu/optopsy/wiki
License: GNU General Public License v3.0
A nimble options backtesting library for Python
Home Page: https://github.com/michaelchu/optopsy/wiki
License: GNU General Public License v3.0
I updated the script to point to './data/sample_spx_data.csv' since './data/Sample_SPX_20151001_to_20151030.csv' doesn't exist.
Then I ran it and it gave me the following empty output.
python3 spx_singles_example.py
Statistics for SPX long calls from 2015-10-01 to 2015-10-30
| index | count | mean | std | min | 25% | 50% | 75% | max |
|---------|---------|--------|-------|-------|-------|-------|-------|-------|
Program Executed in 0.0
Hi Michael,
First off, thank you for sharing your work on this package. It's the only one out there that I've seen dedicated to backtesting options strategies.
I'm curious how I can backtest strategies with my own entry/exit dates. In your wiki, you say "but theoretically, it is possible by injecting a list of entry and exit dates created from external sources based on indicators." After poking around in the code, I struggled to see where to do this and figured asking you might be faster.
Can you point me in the right direction? Thanks
Hi Michael,
I've been testing your module for some time and came up with an improvement idea. Most of my actual strategies are tied to additional external data like VIX, stocks' earnings, etc.
Adding the ability to consider exogenous variables to the strategy will dramatically increase the efficiency and the value of your system.
It could be done by allowing custom columns in the initial dataframe:
Column Name Status
---------------------------
option_symbol Optional
underlying_symbol Required
.....
vega Required
rho Optional
<custom column 1> Optional
<custom column 2> Optional
.....
<custom column n> Optional
And initial filters to be like for example:
filters = {
"start_date": datetime(2018, 1, 1),
"end_date": datetime(2018, 12, 31),
"entry_dte": (40, 47, 50),
"leg1_delta": 0.30,
"contract_size": 1,
"expr_type": "SPXW",
"custom column 1" : (20, 30, 40)
"custom column 2" : 10
.....
"custom column n" : <some conditions>
}
If it could be implemented, then your module could be used to find patterns not only in historical option prices but also across a variety of financial instruments.
In an effort to narrow down the scope of this library, data import APIs will be removed. It should be up to the user to handle data ingestion and transformations outside of this library.
Great library and very well programmed!
To evaluate some strategies, especially selling spreads, it would be useful to have additional entry & exit conditions:
entry:
exit:
Anything planned on including this?
Is it possible to pass a df to create an op instead of using a csv file? Havent had much luck with it. Anyone have any examples or pointers?
thanks!
Hi Michael
after clone the code and run the test sample_spx_strategy.py failed, said that DO not get /data/SPX_2014_2018.pk file, where can we download the file
And I notice in the csv file, we've calculated the delta/gamma so on, but the downloaded data does't include that value, does it means we have to cal them from the org csv file to a new one like data.csv or data_full.csv ?
thanks
Short put spread strategies should have a buy leg on the lower strike, and a sell leg on the higher strike.
Currently it is the opposite.
Hi Michael,
I was working with version #23 of your package. After the update to #32 I start receiving the following error when running the strategy:
TypeError: long_call() takes 1 positional argument but 2 were given
According to your example from 'strategies/sample_spx_strategy.py' next code is using from api call to optopsy module:
spreads = op.long_call(data, filters)
I chected out optopsy/option_strategies.py and it seems to secive only one argument:
def long_call(leg):
return _create_strategy([leg], singles_checks, [(OptionType.CALL, 1)])
Is there any changes in API that wasn't reflected in the example file 'strategies/sample_spx_strategy.py' or I'm doing something wrong?
Thanks!
Fantastic repo and currently the only repo that backtests stock derivatives.
Just a quick question, do you have any plans to work on the 3rd bullet point in the README under "Use cases for Optopsy": Run backtests on option strategies based on entry conditions generated from Optopsy (Planned)?
If not, what did you have in mind for that bullet point? I would imagine it includes being able to generate graphs and charts similar to that of other backtesting libraries to measure things like Annual return, sharpe and sortino ratio, max drawdown, etc.
Hey
I would love to help developing this module.
What is the current status?
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import optopsy as op
/opt/notebooks/options/optopsy/init.py in
----> 1 from .api.strategy import Strategy
2 from .backtest import Backtest
/opt/notebooks/options/optopsy/api/strategy.py in
1 import logging
2
----> 3 from optopsy.api.order_filter import OrderFilter
4
5
/opt/notebooks/options/optopsy/api/order_filter.py in
2 from optopsy.api.order_size import OrderSize
3 from optopsy.api.order_filter_scope import OrderFilterScope
----> 4 from optopsy.api.order_filter_scope2 import OrderFilterScope2
5 from optopsy.api.order_filter_scope3 import OrderFilterScope3
6 from optopsy.api.order_filter_scope4 import OrderFilterScope4
/opt/notebooks/options/optopsy/api/order_filter_scope2.py in
----> 1 from optopsy.orders.order_filters.order_filter_scope import OrderFilterScope
2
3
4 class OrderFilterScope2(OrderFilterScope):
5 def init(self,
ModuleNotFoundError: No module named 'optopsy.orders'
@michaelchu unable to import optopsy
runfile('G:/Projects/python/options/opto/strategies/sample_strategy.py', wdir='G:/Projects/python/options/opto/strategies')
Traceback (most recent call last):
File "", line 1, in
runfile('G:/Projects/python/options/opto/strategies/sample_strategy.py', wdir='G:/Projects/python/options/opto/strategies')
File "C:\Users\kaushik\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
execfile(filename, namespace)
File "C:\Users\kaushik\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "G:/Projects/python/options/opto/strategies/sample_strategy.py", line 1, in
import optopsy as op
ModuleNotFoundError: No module named 'optopsy'
Hey,
when running the sample code as is with the dataset you provided I get this error
File "strategies/sample_strat.py", line 27, in run_strategy
return op.option_strategies.long_call_spread(data, filters)
TypeError: long_call_spread() missing 2 required positional arguments: 'end' and 'filters'
Any idea what went wrong? I don´t see where long_call_spread() takes end as argument..
Thank you!
Hi Michael,
First of all, thank you for sharing your project with the community.
I've done a few tests over your code and find out that for a single leg spread (short put for example), your algorithm requires "leg1_delta" to be specified.
in optopsy/checks.py:
def singles_checks(f):
return "leg1_delta" in f and _date_check(f) and _type_check(f)
Why you chose this parameter to be mandatory and is it possible to run a backtest without "leg1_delta" parameter?
Thanks!
Hello Michael
Thanks for creating this project. This one comes nearest to my backtesting requirements (mainly want to backtest straddles & strangles), but I wonder if this project is still active and any plans of the release 2.0 that you mentioned here?
Best Regards
Dharma
Hi Michael
Another issue I'm quite curious how to run the final strategies, It's ok to run all test in tests/integration, but when running the strategies/, for example sample_spx_strategy.py. I've downloaded the data and format them well
But the long_call can NOT run well, short call neither, said that
Traceback (most recent call last):
File "sample_spx_strategy.py", line 62, in
run_strategy()
File "sample_spx_strategy.py", line 57, in run_strategy
spreads = op.long_call(data, filters)
TypeError: long_call() takes 1 positional argument but 2 were given
Have checked all in option_strategies.py all have no dataframe as input, but actually we need it
So this part need a update ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.