Created
October 11, 2023 17:34
-
-
Save quantra-go-algo/d7357dfdc2eda964a30ffc652dc0315a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Summary statistics for the Buy-and-Hold strategy | |
pf.create_simple_tear_sheet(plot_data['buy_hold_cum_rets'].pct_change().dropna()) | |
# Summary statistics for the 4-day SMA strategy | |
pf.create_simple_tear_sheet(plot_data['basic_stra_cum_rets'].pct_change().dropna()) | |
# Summary statistics for the HMM-DC based 4-day SMA strategy | |
pf.create_simple_tear_sheet(plot_data['hmm_dc_stra_cum_rets'].pct_change().dropna()) |
Hello BlasdeLezo3!
There's a problem with the samy pyfolio library, actually.
I would suggest doing the following:
- Please install https://git-scm.com/downloads and then in your notebook, in the very first line, code:
- !pip install git+https://github.com/quantopian/pyfolio
- Try running the pyfolio method again. Then it will run correctly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AttributeError Traceback (most recent call last)
Input In [12], in <cell line: 1>()
----> 1 pf.create_simple_tear_sheet(plot_data['buy_hold_cum_rets'].pct_change().dropna())
2 pf.create_simple_tear_sheet(plot_data['basic_stra_cum_rets'].pct_change().dropna())
3 pf.create_simple_tear_sheet(plot_data['hmm_dc_stra_cum_rets'].pct_change().dropna())
File ~/miniforge3/lib/python3.10/site-packages/pyfolio/plotting.py:52, in customize..call_w_context(*args, **kwargs)
50 if set_context:
51 with plotting_context(), axes_style():
---> 52 return func(*args, **kwargs)
53 else:
54 return func(*args, **kwargs)
File ~/miniforge3/lib/python3.10/site-packages/pyfolio/tears.py:359, in create_simple_tear_sheet(returns, positions, transactions, benchmark_rets, slippage, estimate_intraday, live_start_date, turnover_denom, header_rows)
356 if live_start_date is not None:
357 live_start_date = ep.utils.get_utc_timestamp(live_start_date)
--> 359 plotting.show_perf_stats(returns,
360 benchmark_rets,
361 positions=positions,
362 transactions=transactions,
363 turnover_denom=turnover_denom,
364 live_start_date=live_start_date,
365 header_rows=header_rows)
367 fig = plt.figure(figsize=(14, vertical_sections * 6))
368 gs = gridspec.GridSpec(vertical_sections, 3, wspace=0.5, hspace=0.5)
File ~/miniforge3/lib/python3.10/site-packages/pyfolio/plotting.py:648, in show_perf_stats(returns, factor_returns, positions, transactions, turnover_denom, live_start_date, bootstrap, header_rows)
645 perf_stats = pd.DataFrame(perf_stats_all, columns=['Backtest'])
647 for column in perf_stats.columns:
--> 648 for stat, value in perf_stats[column].iteritems():
649 if stat in STAT_FUNCS_PCT:
650 perf_stats.loc[stat, column] = str(np.round(value * 100,
651 1)) + '%'
File ~/miniforge3/lib/python3.10/site-packages/pandas/core/generic.py:5989, in NDFrame.getattr(self, name)
5982 if (
5983 name not in self._internal_names_set
5984 and name not in self._metadata
5985 and name not in self._accessors
5986 and self._info_axis._can_hold_identifiers_and_holds_name(name)
5987 ):
5988 return self[name]
-> 5989 return object.getattribute(self, name)
AttributeError: 'Series' object has no attribute 'iteritems'