Closed leolle closed 6 years ago
I fixed this issue on my branch. I've already made a pull request, but there has been no response. You can download my fixed version here:
@jonathanng thank you, I cloned your branch, but new error came up. I am using anaconda3-4.4.0.
/home/weiwu/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/cvxpy/atoms/quad_form.py:81: UserWarning: Forming a nonconvex expression quad_form(x, indefinite).
warnings.warn("Forming a nonconvex expression quad_form(x, indefinite).")
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-8-b229f1c1f6b4> in <module>()
4 result = market_sim.run_backtest(init_portfolio,
5 start_time='2013-01-03', end_time='2016-12-31',
----> 6 policy=spo_policy)
7
8 result.summary()
/home/weiwu/projects/cvxportfolio/cvxportfolio/simulator.py in run_backtest(self, initial_portfolio, start_time, end_time, policy, loglevel)
114 start = time.time()
115 try:
--> 116 u = policy.get_trades(h, t)
117 except cvx.SolverError:
118 logging.warning(
/home/weiwu/projects/cvxportfolio/cvxportfolio/policies.py in get_trades(self, portfolio, t)
236
237 for el in costs:
--> 238 assert (el.is_convex())
239
240 for el in constraints:
AssertionError:
Try updating your copy of cvxopt:
pip install cvxopt -U
Also in my branch, I cleaned up the HelloWorld example code. Try to see if that works.
@jonathanng My cvxopt versions is up to date. Here's another error:
home/weiwu/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/cvxpy/atoms/quad_form.py:81: UserWarning: Forming a nonconvex expression quad_form(x, indefinite).
warnings.warn("Forming a nonconvex expression quad_form(x, indefinite).")
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-7-22d34144d184> in <module>()
12 start_time = '2013-01-03',
13 end_time = '2016-12-31',
---> 14 policy = spo_policy
15 )
16
/home/weiwu/projects/tmp/test/cvxportfolio/cvxportfolio/simulator.py in run_backtest(self, initial_portfolio, start_time, end_time, policy, loglevel)
114 start = time.time()
115 try:
--> 116 u = policy.get_trades(h, t)
117 except cvx.SolverError:
118 logging.warning(
/home/weiwu/projects/tmp/test/cvxportfolio/cvxportfolio/policies.py in get_trades(self, portfolio, t)
236
237 for el in costs:
--> 238 assert (el.is_convex())
239
240 for el in constraints:
AssertionError:
Which notebook is this? HelloWorld?
yes, hello world. I have no problem with preload data optimization and simulation.
On Tue, Aug 8, 2017 at 9:32 PM, JPN notifications@github.com wrote:
Which notebook is this? HelloWorld?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cvxgrp/cvxportfolio/issues/3#issuecomment-320956854, or mute the thread https://github.com/notifications/unsubscribe-auth/AMSS0rOjQRYBac4gqmz_CtHPePvco3wWks5sWGN0gaJpZM4OsBc1 .
Which cell/line is giving you this error?
this one:
market_sim = cp.MarketSimulator(
market_returns = returns,
costs = [tcost_model, hcost_model],
cash_key = 'USDOLLAR'
)
init_portfolio = pd.Series(index=returns.columns, data=0.)
init_portfolio.USDOLLAR = 100
result = market_sim.run_backtest(
initial_portfolio = init_portfolio,
start_time = '2013-05-21',
end_time = '2016-12-31',
policy = spo_policy
)
result.summary()
I'm not sure what the issue is. It's hard to say without have the same environment. Have you tried a fresh install of Python & cvxportfolio?
I encountered a similar error and I found that if you have negative borrow rates, it won't be able to determine if the problem is convex.
One easy fix would be to do something like:
borrow_costs[borrow_costs < 0.0] = 0.0
This should be fixed now.
You need to sort the columns alphabetically in 'returns' DataFrame. Probably 'cvxpy' not fully compatible with pandas. I spent three days searching for this glitch.
Add to your code: returns.sort_index(axis=1, inplace=True)
And the cash asset should be in last place, i.e. in the last column as described in paper:
https://web.stanford.edu/~boyd/papers/pdf/cvx_portfolio.pdf
This column can be called '_USDOLLAR' instead 'USDOLLAR', then the columns will be sorted correctly.
I have this error when I run the HelloWorld example. Can anybody tell me how to fix it? Thank you.