Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor timeseries.py #262

Merged
merged 10 commits into from
Dec 23, 2015
11 changes: 6 additions & 5 deletions pyfolio/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import division
from collections import OrderedDict

import pandas as pd
import numpy as np
Expand Down Expand Up @@ -510,13 +511,13 @@ def show_perf_stats(returns, factor_returns, live_start_date=None):
perf_stats = np.round(timeseries.perf_stats(
returns_backtest,
factor_returns=factor_returns), 2)
perf_stats.columns = ['Backtest']

if live_start_date is not None:
perf_stats = perf_stats.join(perf_stats_live,
how='inner')
perf_stats = perf_stats.join(perf_stats_all,
how='inner')
perf_stats = pd.DataFrame(OrderedDict([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, I didn't know dataframe respected ordered dict key ordering until now

('Backtest', perf_stats),
('Out of sample', perf_stats_live),
('All history', perf_stats_all),
]))

print(perf_stats)

Expand Down
28 changes: 0 additions & 28 deletions pyfolio/tears.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ def create_returns_tear_sheet(returns, live_start_date=None,
ax_monthly_dist = plt.subplot(gs[8, 2])
ax_return_quantiles = plt.subplot(gs[9, :])

if live_start_date is not None:
ax_daily_similarity_scale = plt.subplot(gs[10, 0])
ax_daily_similarity_no_var = plt.subplot(gs[10, 1])
ax_daily_similarity_no_var_no_mean = plt.subplot(gs[10, 2])

plotting.plot_rolling_returns(
returns,
factor_returns=benchmark_rets,
Expand Down Expand Up @@ -322,29 +317,6 @@ def create_returns_tear_sheet(returns, live_start_date=None,
df_monthly,
ax=ax_return_quantiles)

if live_start_date is not None:
returns_backtest = returns[returns.index < live_start_date]
returns_live = returns[returns.index > live_start_date]

plotting.plot_daily_returns_similarity(
returns_backtest,
returns_live,
title='Daily Returns Similarity',
ax=ax_daily_similarity_scale)
plotting.plot_daily_returns_similarity(
returns_backtest,
returns_live,
scale_kws={'with_std': False},
title='Similarity without\nvariance normalization',
ax=ax_daily_similarity_no_var)
plotting.plot_daily_returns_similarity(
returns_backtest,
returns_live,
scale_kws={'with_std': False,
'with_mean': False},
title='Similarity without variance\nand mean normalization',
ax=ax_daily_similarity_no_var_no_mean)

for ax in fig.axes:
plt.setp(ax.get_xticklabels(), visible=True)

Expand Down
2 changes: 1 addition & 1 deletion pyfolio/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def test_sharpe_2(self, returns, rolling_sharpe_window, expected):
returns, rolling_sharpe_window).values.tolist()), expected)

@parameterized.expand([
(simple_rets, 0.010766923838471554)
(simple_rets, 0.10376378866671222)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what caused this test to change, the only bug commit I see is the df join

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bb13b0a. You're right that it should be a BUG commit as the original implementation wasn't correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded that commit: ca8567e

])
def test_stability_of_timeseries(self, returns, expected):
self.assertAlmostEqual(
Expand Down
Loading