【发布时间】:2020-10-14 14:52:05
【问题描述】:
此代码生成一个字典列表。
watchlist = r.get_open_option_positions()
for x in watchlist:
print('Symbol: {}, Average Price: {}, Quantity: {}'.format(x['chain_symbol'],
x['average_price'], x['quantity']))
输出:
Symbol: PG, Average Price: -46.5714, Quantity: 35.0000
Symbol: PG, Average Price: 33.7142, Quantity: 35.0000
Symbol: MSFT, Average Price: -80.0000, Quantity: 6.0000
Symbol: MSFT, Average Price: 53.0000, Quantity: 6.0000
如何编码以下标准:
if symbol is the same and quantity of both symbols is the same, then subtract average prices and multiply by quantity
所以例如结果应该是这样的:
Symbol: PG, Average Price: (-12.8572 * 35), Quantity: 35.000
Symbol: MSFT, Average Price: (-27 * 6), Quantity: 6.000
【问题讨论】:
-
您是希望仅将具有此条件的连续项目分组,还是将监视列表中的所有内容分组?
-
关注列表中的一切都会更好
标签: python list dictionary merge finance