You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I have a problem at 3.1 Optimizing Portfolios each Rebalancing Date. I tried with anaconda and with Colab but I couldn't make it run. When I run the code I get the following error:
The problem doesn't have a solution with actual input parameters
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I have a problem at 3.1 Optimizing Portfolios each Rebalancing Date. I tried with anaconda and with Colab but I couldn't make it run. When I run the code I get the following error:
The problem doesn't have a solution with actual input parameters
AttributeError Traceback (most recent call last)
File :25
File ~\anaconda3\lib\site-packages\vectorbt\portfolio\base.py:3919, in Portfolio.from_order_func(cls, close, order_func_nb, flexible, init_cash, cash_sharing, call_seq, segment_mask, call_pre_segment, call_post_segment, pre_sim_func_nb, pre_sim_args, post_sim_func_nb, post_sim_args, pre_group_func_nb, pre_group_args, post_group_func_nb, post_group_args, pre_row_func_nb, pre_row_args, post_row_func_nb, post_row_args, pre_segment_func_nb, pre_segment_args, post_segment_func_nb, post_segment_args, post_order_func_nb, post_order_args, ffill_val_price, update_value, fill_pos_record, row_wise, use_numba, max_orders, max_logs, seed, group_by, broadcast_named_args, broadcast_kwargs, template_mapping, wrapper_kwargs, freq, attach_call_seq, *order_args, **kwargs)
3917 if not use_numba and hasattr(simulate_func, 'py_func'):
3918 simulate_func = simulate_func.py_func
-> 3919 order_records, log_records = simulate_func(
3920 target_shape=target_shape_2d,
3921 group_lens=group_lens,
3922 init_cash=init_cash,
3923 cash_sharing=cash_sharing,
3924 call_seq=call_seq,
3925 segment_mask=segment_mask,
3926 call_pre_segment=call_pre_segment,
3927 call_post_segment=call_post_segment,
3928 pre_sim_func_nb=pre_sim_func_nb,
3929 pre_sim_args=pre_sim_args,
3930 post_sim_func_nb=post_sim_func_nb,
3931 post_sim_args=post_sim_args,
3932 pre_group_func_nb=pre_group_func_nb,
3933 pre_group_args=pre_group_args,
3934 post_group_func_nb=post_group_func_nb,
3935 post_group_args=post_group_args,
3936 pre_segment_func_nb=pre_segment_func_nb,
3937 pre_segment_args=pre_segment_args,
3938 post_segment_func_nb=post_segment_func_nb,
3939 post_segment_args=post_segment_args,
3940 order_func_nb=order_func_nb,
3941 order_args=order_args,
3942 post_order_func_nb=post_order_func_nb,
3943 post_order_args=post_order_args,
3944 close=broadcasted_args['close'],
3945 ffill_val_price=ffill_val_price,
3946 update_value=update_value,
3947 fill_pos_record=fill_pos_record,
3948 max_orders=max_orders,
3949 max_logs=max_logs,
3950 flex_2d=close.ndim == 2
3951 )
3953 # Create an instance
3954 return cls(
3955 wrapper,
3956 close,
(...)
3962 **kwargs
3963 )
File ~\anaconda3\lib\site-packages\vectorbt\portfolio\nb.py:2920, in simulate_nb(target_shape, group_lens, init_cash, cash_sharing, call_seq, segment_mask, call_pre_segment, call_post_segment, pre_sim_func_nb, pre_sim_args, post_sim_func_nb, post_sim_args, pre_group_func_nb, pre_group_args, post_group_func_nb, post_group_args, pre_segment_func_nb, pre_segment_args, post_segment_func_nb, post_segment_args, order_func_nb, order_args, post_order_func_nb, post_order_args, close, ffill_val_price, update_value, fill_pos_record, max_orders, max_logs, flex_2d)
2884 if call_pre_segment or segment_mask[i, group]:
2885 # Call function before the segment
2886 pre_seg_ctx = SegmentContext(
2887 target_shape=target_shape,
2888 group_lens=group_lens,
(...)
2918 call_seq_now=call_seq_now
2919 )
-> 2920 pre_segment_out = pre_segment_func_nb(pre_seg_ctx, *pre_group_out, *pre_segment_args)
2922 # Update open position stats
2923 if fill_pos_record:
Cell In[4], line 24, in pre_segment_func_nb(sc, find_weights_nb, rm, history_len, ann_factor, num_tests, srb_sharpe)
21 close = sc.close[sc.i - history_len:sc.i, sc.from_col:sc.to_col]
23 # Find optimal weights
---> 24 best_sharpe_ratio, weights = find_weights_nb(sc, rm, close, num_tests)
25 srb_sharpe[sc.i] = best_sharpe_ratio
27 # Update valuation price and reorder orders
Cell In[8], line 30, in opt_weights(sc, rm, close, num_tests)
27 l = 0 # Risk aversion factor, only useful when obj is 'Utility'
29 w = port.optimization(model=model, rm=rm, obj=obj, rf=rf, l=l, hist=hist)
---> 30 weights = np.ravel(w.to_numpy())
31 shp = rp.Sharpe(w, port.mu, cov=port.cov, returns=returns, rm=rm, rf=0, alpha=0.05)
33 return shp, weights
AttributeError: 'NoneType' object has no attribute 'to_numpy'
Is there a way to solve it?
Beta Was this translation helpful? Give feedback.
All reactions