Giter Club home page Giter Club logo

Comments (8)

polakowo avatar polakowo commented on May 12, 2024

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.

emiliobasualdo avatar emiliobasualdo commented on May 12, 2024

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.

polakowo avatar polakowo commented on May 12, 2024

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.

emiliobasualdo avatar emiliobasualdo commented on May 12, 2024

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.

polakowo avatar polakowo commented on May 12, 2024

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.

emiliobasualdo avatar emiliobasualdo commented on May 12, 2024

Thanks!

from vectorbt.

emiliobasualdo avatar emiliobasualdo commented on May 12, 2024

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.

polakowo avatar polakowo commented on May 12, 2024

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)

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.