Code Monkey home page Code Monkey logo

ib_nope's People

Contributors

ajhpark avatar ayeung9 avatar norman-c avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ib_nope's Issues

Handle the no reversion by market close scenarios

Two possible scenarios:
Scene. 1.

  1. NOPE reaches long_enter threshold so the bot buy calls
  2. However, instead of a reversion NOPE keeps going down until market close
  3. Bot is holding calls at close (default configuration should not buy 0dte contracts, so we may not want to sell before close if we're down since it could go up next day)

Scene. 2.

  1. NOPE reaches short_enter threshold so the bot buys puts
  2. No reversion, NOPE keeps going up until market close
  3. Bot is holding puts at close (same as above, we do not sell since it could go down next day)

Currently the bot closes the open positions from the above scenarios as soon as the market opens, since all it looks at is NOPE and NOPE resets to 0 at open. This is not ideal, need a better exit strategy for this case.

Sells are blocked by unfilled buys

  1. Buy order placed but unfilled
  2. Sells are triggered on held contracts
  3. Sells are blocked since you can't have open buy and sell orders on the same contract

Bet sizing based on Kelly Criterion

Use kelly criterion to dynamically size max call/put contract limits based on portfolio value to avoid portfolio blowout.

https://explore.paulbutler.org/bet/

Half kelly is normally a good betting size if you want to stay conservative, but base logic is that you don't bet so much that you blow up your account in a few trades.

Event loop already running

asyncio needs to be patched to handle nested event loops, otherwise we see an event loop already running error when using ib_insync

How to use different source for NOPE

Reason for using Questrade for NOPE data is because there's no efficient way to use IB API to get NOPE, especially since we need to update frequently. Click here see how to get option chain data using the IB API. You need to send a separate request for each contract in the chain which is too slow and there is no endpoint to get it all at once.

Why Questrade? Because I happened to have a Questrade account and their API is good for NOPE, that's about it. Good news is this project can very easily be modified to use a different source for NOPE such as TDA or ORATS if you don't have a Questrade account.

How:

  1. Remove these two lines in NopeStrategy.__init__:
    self.qt = QuestradeClient(token_yaml=self.QT_ACCESS_TOKEN)
    self.run_qt_tasks()
  2. Change NopeStrategy.set_nope_value to use the client you want. For example if using TDA, import the TDAClient from tda/tda_client.py and replace self.qt.get_nope() with self.tda.get_nope(). If using neither TDA or Questrade, you will need to write your own client for your NOPE source.
  3. Add an asyncio task to run NopeStrategy.set_nope_value every minute (see NopeStrategy.run_qt_tasks to see how it's done)

The rest of NopeStrategy doesn't care how the NOPE value is set and should work fine.

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.