Code Monkey home page Code Monkey logo

Comments (2)

 avatar commented on May 27, 2024

Thanks! These are all valid observations.

  1. Yup, I should change that. self.expression.value.A1 converts to numpy array (by default, cvxpy uses numpy matrices). It's kind of annoying, but unfortunately numpy has some inconsistencies there (i.e., there should be no difference between a n x 1 matrix and a n column vector, but there is).

  2. If the portfolio value drops below zero, you've gone bankrupt. Stopping the simulation is the correct thing to do. However, it would be more correct to throw an appropriate exception, e.g.,

class SimulationBankruptcy(Exception): pass

  1. I never really encountered negative values in my tests, so I haven't implemented guards against all possible breaking cases. Complex numbers in the Tcost model are clearly an absurdity. Negative portfolio values should be caught earlier and throw the same exception of point 2.

If you have implemented these changes, please go forward with a pull request.

Thanks!
Enzo

from cvxportfolio.

joseortiz3 avatar joseortiz3 commented on May 27, 2024

Thanks for your ideas.

  1. So do changes need to be made in all the Costs.optimization_logs? Or just Result.log_policy?

  2. Throwing an exception sounds interesting. I guess it would be thrown in Policy.get_trades? And then handled in Simulation.run_backtest? How would this handling work? Don't want the other 39 threads to get halted just because one went bankrupt.

The only changes I've made are to allow the simulation to continue, which sometimes maintains zero portfolio value for the rest of the time (at the cost of lots of unnecessary optimization), other times going further negative with further bankrupt trades (I guess, the leverage constraint unbinds when the portfolio becomes negative enough).

I think ideally, trades and portfolio values would get set to zero, and get_trades would return zeros without attempting optimization or throwing exceptions, and logging would record zero for everything. This way, the Result of a simulation that hits zero value has attributes with the same dimensions (DatetimeIndexs) as the other Results, and the simulation finishes very quickly. Then post-analysis doesn't have to worry about different results having different simulation lengths.

Hopefully I'll have time to try it out soon.

from cvxportfolio.

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.