Vote count: 0
I am trying to create dictionaries that will be order requests for a portfolio of funds. The dictionaries will be exported as JSON files, just to give a bit of context. This is what the dictionaries look like.
{
"accountID":"02e57c7d-d071-4c63-b491-1194a9939ea5.1452548617456",
"accountNo":"DWTE000005",
"userID":"02e57c7d-d071-4c63-b491-1194a9939ea5",
"accountType":2,
"ordType":"1",
"side":"B",
"instrumentID":"06926627-e950-48f3-9c53-b679f61120ec",
"orderQty":1.4312,
"comment":""
}
The condition that the dictionaries will be created upon are if the target weightings are above 0, as follows.
targetportfolio = {
'VXUS' : 0.2,
'GOVT' : 0,
'IVW' : 0.2,
'EEM' : 0.2,
'JNK' : 0,
'VDE' : 0.15,
'LQD' : 0,
'IJR' : 0.1,
'BIL' : 0,
'AAXJ' : 0.15
}
Where each fund (for example VXUS) will have an order generated if the amount in the target portfolio dict is greater than 0. I was thinking of something along the lines of the code below, but I am quite confused. Any ideas?
def ordergen(portfolio):
for i in portfolio:
{
"accountID" : "02e57c7d-d071-4c63-b491-1194a9939ea5.1452548617456",
"accountNo" : "DWTE000005",
"userID" : "02e57c7d-d071-4c63-b491-1194a9939ea5",
"accountType" : 2,
"ordType" : "1",
"side" : "B",
"instrumentID" :fundID[i],
"orderQty" : ,
"comment":""
}
asked 36 secs ago
Creating Python dictionaries based on a condition
Aucun commentaire:
Enregistrer un commentaire