I am trying to set an optimal asset allocation code for Repo (Repurchase Agreement) based on the MTM (bond inventory I currently own * the price of the bond. Both inputs) given a bucket of trades (input). The optimal result allocations respond to the minimum number of count(allocations) per trade. Therefore my inputs are as follows:
bonds = ['first',"second","third","fourth","fifth"]
position= [100,110,120,130,140]
price = [10,10.1,10.2,10.3,10.4]
MTM= []
for i in range(len(bonds)):
MTM.append(position[i]*price[i])
Let say for example I want to allocate the sum(MTM) into the following trades:
trade=[1500,1500,100,500]
ToBeAllocated = {}
for x in range(len(trade)):
for i in range(len(bonds)):
ToBeAllocated[bonds[x].format(x)] = mtm[x]
The allocation has to be the optimal lowest count(of all the N allocations per trade), For example:
I can allocate the bond "first" with the MTM value of 1000 to the trade[1] and partially allocate "second" as the int(position) that solves trade[1] == sum of the MTM of the allocated bonds, therefore the position of "second" to be allocated is as follows: (1000 position*10.1)=1500 , which is 49 as we cannot allocate less than 1 bond. This trade has 2 allocations therefore it's count value of allocation is 2. The ToBeAllocated values went from:
{'first': 1000, 'second': 1111.0, 'third': 1224.0, 'fourth': 1339.0}
to the following, since we already have allocated one whole bond and another partially.
{'first': 0, 'second': 1062, 'third': 1224.0, 'fourth': 1339.0}
the values as of now of count allocations is 2. How can I find the optimal asset allocation for this problem?
CodePudding user response:
