Comments (2)
Thanks! These are all valid observations.
-
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). -
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
- 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.
Thanks for your ideas.
-
So do changes need to be made in all the
Costs.optimization_log
s? Or justResult.log_policy
? -
Throwing an exception sounds interesting. I guess it would be thrown in
Policy.get_trades
? And then handled inSimulation.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 (DatetimeIndex
s) 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)
- Make `MarketSimulator`, `TransactionCost`, `HoldingCost` agnostic to asset class and subclass them to specialize them
- Query: How do I use ESG scores of a company to optimize a portfolio? HOT 3
- FactorModelSigma -> FactorModelCovariance HOT 3
- Error while calculating returns from 2010. HOT 3
- pip install complains of scipy<1.11.0 HOT 4
- User provided returns forecast (`r_hat`) can be problematic HOT 1
- Interest rate on short sell cash proceeds
- Error from sp500_ndx100 example HOT 1
- Issue When Running examples/sp500_ndx100.py HOT 5
- poetry for dependency management HOT 6
- Best practices for dealing with nan assets (e.g., IPOs) HOT 3
- MarketData <> prepare_data HOT 7
- questions / thoughts on examples folder HOT 2
- suggestion for splitting backtest() method into single and multiple HOT 2
- Implement TurnoverLimit and other constraints from Chapter 4 of the book
- simulator.simulate() doesn't work unless backtest() is called first HOT 3
- Dollar volume assumption HOT 1
- Pulling out F parameter in FactorModelCovariance
- Memory Error When use more than two policiy HOT 1
- PEP8 HOT 2
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 cvxportfolio.