Code Monkey home page Code Monkey logo

Comments (7)

polakowo avatar polakowo commented on August 11, 2024

You'll need the Portfolio.from_signals method. It expects a separate Series/DataFrame for price, and two Series/DataFrames for entry signals and exit signals respectively.

Here is a simple workflow for your particular use case:

price = df['prices']
entries = (df['signs'] == 1).vbt.signals.first() # buy at first 1
exits = (df['signs'] == 0).vbt.signals.first() # sell at first 0

portfolio = vbt.Portfolio.from_signals(price, entries, exits)
print(portfolio.total_return)

Refer to the portfolio documentation to see what methods and metrics you can use to build a portfolio.

from vectorbt.

MislavSag avatar MislavSag commented on August 11, 2024

@polakowo sorry for the late response. It works with your code. Is it possible to set commissions to fixed value? Some brokerage, like the Interactive brokers that I use, set commissions as a fixed price per quantity. For example, if I buy 100 equities of SPY, the commission is 100x0.002$, which is 2$.

from vectorbt.

polakowo avatar polakowo commented on August 11, 2024

If you look in the docs of the from_signals method, you will see that two commission inputs are supported: variable fees (in % of value) and fixed fees (in $). Variable fees are charged per dollar transacted. If you commission depends upon quantity and not value, you will have to multiply your transaction size with 0.002 and pass it as fixed fees. Again, here are the docs.

from vectorbt.

MislavSag avatar MislavSag commented on August 11, 2024

I saw that, but I thougt fixed_fees is invariant to quantity.
Thanks.

from vectorbt.

polakowo avatar polakowo commented on August 11, 2024

fixed_fees is indeed invariant to quantity, but in order for your example to work you need to multiply quantity by your commission to get what can be used as fixed fees.

Under the hood, fees are multiplied by price * quantity, while fixed_fees is just a constant. Also remember that you can pass your size and all the fees as arrays, such that you can define a different fee at different time steps.

from vectorbt.

MislavSag avatar MislavSag commented on August 11, 2024

Now I am not sure anymore what should I do to set fixed fee, say $.001

from vectorbt.

polakowo avatar polakowo commented on August 11, 2024

If your fee is in $ it must be fixed_fee, if it’s in % of transaction value it must be fees, simple as that.

from vectorbt.

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.