Skip to content

Commit fbb9c75

Browse files
Improve accuracy for the display of fractional shares (#119)
1 parent 63f64ca commit fbb9c75

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pytr/portfolio.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def portfolio_to_csv(self, output_path):
8484
csv_lines = []
8585
for pos in sorted(positions, key=lambda x: x['netSize'], reverse=True):
8686
csv_lines.append(
87-
f"{pos['name']};{pos['instrumentId']};{float(pos['averageBuyIn']):.2f};{float(pos['netValue']):.2f}"
87+
f"{pos['name']};{pos['instrumentId']};{float(pos['netSize']):>10.3f};{float(pos['averageBuyIn']):.2f};{float(pos['netValue']):.2f}"
8888
)
8989

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

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

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

0 commit comments

Comments
 (0)