Skip to content

Commit

Permalink
expose position flow
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Jul 24, 2023
1 parent d804efa commit 67c283c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
17 changes: 3 additions & 14 deletions absbox/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json, datetime, pickle, re, urllib3, getpass
import json, datetime, pickle, re, urllib3, getpass, copy
from importlib.metadata import version
from json.decoder import JSONDecodeError
from dataclasses import dataclass,field
Expand Down Expand Up @@ -95,8 +95,7 @@ def validate(self, _r) -> list:
def run(self, deal,
assumptions=None,
pricing=None,
read=True,
position=None):
read=True):

# if run req is a multi-scenario run
multi_run_flag = True if isinstance(assumptions, dict) else False
Expand Down Expand Up @@ -291,14 +290,4 @@ def _send_req(self,_req,_url,timeout=10,headers={})->dict:
console.print(e)
console.rule()
return None



def save(deal,p:str):
def save_to(b):
with open(p,'wb') as _f:
pickle.dump(b,_f)

match deal:
case _:
save_to(deal)

1 change: 1 addition & 0 deletions absbox/local/china.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def read(resp):

output['pricing'] = readPricingResult(resp[3], 'cn')
output['result'] = readRunSummary(resp[2], 'cn')
output['_deal'] = resp[0]
return output


Expand Down
4 changes: 2 additions & 2 deletions absbox/local/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import functools

from absbox import *
from absbox.local.util import mkTag,mapListValBy,mapValsBy,renameKs2,guess_pool_flow_header
from absbox.local.util import mkTag,mapListValBy,mapValsBy,renameKs2,guess_pool_flow_header,positionFlow
from absbox.local.component import *
from absbox.local.base import *
import pandas as pd
Expand Down Expand Up @@ -115,5 +115,5 @@ def read(resp):

output['pricing'] = readPricingResult(resp[3], 'en')
output['result'] = readRunSummary(resp[2], 'en')

output['_deal'] = resp[0]
return output
23 changes: 22 additions & 1 deletion absbox/local/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pandas as pd
import functools,json
import functools,json,copy
import logging
import itertools,re
from enum import Enum
Expand Down Expand Up @@ -300,3 +300,24 @@ def mergeStrWithDict(s:str,m:dict) -> str:
t = json.loads(s)
t = t | m
return json.dumps(t)

def positionFlow(x,m:dict,facePerPaper=100):
_,_bflow = list(x['bonds'].items())[0]
bflowHeader = _bflow.columns.to_list()

def calcBondFlow(_bflow,factor):
bflow = copy.deepcopy(_bflow)
bflow[bflowHeader[0]] *= factor
bflow[bflowHeader[1]] *= factor
bflow[bflowHeader[2]] *= factor
bflow[bflowHeader[4]] *= factor
return bflow

assert isinstance(m, dict),"Position info must be a map/dict"

bOrignBal = {k:x['_deal']['contents']['bonds'][k]['bndOriginInfo']['originBalance'] for k,v in m.items()}
bPapersPerBond = {k:v/facePerPaper for k,v in bOrignBal.items()}

bflowFactor = {k:(v/bPapersPerBond[k]) for k,v in m.items()}

return {bn:calcBondFlow(bf,bflowFactor[bn]) for bn,bf in x['bonds'].items() if bn in m}

0 comments on commit 67c283c

Please sign in to comment.