Skip to content

Commit

Permalink
✨ Update trades report example for actual version
Browse files Browse the repository at this point in the history
  • Loading branch information
esemi committed Nov 23, 2020
1 parent 4c3ec2e commit fda2f79
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 17 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ $ pip install investments --upgrade --user
- пока **НЕ** поддерживаются сделки Forex, сделка пропускается и выводится сообщение о том, что это может повлиять на итоговый отчет

*Пример отчета:*
TODO UPDATE example
![ibtax report example](./images/ibtax_2016.jpg)
![ibtax report example](./images/ibtax_2020.jpg)


### Запуск
Expand Down
Binary file removed images/ibtax_2016.jpg
Binary file not shown.
Binary file added images/ibtax_2020.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 3 additions & 9 deletions investments/data_providers/cbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,11 @@ def __init__(self, currency: Currency, year_from: int = 2000, cache_dir: str = N
def dataframe(self) -> pandas.DataFrame:
return self._df

def get_rate(self, dt: datetime.date) -> Money:
if isinstance(dt, datetime.datetime):
dt = datetime.datetime.combine(dt.date(), datetime.datetime.min.time())

if isinstance(dt, datetime.date):
dt = datetime.datetime.combine(dt, datetime.datetime.min.time())

def get_rate(self, dt: datetime.datetime) -> Money:
return self._df.loc[dt].item()

def convert_to_rub(self, source: Money, rate_date: datetime.date) -> Money:
assert isinstance(rate_date, datetime.date)
def convert_to_rub(self, source: Money, rate_date: datetime.datetime) -> Money:
assert isinstance(rate_date, datetime.datetime)

if source.currency == Currency.RUB:
return Money(source.amount, Currency.RUB)
Expand Down
2 changes: 1 addition & 1 deletion investments/ibtax/ibtax.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def prepare_trades_report(finished_trades: List[FinishedTrade], cbr_client_usd:
trade_date_column = 'trade_date'
tax_date_column = 'settle_date'

df = pandas.DataFrame(finished_trades, columns=finished_trades[0]._fields) # noqa: WPS437
df = pandas.DataFrame(finished_trades, columns=finished_trades[0].fields)

df[trade_date_column] = df[trade_date_column].dt.normalize()
df[tax_date_column] = pandas.to_datetime(df[tax_date_column])
Expand Down
4 changes: 0 additions & 4 deletions investments/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class Trade(NamedTuple):
# комиссия за сделку
fee: Money

@property
def settle_datetime(self) -> datetime.datetime:
return datetime.datetime.combine(self.settle_date, datetime.datetime.min.time())

@property
def fee_per_piece(self) -> Money:
"""Комиссия за сделку за одну бумагу, полезно для расчёта налогов."""
Expand Down
4 changes: 4 additions & 0 deletions investments/trades_fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class FinishedTrade(NamedTuple):
# комиссия за сделку с одной бумагой, "-"
fee_per_piece: Money

@property
def fields(self) -> Tuple[str, ...]:
return self._fields


class PortfolioElement(NamedTuple):
ticker: Ticker
Expand Down
2 changes: 1 addition & 1 deletion tests/data_providers/cbr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(datetime(2015, 3, 8), Currency.USD, Money('59.9938', Currency.RUB)),
(datetime(2020, 3, 31), Currency.USD, Money('77.7325', Currency.RUB)),
(datetime(2020, 1, 9), Currency.USD, Money('61.9057', Currency.RUB)),
(date(2020, 2, 4), Currency.EUR, Money('70.7921', Currency.RUB)),
(datetime(2020, 2, 4), Currency.EUR, Money('70.7921', Currency.RUB)),

(datetime(2015, 3, 7), Currency.EUR, Money('66.1012', Currency.RUB)),
(datetime(2015, 1, 15), Currency.EUR, Money('77.9629', Currency.RUB)),
Expand Down

0 comments on commit fda2f79

Please sign in to comment.