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)
- 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.