Consider removing the commented out code block
79 },
80
81 include_package_data=True,
82 # package_data={83 # 'static': 'quantstats/report.html*'
84 # },
85)
Consider removing the commented out code block
9"""
10
11from setuptools import setup, find_packages
12# from codecs import open13import io
14from os import path
15
Consider removing the commented out code block
956
957 alpha = df["returns"].mean() - beta * df["benchmark"].mean()
958
959 # alpha = alpha * periods 960 return _pd.DataFrame(index=returns.index, data={"beta": beta, "alpha": alpha})
961
962
Consider removing the commented out code block
887
888def r_squared(returns, benchmark, prepare_returns=True):
889 """Measures the straight line fit of the equity curve"""
890 # slope, intercept, r_val, p_val, std_err = _linregress( 891 if prepare_returns:
892 returns = _utils._prepare_returns(returns)
893 _, _, r_val, _, _ = _linregress(
Consider removing the commented out code block
259 if isinstance(returns, _pd.DataFrame):
260 returns = returns[returns.columns[0]]
261
262 # returns.to_csv('/Users/ran/Desktop/test.csv') 263 num = len(returns)
264 coef = _np.abs(_np.corrcoef(returns[:-1], returns[1:])[0, 1])
265 corr = [((num - x) / num) * coef**x for x in range(1, num)]
Consider removing the commented out code block
958
959 metrics["Gain/Pain Ratio"] = _stats.gain_to_pain_ratio(df, rf)
960 metrics["Gain/Pain (1M)"] = _stats.gain_to_pain_ratio(df, rf, "M")
961 # if mode.lower() == 'full': 962 # metrics['GPR (3M)'] = _stats.gain_to_pain_ratio(df, rf, "Q")
963 # metrics['GPR (6M)'] = _stats.gain_to_pain_ratio(df, rf, "2Q")
964 # metrics['GPR (1Y)'] = _stats.gain_to_pain_ratio(df, rf, "A")
Consider removing the commented out code block
852 if mode.lower() == "full":
853 # metrics['Prob. Sortino Ratio %'] = _stats.probabilistic_sortino_ratio(df, rf, win_year, False) * pct
854 metrics["Smart Sortino"] = _stats.smart_sortino(df, rf, win_year, True)
855 # metrics['Prob. Smart Sortino Ratio %'] = _stats.probabilistic_sortino_ratio(df, rf, win_year, False, True) * pct 856
857 metrics["Sortino/√2"] = metrics["Sortino"] / _sqrt(2)
858 if mode.lower() == "full":
Consider removing the commented out code block
850
851 metrics["Sortino"] = _stats.sortino(df, rf, win_year, True)
852 if mode.lower() == "full":
853 # metrics['Prob. Sortino Ratio %'] = _stats.probabilistic_sortino_ratio(df, rf, win_year, False) * pct 854 metrics["Smart Sortino"] = _stats.smart_sortino(df, rf, win_year, True)
855 # metrics['Prob. Smart Sortino Ratio %'] = _stats.probabilistic_sortino_ratio(df, rf, win_year, False, True) * pct
856
Consider removing the commented out code block
846 )
847 if mode.lower() == "full":
848 metrics["Smart Sharpe"] = _stats.smart_sharpe(df, rf, win_year, True)
849 # metrics['Prob. Smart Sharpe Ratio %'] = _stats.probabilistic_sharpe_ratio(df, rf, win_year, False, True) * pct 850
851 metrics["Sortino"] = _stats.sortino(df, rf, win_year, True)
852 if mode.lower() == "full":
Consider removing the commented out code block
757 else:
758 blank = [""]
759
760 # if isinstance(returns, _pd.DataFrame): 761 # if len(returns.columns) > 1:
762 # raise ValueError("`returns` needs to be a Pandas Series or one column DataFrame. multi colums DataFrame was passed")
763 # returns = returns[returns.columns[0]]
Consider removing the commented out code block
1023 cmap=cmap,
1024 cbar_kws={"format": "%.0f%%"},
1025 )
1026 # _sns.set(font_scale=1)1027
1028 # align plot to match other
1029 if ylabel:
Consider removing the commented out code block
973 fig.set_facecolor("white")
974 ax.set_facecolor("white")
975
976 # _sns.set(font_scale=.9) 977 if active and benchmark is not None:
978 ax.set_title(
979 f"{returns_label} - Monthly Active Returns (%)\n",
Consider removing the commented out code block
948 show=True,
949 active=False,
950):
951 # colors, ls, alpha = _core._get_colors(grayscale) 952 cmap = "gray" if grayscale else "RdYlGn"
953
954 returns = _stats.monthly_returns(returns, eoy=eoy, compounded=compounded) * 100
Consider removing the commented out code block
217 axes[2].axhline(0, color=colors[-1], linestyle="--", lw=1, zorder=2)
218
219 axes[2].set_yscale("symlog" if log_scale else "linear")
220 # axes[2].legend(fontsize=12) 221
222 retmax = _utils._round_to_closest(returns.max() * 100, 5)
223 retmin = _utils._round_to_closest(returns.min() * 100, 5)
Consider removing the commented out code block
199 )
200
201 axes[1].set_yscale("symlog" if log_scale else "linear")
202 # axes[1].legend(fontsize=12) 203
204 axes[2].set_ylabel(
205 "Daily Return", fontname=fontname, fontweight="bold", fontsize=12
Consider removing the commented out code block
180 ddmin_ticks = ddmin / 3
181 ddmin_ticks = int(_utils._round_to_closest(ddmin_ticks, 5))
182
183 # ddmin_ticks = int(_utils._round_to_closest(ddmin, 5)) 184 axes[1].set_ylabel("Drawdown", fontname=fontname, fontweight="bold", fontsize=12)
185 axes[1].set_yticks(_np.arange(-ddmin, 0, step=ddmin_ticks))
186 if isinstance(dd, _pd.Series):
Consider removing the commented out code block
169 axes[0].axhline(0, color="silver", lw=1, zorder=0)
170
171 axes[0].set_yscale("symlog" if log_scale else "linear")
172 # axes[0].legend(fontsize=12) 173
174 dd = _stats.to_drawdown_series(returns) * 100
175 ddmin = _utils._round_to_closest(abs(dd.min()), 5)
Consider removing the commented out code block
176 ax.set_xticklabels(df.index)
177 years = sorted(list(set(df.index)))
178
179 # ax.fmt_xdata = _mdates.DateFormatter('%Y-%m-%d') 180 # years = sorted(list(set(df.index.year)))
181 if len(years) > 10:
182 mod = int(len(years) / 10)
Consider removing the commented out code block
196
197 ax.axhline(0, ls="--", lw=1, color="#000000", zorder=2)
198
199 # if isinstance(benchmark, _pd.Series) or hline: 200 ax.legend(fontsize=11)
201
202 _plt.yscale("symlog" if log_scale else "linear")
Consider removing the commented out code block
328 if isinstance(returns, _pd.Series):
329 ax.plot(returns, lw=lw, label=returns.name, color=colors[1], alpha=alpha)
330 elif isinstance(returns, _pd.DataFrame):
331 # color_dict = {col: colors[i+1] for i, col in enumerate(returns.columns)} 332 for i, col in enumerate(returns.columns):
333 ax.plot(returns[col], lw=lw, label=col, alpha=alpha, color=colors[i + 1])
334
Consider removing the commented out code block
356 ax.axhline(0, ls="-", lw=1, color="gray", zorder=1)
357 ax.axhline(0, ls="--", lw=1, color="white" if grayscale else "black", zorder=2)
358
359 # if isinstance(benchmark, _pd.Series) or hline is not None: 360 ax.legend(fontsize=11)
361
362 _plt.yscale("symlog" if log_scale else "linear")
Consider removing the commented out code block
363
364 if percent:
365 ax.yaxis.set_major_formatter(_FuncFormatter(format_pct_axis))
366 # ax.yaxis.set_major_formatter(_plt.FuncFormatter( 367 # lambda x, loc: "{:,}%".format(int(x*100))))
368
369 ax.set_xlabel("")
Consider removing the commented out code block
420 show=True,
421):
422
423 # colors = ['#348dc1', '#003366', 'red'] 424 # if grayscale:
425 # colors = ['silver', 'gray', 'black']
426
Consider removing the commented out code block
530 .reset_index()
531 .rename(columns={"level_1": "", 0: "Returns"})
532 )
533 # _sns.kdeplot(data=combined_returns, color='black', ax=ax) 534 x = _sns.histplot(
535 data=combined_returns,
536 x="Returns",
Consider removing the commented out code block
554 color="red",
555 )
556
557 # _plt.setp(x.get_legend().get_texts(), fontsize=11) 558 ax.xaxis.set_major_formatter(
559 _plt.FuncFormatter(lambda x, loc: "{:,}%".format(int(x * 100)))
560 )
Description
It is recommended to remove any commented code in your codebase.
Bad practice
for item in sequence:
# print(item)
do_something(item)
# def old_function():
# '''Older implementation that has been replaced'''
# data = get_data()
# api.post(data)
Recommended
for item in sequence:
do_something(item)