Comments (1)
hi @vjtrost88 thank you for trying my library!
In terms of using your own entry/exit dates, currently it is not supported, but I do plan on adding that function in the future.
If you wanted to modify the code yourself to see if it works, my suggestion is this:
In the function below, located inside core.py,
def _evaluate_options(data, **kwargs):
# trim option chains with strikes too far out from current price
data = data.pipe(_calculate_otm_pct).pipe(
_trim, "otm_pct", lower=kwargs["max_otm_pct"] * -1, upper=kwargs["max_otm_pct"],
)
# remove option chains that are worthless, it's unrealistic to enter
# trades with worthless options
entries = _remove_min_bid_ask(data, kwargs["min_bid_ask"])
# to reduce unnecessary computation, filter for options with the desired exit DTE
exits = _get(data, "dte", kwargs["exit_dte"])
return (
entries.merge(
right=exits,
on=["underlying_symbol", "option_type", "expiration", "strike"],
suffixes=("_entry", "_exit"),
)
# by default we use the midpoint spread price to calculate entry and exit costs
.assign(entry=lambda r: (r["bid_entry"] + r["ask_entry"]) / 2)
.assign(exit=lambda r: (r["bid_exit"] + r["ask_exit"]) / 2)
.pipe(_remove_invalid_evaluated_options)
.pipe(_calculate_profit_loss)
)[evaluated_cols]
update the lines where entries( entries = _remove_min_bid_ask(data, kwargs["min_bid_ask"])
) and exits (exits = _get(data, "dte", kwargs["exit_dte"])
) dataframes are being filtered, and filter on the df's quote_dates to equal the entry/exit dates you want to look at (likely from some lists).
so for example, lets say you have a list of entry_dates = [...] and exit_dates = [...],
entries = data[data['quote_date'].isin(entry_dates)]
exits = data[data['quote_date'].isin(exit_dates)]
You may/may not have to figure out how to match up the option on entry to the correct exit on the correct exit dates however, since it's doing a merge between the two dataframes after.
Let me know if that works for you.
from optopsy.
Related Issues (20)
- Short put spreads have wrong ratios assigned
- unable to import optopsy HOT 5
- Wrong Bid/Ask prices used to calculate entry/exit prices when using "market" mode
- Implement Iron Condor Strategy
- TypeError: long_call_spread() missing 2 required positional arguments: 'end' and 'filters' HOT 1
- Parameters selection HOT 5
- Remove get function, move data validation to strategy function
- long_call() takes 1 positional argument but 2 were given HOT 2
- Improvement idea HOT 3
- running strategies/sample_spx_strategy.py sample failed issue HOT 2
- argument issue in sample_spx_strategy.py issue HOT 1
- Branch code-rewrite throws Error (Missing optopsy.orders module)
- Still active? HOT 6
- Include Stress testing?
- Load from a dataframe ends in AttributeError: 'Index' object has no attribute 'remove_unused_levels' HOT 3
- Additional entry/exit conditions HOT 1
- Planned work as mentioned in the README HOT 1
- _remove_invalid_evaluated_options
- SPX singles examples generates empty output HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from optopsy.