Skip to content

Commit

Permalink
Improve accuracy for the display of fractional shares (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
ExploracuriousAlex authored Sep 23, 2024
1 parent 63f64ca commit fbb9c75
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pytr/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def portfolio_to_csv(self, output_path):
csv_lines = []
for pos in sorted(positions, key=lambda x: x['netSize'], reverse=True):
csv_lines.append(
f"{pos['name']};{pos['instrumentId']};{float(pos['averageBuyIn']):.2f};{float(pos['netValue']):.2f}"
f"{pos['name']};{pos['instrumentId']};{float(pos['netSize']):>10.3f};{float(pos['averageBuyIn']):.2f};{float(pos['netValue']):.2f}"
)

with open(output_path, 'w', encoding='utf-8') as f:
f.write('Name;ISIN;avgCost;netValue\n')
f.write('Name;ISIN;quantity;avgCost;netValue\n')
f.write('\n'.join(csv_lines))

print(f'Wrote {len(csv_lines) + 1} lines to {output_path}')
Expand Down Expand Up @@ -116,7 +116,7 @@ def overview(self):
totalNetValue += float(pos['netValue'])

print(
f"{pos['name']:<25.25} {pos['instrumentId']} {float(pos['averageBuyIn']):>10.2f} * {float(pos['netSize']):>10.2f}"
f"{pos['name']:<25.25} {pos['instrumentId']} {float(pos['averageBuyIn']):>10.2f} * {float(pos['netSize']):>10.3f}"
+ f" = {float(buyCost):>10.2f} -> {float(pos['netValue']):>10.2f} {diff:>10.2f} {diffP:>7.1f}%"
)

Expand Down

0 comments on commit fbb9c75

Please sign in to comment.