backtest error

When I run backtest function, it gives me this error


‘c’ argument has 6 elements, which is not acceptable for use with ‘x’ with size 10, ‘y’ with size 10.

And it can calculate portfolio summary and plot Portfolio Total Return, but it fails to plot other pictures.

Code:

tickers = list(set(tickers_df[‘ticker’]))
port = alphien.portfolio.Portfolio(tickers)
port.addFeatures(fields=‘OHLCV’,startDate=“2010-01-01”, endDate=“2010-12-31”)
port.payout(jiucai_simple_Payout)
#port.evaluate(zoom=“2010::2010”)
port.evaluate()
port.backtest()



Can you provide the full traceback pls?

Values for CBSS.US Equity, APCC.US Equity, UVN.US Equity, PGL.US Equity, EOP.US Equity, TRB.US Equity, SLR.US Equity, BOL.US Equity, LEH.US Equity, TXU.US Equity, MEL.US Equity, WWY.US Equity, BRL.US Equity, KSE.US Equity, MEDI.US Equity, AW.US Equity, TEK.US Equity, BMET.US Equity, SGP.US Equity, SBL.US Equity, ROH.US Equity, ABK.US Equity, DJ.US Equity, MER.US Equity, SOV.US Equity, CTX.US Equity, HPC.US Equity, NCC.US Equity, WYE.US Equity, CMX.US Equity, CFC.US Equity, ASN.US Equity at requested dates have been coerced to NaN.

 

           Found 45 day(s) where weights are assigned but 1 or more markets are closed.

           These weights will be assigned to their next trading day unless there are already weights on that day.

 

           Portfolio Summary:

           ================

           Annualised Return:     20.43%

           Total Return:          19.76%

           Annualised volatility: 20.51%

           Maximum Drawdown:     -15.79%  

           Sharpe Ratio:           1.00

           Calmar Ratio:           1.29

           

 

The output have been limited to the top 5 and bottom 5 assets by sharpe ratio in the portfolio.

 

---------------------------------------------------------------------------

ValueError                               Traceback (most recent call last)

/opt/conda/lib/python3.6/site-packages/matplotlib/axes/_axes.py in _parse_scatter_color_args(c, edgecolors, kwargs, xshape, yshape, get_next_color_func)

  4282                    valid_shape = False

-> 4283                    raise ValueError

  4284            except ValueError:

 

ValueError:

 

During handling of the above exception, another exception occurred:

 

ValueError                               Traceback (most recent call last)

<ipython-input-36-0fd355ce105d> in <module>

     5 #port.evaluate(zoom=“2010::2010”)

     6 port.evaluate()

----> 7 port.backtest()

 

/mnt/public/IT/Libs/Python/alphien/portfolio/portfolio.py in backtest(self, zoom, period, plot, printStats, tc, fc, rp)

   677            returnsVsVol.plot.scatter(x=0, y=1, s=(returnsVsVol[‘Sharpe’].values+2np.abs(returnsVsVol[‘Sharpe’].min()))/

   678                                      (returnsVsVol[‘Sharpe’]+2np.abs(returnsVsVol[‘Sharpe’].min())).sum()10000,

–> 679                                      c=colours[:returnsVsVol.shape[0]], ax=ax2, title=‘Asset Return Vs Volatility (annualised)’)

   680            #add labels to each point

   681            for i, asset in enumerate(returnsVsVol.index):

 

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_core.py in scatter(self, x, y, s, c, kwargs)

  1611            …                      colormap=‘viridis’)

  1612        “”"

-> 1613        return self(kind=“scatter”, x=x, y=y, s=s, c=c, kwargs)

  1614

  1615    def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, kwargs):

 

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_core.py in call(self, *args, kwargs)

   892        if kind in self._dataframe_kinds:

   893            if isinstance(data, ABCDataFrame):

–> 894                return plot_backend.plot(data, x=x, y=y, kind=kind, kwargs)

   895            else:

   896                raise ValueError(f"plot kind {kind} can only be used for data frames")

 

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_matplotlib/init.py in plot(data, kind, kwargs)

    59            kwargs[“ax”] = getattr(ax, “left_ax”, ax)

    60    plot_obj = PLOT_CLASSES[kind](data, kwargs)

—> 61    plot_obj.generate()

    62    plot_obj.draw()

    63    return plot_obj.result

 

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py in generate(self)

   269        self._compute_plot_data()

   270        self._setup_subplots()

–> 271        self._make_plot()

   272        self._add_table()

   273        self._make_legend()

 

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py in _make_plot(self)

  1014            label=label,

  1015            cmap=cmap,

-> 1016            self.kwds,

  1017        )

  1018        if cb:

 

/opt/conda/lib/python3.6/site-packages/matplotlib/init.py in inner(ax, data, args, **kwargs)

  1587    def inner(ax, args, data=None, **kwargs):

  1588        if data is None:

-> 1589            return func(ax, map(sanitize_sequence, args), kwargs)

  1590

  1591        bound = new_sig.bind(ax, *args, kwargs)

 

/opt/conda/lib/python3.6/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, **kwargs)

  4444            self._parse_scatter_color_args(

  4445                c, edgecolors, kwargs, xshape, yshape,

-> 4446                get_next_color_func=self._get_patches_for_fill.get_next_color)

  4447

  4448        if plotnonfinite and colors is None:

 

/opt/conda/lib/python3.6/site-packages/matplotlib/axes/_axes.py in _parse_scatter_color_args(c, edgecolors, kwargs, xshape, yshape, get_next_color_func)

  4288                        "acceptable for use with ‘x’ with size {xs}, "

  4289                        “‘y’ with size {ys}.”

-> 4290                            .format(nc=n_elem, xs=xsize, ys=ysize)

  4291                    )

  4292                else:

 

ValueError: ‘c’ argument has 6 elements, which is not acceptable for use with ‘x’ with size 10, ‘y’ with size 10.