Giter VIP home page Giter VIP logo

ibck's Introduction

ibck

Portfolio sanity-checker for IBKR accounts (name is a pun on fsck).

So far, it's fairly primitive/hacky, and is focused only on writing equity options. However, it does present a nice proof-of-concept for a high-level wrapper to the IBKR TWS API that ought to be a huge breath of fresh air (example below).

Sanity checks

Right now, it has only two basic sanity checks:

  • All short calls in each account should be covered.

  • Each account should have enough cash to cover the exercise of all short puts at any time should any/all underlyings abruptly move to any price.

I'm hoping to add more when I have the time to wrap more of the API.

Isn't that second condition awfully conservative?

Oh, yes. Here's the thing: I don't trust any value-at-risk analysis (like those that TWS will happily show you) because I don't want to assume a distribution for the price movement of any underlying. Weird stuff happens, and I want to sleep at night.

TWS API Wrapper

The interesting part is mostly visible in the TWSAdapter API, which lets you "just ask questions" about your portfolios without getting bogged down in all the TWS messaging minutia.

For example, to find the set of all symbols of all underlyings on which you have open short puts, the TWSAdapter wrapper I've written allows you to just say something like:

adapter
  .getPositions(accountNumber)
  .filter(pos => pos.isShort && pos.isPut)
  .map(_.contract.symbol())
  .toSet

which is substantially easier than using the IBKR TWS API "directly".

What's broken / needs work

  • Most exceptions are placeholders.

  • There are a lot of unwrapped parts of the IBKR EWrapper API.

  • The notion of a "sanity check" should probably be abstracted away to allow us to factor out some of the spaghetti in Main and make it easy to extend the set of available sanity checks.

  • There's no build.sbt (sorry).

  • There's no way to specify the host/port of TWS / the IBKR gateway from the command line; it's assumed to be the default.

Building / running this

I'm assuming you have nix installed.

Running nix-shell will install scala, a jdk, and the IBKR API under ./nix-jdk. You'll want to tell IntelliJ to look there for the JDK, scalac, all jars, etc.

One day, I'll get around to writing a build.sbt so you can realistically do this without an IDE.

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.