Skip to content

Commit

Permalink
♻️ Move dividends and portfolio presenters to separate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
esemi committed Oct 24, 2020
1 parent bf4460b commit 3b543e8
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions investments/ibtax/ibtax.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ def _show_interests_report(interests: pandas.DataFrame, year: int):
print('\n\n')


def _show_portfolio_report(portfolio: List[PortfolioElement]):
def _show_dividends_report(dividends: pandas.DataFrame, year: int):
dividends_year = dividends[dividends['tax_year'] == year].drop(columns=['tax_year'])
dividends_year['N'] -= dividends_year['N'].iloc[0] - 1
_show_header('DIVIDENDS')
print(dividends_year.set_index(['N', 'ticker', 'date']).to_string())
print('\n\n')


def show_portfolio_report(portfolio: List[PortfolioElement]):
_show_header('PORTFOLIO')
for elem in portfolio:
print(f'{elem.ticker}\tx\t{elem.quantity}')
Expand All @@ -110,7 +118,7 @@ def _show_portfolio_report(portfolio: List[PortfolioElement]):

def show_report(trades: Optional[pandas.DataFrame], dividends: Optional[pandas.DataFrame],
fees: Optional[pandas.DataFrame], interests: Optional[pandas.DataFrame],
portfolio: List[PortfolioElement], filter_years: List[int]): # noqa: WPS318,WPS319
filter_years: List[int]): # noqa: WPS318,WPS319
years = set()
for report in (trades, dividends, fees, interests):
if report is not None:
Expand All @@ -122,13 +130,7 @@ def show_report(trades: Optional[pandas.DataFrame], dividends: Optional[pandas.D
print('\n', '______' * 8, f' {year} ', '______' * 8, '\n')

if dividends is not None:
dividends_year = dividends[dividends['tax_year'] == year].drop(columns=['tax_year'])
dividends_year['N'] -= dividends_year['N'].iloc[0] - 1

_show_header('DIVIDENDS')
print(dividends_year.set_index(['N', 'ticker', 'date']).to_string())
# print('\n>>> DIVIDENDS PROFIT BEFORE TAXES:\n ', dividends_year['amount_rub'].sum())
print('\n\n')
_show_dividends_report(dividends, year)

if trades is not None:
trades_year = trades[trades['tax_year'] == year].drop(columns=['tax_year', 'datetime'])
Expand Down Expand Up @@ -158,8 +160,6 @@ def show_report(trades: Optional[pandas.DataFrame], dividends: Optional[pandas.D

print('______' * 8, f'EOF {year}', '______' * 8, '\n\n\n')

_show_portfolio_report(portfolio)


def csvs_in_dir(directory: str):
ret = []
Expand Down Expand Up @@ -234,7 +234,8 @@ def main():
else:
trades_report = None

show_report(trades_report, dividends_report, fees_report, interests_report, portfolio, args.years)
show_report(trades_report, dividends_report, fees_report, interests_report, args.years)
show_portfolio_report(portfolio)


if __name__ == '__main__':
Expand Down

0 comments on commit 3b543e8

Please sign in to comment.