Comments (8)
The way performance metrics based on returns are implemented is: you write a Numba-compiled function (or any other function) that takes a two-dimensional array and returns a one-dimensional array with values per column. Then, it gets wrapped into a pandas object and finally returned. There is no need for any factory since the process cannot be further automated.
You can easily subclass the Portfolio and define your custom cached properties there. I was thinking about doing many crazy things with Portfolio, but the way it is right now is the most generic. For example, below is an example how attach a skew method:
from vectorbt import Portfolio
from vectorbt.utils.decorators import cached_property
class MyPortfolio(Portfolio):
@cached_property
def returns_skew(self):
return self.returns.skew()
This will behave the same as if it was defined in the original class.
from vectorbt.
I'm trying to make a similar property but from trades.
Basically I want to apply a log((trade.pnl/100)+1)
function to each trade and then a reduce each columnsum()/len()
Based on the code of the WalkForwardOptimization
, im running simulate_all_params(in_df, params_range).
So in Portfolio.from_signals(close,
, close.shape = (1080, 405)
as there are many windows and combination of params.
portfolio.returns
has the same shape as close
. But trades does not.
How can I wrap it so that I can calculate the log return over the return of each trade in each window?
from vectorbt.
Trade pnl is a MappedArray, so if you want to bring it to the same shape as close, use portfolio.trades.pnl.to_matrix
and do your operations.
from vectorbt.
Perfect, works like a charm.
Now, I see more returns values per window than trades.pnl values per window. So mind my question but, what is the difference between returns and trades.pnl in vbt?
from vectorbt.
returns are generated from portfolio value that is available at each bar (it's your close * current stake + current cash), while trade returns are generated only at the bar where the trade has been closed.
from vectorbt.
Thanks!
from vectorbt.
Hi @polakowo .
Is there a way to add custom @cached_property
to the Trades
class and then use the Portfolio_fom_signals method?
from vectorbt.
Hi @emiliobasualdo, you need to subclass Trades
, add your method, then subclass Portfolio
, and overwrite trades
property to call your new Trades
class (see this line)
from vectorbt.
Related Issues (20)
- vectorbt.utils' has no attribute 'data' HOT 2
- Difference between `returns`, `daily_returns`, `asset_returns` and `log_returns` in portfolio HOT 1
- python 3.11 HOT 3
- import vectorbt will take forever HOT 1
- vbt.CCXTData.pull HOT 2
- Lack of compatibility with python 3.12? HOT 6
- How to view the total net value trend of the entire strategy HOT 2
- Exits do not trigger consistently when using limit orders with from_signals HOT 2
- Custom sizing in portfolio.from_signals.
- ImportError: cannot import name 'generated_jit' from 'numba' HOT 9
- portfolio stats calculation for dca strategies. not appear all buy orders only first HOT 1
- Error specifying `benchmark_rets` arg in `Portfolio.plot_cum_returns()` HOT 2
- Doc Bug report HOT 1
- how to plot the trades of each symbol in portfolio HOT 1
- slippages are not applied to stop orders HOT 1
- How to import 3rd party data HOT 1
- Open short position right after closing long position with full capital HOT 3
- Installing vectorbt on Google Colab HOT 1
- plot with 1m granularity takes forever HOT 5
- portfolio.from_signals reporting HIGH variations with fees vs no fees
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.