Comments (7)
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.
@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.
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.
I saw that, but I thougt fixed_fees
is invariant to quantity.
Thanks.
from vectorbt.
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.
Now I am not sure anymore what should I do to set fixed fee, say $.001
from vectorbt.
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)
- tp_stop with accumulate gives wrong result
- Data mismatch
- Incorrect Position Size Allocation Across Multiple Assets HOT 3
- For the same precision data, there is an accuracy error in the results.
- Issues with combining multiple plots into subplots in 1 figure HOT 1
- Plotting Error: Subplot 'trade_pnl' raised an exception HOT 1
- Getting Daily PNL Portfolio Change
- What is the difference in the documentation of vectorbt PRO vs the open source vectorbt?
- What is the benchmark plotted in pf.plot().show()?
- How to use run_combs in combination with other signals?
- Questions about backtesting
- StopLoss group_by
- Plots missing "close" curve
- Import Errors HOT 5
- Plotting with custom benchmark_rets got error (VectorBT used undefined attribute 'obj')
- Datetime support with from_order_func HOT 1
- Dockerfile changes to run /apps/candlestick-patterns app
- Multiprocessing Error When Creating Portofiolio
- Pandas MultiIndex on axis 0 HOT 1
- Closing all positions at the end of the day
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 vectorbt.