Skip to content

Commit

Permalink
STY PPE8 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
twiecki committed Apr 18, 2016
1 parent 7613137 commit 124cc0d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 7 additions & 3 deletions pyfolio/round_trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from __future__ import division
from math import copysign
import warnings
from collections import deque, defaultdict, OrderedDict
from collections import deque, OrderedDict

import pandas as pd
import numpy as np
Expand Down Expand Up @@ -197,7 +197,8 @@ def extract_round_trips(transactions,
dt_stack = deque()
for dt, t in trans_sym.iterrows():
if t.price < 0:
warnings.warn('Negative price detected, ignoring for round-trip.')
warnings.warn('Negative price detected, ignoring for'
'round-trip.')
continue
signed_price = t.price * np.sign(t.amount)
abs_amount = int(abs(t.amount))
Expand Down Expand Up @@ -246,7 +247,10 @@ def extract_round_trips(transactions,
pv = pd.DataFrame(portfolio_value,
columns=['portfolio_value'])\
.assign(date=portfolio_value.index)
roundtrips['date'] = roundtrips.close_dt.apply(lambda x: x.replace(hour=0, minute=0, second=0))
roundtrips['date'] = roundtrips.close_dt.apply(lambda x:
x.replace(hour=0,
minute=0,
second=0))

tmp = roundtrips.assign(date=roundtrips.close_dt)\
.join(pv, on='date', lsuffix='_')
Expand Down
8 changes: 4 additions & 4 deletions pyfolio/tears.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def create_round_trip_tear_sheet(positions, transactions,
transactions_closed = round_trips.add_closing_transactions(positions,
transactions)
trades = round_trips.extract_round_trips(transactions_closed,
portfolio_value=positions.sum(axis='columns'))
portfolio_value=positions.sum(axis='columns'))

if len(trades) < 5:
warnings.warn(
Expand Down Expand Up @@ -744,16 +744,16 @@ def create_capacity_tear_sheet(returns, positions, transactions,

llt = capacity.get_low_liquidity_transactions(transactions, market_data)
print('Tickers with daily transactions consuming >{}% of daily bar \n'
'all backtest:'.format(trade_daily_vol_limit*100))
'all backtest:'.format(trade_daily_vol_limit * 100))
utils.print_table(
llt[llt['max_pct_bar_consumed'] > trade_daily_vol_limit*100])
llt[llt['max_pct_bar_consumed'] > trade_daily_vol_limit * 100])

llt = capacity.get_low_liquidity_transactions(
transactions, market_data, last_n_days=last_n_days)

print("last {} trading days:".format(last_n_days))
utils.print_table(
llt[llt['max_pct_bar_consumed'] > trade_daily_vol_limit*100])
llt[llt['max_pct_bar_consumed'] > trade_daily_vol_limit * 100])

bt_starting_capital = positions.iloc[0].sum() / (1 + returns.iloc[0])
fig, ax_capacity_sweep = plt.subplots(figsize=(14, 6))
Expand Down
8 changes: 4 additions & 4 deletions pyfolio/tests/test_round_trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pyfolio.round_trips import (extract_round_trips,
add_closing_transactions,
_groupby_consecutive,
)
)


class RoundTripTestCase(TestCase):
Expand Down Expand Up @@ -46,8 +46,8 @@ class RoundTripTestCase(TestCase):
[2, 20., 'A'],
[2, 10., 'A'],
],
columns=['amount', 'price', 'symbol'],
index=dates_intraday[[0, 1, 4, 5]]),
columns=['amount', 'price', 'symbol'],
index=dates_intraday[[0, 1, 4, 5]]),
DataFrame(data=[[4, 15., 'A'],
[4, 15., 'A'],
],
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_add_closing_trades(self):
index=[dates[:3]])

expected_ix = dates[:3].append(DatetimeIndex([dates[2] +
Timedelta(seconds=1)]))
Timedelta(seconds=1)]))
expected = DataFrame(data=[[2, 10, 'A'],
[-5, 10, 'A'],
[-1, 10., 'B'],
Expand Down

0 comments on commit 124cc0d

Please sign in to comment.