Giter Site home page Giter Site logo

Comments (1)

michaelchu avatar michaelchu commented on May 26, 2024 2

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.