Pricing Currency Override in bloomberg api wrapper blp - bloomberg

I'm using the BLP Package as a wrapper around Bloomberg's API.
In the excel bloomberg api, I'm pulling a ticker called FUND_TOTAL_ASSETS. That value can be in any of several currencies. But by adding the "FX=USD" parameter to my BDH() query, it normalizes all the values to USD. Eg. ticker '1671 JP Equity' for 'FUND_TOTAL_ASSETS' field becomes 188.3905USD instead of 25915. =#BDH(E$4,E$6,$B1,$B2,"Dir=V","CDR=5D","Days=A","FX=USD","Dts=H","cols=1;rows=22")
I want to pull up the same data with the same conversion-to-usd operation using blp wrapper. I thought that I can do this via an override parameter.
From the bloomberg api guide I see
so I thought something like the following would work:
xf = bquery.bdh(securities=search, fields=['FUND_TOTAL_ASSETS',],
start_date=dt.date(2022,10,1).strftime("%Y%m%d"),
end_date=dt.datetime.now().date().strftime("%Y%m%d"),
overrides= [('currency','USD')])
It returns the data, but the value remains in the native currency.
I tried the same code as the excel api (FX,USD) but that fails with a bloomberg INVALID_OVERRIDE_FIELD.

The underlying Bloomberg DAPI differentiates between Overrides and Options (but even then there is some confusing overlap).
Typically an Override is applied to a Bloomberg Field. Eg the field FUND_CRNCY_ADJ_TOTAL_ASSETS for 1671 JP Equity has an override of FUND_TOTAL_ASSETS_CRNCY, where you can set the currency. You can see this by typing 1671 JP Equity FLDS in the Terminal and searching the available fields. The overrides are specific to the field.
In addition the HistoricalDataRequest schema also has various options which can be specified. These are elements of the request, in the same way as startDate and endDate. These are the options in the reference to which the OP links. The options apply to all the fields and usually govern how the data is returned (eg date periodicity).
With the blp package, options are supplied as a dictionary of key:value pairs.
This snippet demonstrates how this can be done to specify the currency of the returned data:
from blp import blp
import datetime as dt
bquery = blp.BlpQuery().start()
dtEnd = dt.datetime.now().date()
dtStart = dtEnd - dt.timedelta(days=7)
xf = bquery.bdh(securities='1671 JP Equity', fields=['FUND_TOTAL_ASSETS',],
start_date=dtStart.strftime("%Y%m%d"),
end_date=dtEnd.strftime("%Y%m%d"))
print(xf)
xfUSD = bquery.bdh(securities='1671 JP Equity', fields=['FUND_TOTAL_ASSETS',],
start_date=dtStart.strftime("%Y%m%d"),
end_date=dtEnd.strftime("%Y%m%d"),
options={'currency':'USD'})
print(xfUSD)
The output should reflect the different currency used.

Related

Odoo: how to set default field for many2many field by id?

i want to set default value in many2many field for example:
that field in models.py:
# alarms
alarm_ids = fields.Many2many(
'calendar.alarm', 'calendar_alarm_calendar_event_rel',
string='Reminders', ondelete="restrict",
help="Notifications sent to all attendees to remind of the meeting.")
also it is default values created by system, and i want first variant by default:
i know that i can set it by id, but dont know how.
You can use Command to set X2many field values.
From the documentation:
Via Python, we encourage developers craft new commands via the various functions of this namespace. We also encourage developers to use the command identifier constant names when comparing the 1st element of existing commands.
Example:
from odoo import Command, models, fields
class CalendarEvent(models.Model):
_inherit = 'calendar.event'
alarm_ids = fields.Many2many(default=lambda self: [Command.link(self.env.ref('calendar.alarm_notif_1').id)])
i just watch in postgres, there is no id`s like in xml screenshots, i just take id of a record and find some documentation.
next example works:

BAPI/FM to search prod orders confirmations by workcenter and date?

I'm trying to figure out which BAPI/FM I could use to search amounts confirmed based on search criteria of date (+time if possible) and workcenter confirmed where was confirmed...
I would be using BAPI_PRODORDCONF_GETDETAIL which contains these informations, but according to BAPI guide I can only load in the data of confirmation number+confirmation counter.
Therefore the option would be to run BAPI_PRODORDCONF_GETLIST (but I can only input the production order range or confirmation number range), then filter what includes the workcenter and date I need and from those pick up confirmation number+counter and run it through BAPI_PRODORDCONF_GETDETAIL.
but this procedure of getting list of everything without data being filtered on serverside is extemly timeconsuming and out of SAP Gui I have timeout error... therefore I need any BAPI/FM which I could input the workcenter where was confirmed and date, and have the data filtered already...
Any ideas how to do that?
As far as I know there is no such standard FM, so your only choice is custom development.
I would suggest you MCPK transaction were this info is exposed in a handy form, but as I see that your requirement is to receive this info externally this is not appropriate for you.
The confirmations reside in AFRU table and workcenters are in CRHD, so to find confirmed quantities by workcenter you should join these tables, or use a view u_15673 where this info is linked:
TYPES: BEGIN OF prod_orders,
rueck TYPE afru-rueck, "confirmation number
rmzhl TYPE afru-rmzhl," confirmation counter
gmnga TYPE afru-gmnga, " quantity
arbid TYPE crhd-arbpl, " workcenter
END OF prod_orders.
DATA: orders TYPE TABLE OF prod_orders.
SELECT *
FROM u_15673
INTO CORRESPONDING FIELDS OF TABLE orders
WHERE isdd >= '20180101' AND isdz <= '163000'.
To pull this externally, you must create RFC-enabled FM or use RFC_READ_TABLE and fetch this view with parameters, here is the sample.
Another approach is to use RFC_ABAP_INSTALL_AND_RUN. You must create an ABAP program that uses WRITE for output the results as a standard list to screen.
Send the lines of this program to RFC_ABAP_INSTALL_AND_RUN to PROGRAM parameter and the code will be executed on the remote system and this FM will return screen results as the lines of table WRITES.
Possible sample based on MCPK tcode to send to RFC_ABAP_INSTALL_AND_RUN:
CLEAR lwa_selection.
lwa_selection-selname = 'SL_SPTAG'.
lwa_selection-sign = 'I'.
lwa_selection-option = 'BT'.
lwa_selection-low = '20180101'.
lwa_selection-high = '20201231'.
APPEND lwa_selection TO li_selection.
CLEAR lwa_selection.
lwa_selection-selname = 'SL_ARBPL'.
lwa_selection-sign = 'I'.
lwa_selection-option = 'EQ'.
lwa_selection-low = '10400001'.
APPEND lwa_selection TO li_selection.
SUBMIT rmcf0200 WITH SELECTION-TABLE li_selection
with par_stat = abap_true
EXPORTING LIST TO MEMORY
AND RETURN.
DATA: xlist TYPE TABLE OF abaplist.
DATA: xtext TYPE TABLE OF char200.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = xlist.
CALL FUNCTION 'LIST_TO_TXT'
EXPORTING
list_index = -1
TABLES
listtxt = xtext
listobject = xlist.
IF sy-subrc = 0.
LOOP AT xtext ASSIGNING FIELD-SYMBOL(<text>).
WRITE <xtext>.
ENDLOOP.
ENDIF.
However, this approach is not flexible because MCPK standard layout is a bit different than you want, and is not easy to adjust programmatically.
Because of that I recommend to stick to the RFC_READ_TABLE approach.

USPS API not returning Commitment Date

My client needs to know how long it will take to ship their time sensitive product for FedEx and USPS. I'm using the GetRates function of DotNetShipping but the Commitment Date is coming back as null and being set to 30 days by DotNetShipping which isn't helpful. Are there particular parameters for the USPS Web Tools API that have to be passed in in order to get a Commitment Date? I know that when I call the USPS API directly, with the following URL, I do get a Commitment Date in the return data.
http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML=<RateV4Request USERID="[USPSUSERID]"><Revision>2</Revision><Package ID="2ND"><Service>PRIORITY</Service><ZipOrigination>44106</ZipOrigination><ZipDestination>20770</ZipDestination><Pounds>1</Pounds><Ounces>0</Ounces><Container>RECTANGULAR</Container><Size>LARGE</Size><Width>11</Width><Length>13</Length><Height>11</Height><Girth>55</Girth><Value>1000</Value><SpecialServices><SpecialService>1</SpecialService></SpecialServices></Package></RateV4Request>
The above URL won't work without replacing [USPSUSERID] with a valid user ID.
I had to modify DotNetShipping to pass in Value and SpecialServices -> SpecialService and remove Machinable in order to get the CommitmentDate returned.

Convert a spool into text format

I want to send the spool generated by a Smart Form, by email as attachment in TXT format.
The issue is to get the spool in a TXT format, without technical stuff, just the characters in the form.
I have used the function module RSPO_RETURN_SPOOLJOB for getting it, but it returns a technical format like this:
//XHPLJIIID 0700 00000+00000+
IN01ES_CA930_DEMO_3 FIRST
OPINCH12 P 144 240 1728020160000010000100001
IN02MAIN
MT0100808400
CP11000000E
FCCOURIER 120 00144 SF001SF001110000144E
UL +0000000000000
ST0201614Dear Customer,
MT0214209000
ST0864060We would like to take this opportunity to confirm the flight
MT0100809360
ST0763253reservations listed below. Thank you for your custom.
...
I want something as follows, without the technical stuff:
Dear Customer,
We would like to take this opportunity to confirm the flight
reservations listed below. Thank you for your custom.
...
This is the code I have used :
PARAMETERS spoolnum type TSP01-RQIDENT.
DATA spool_contents type soli_tab.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = spoolnum
tables
buffer = spool_contents
exceptions
others = 1.
If the parameter DESIRED_TYPE is not passed or has the value 'OTF', and the spool is of type SAPscript/Smart Form, the function module returns the technical format you have experienced.
Instead, you should use the parameter DESIRED_TYPE = 'RAW' so that all the technical stuff is interpreted and the form is returned as text, the way you request, as follows :
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = spoolnum
desired_type = 'RAW'
tables
buffer = spool_contents
exceptions
others = 1.

Using Excel's Bloomberg API to find a stock's IPO date?

I am wondering if there is a function in Excel's Bloomberg API to find a stock's IPO date.
For example, given 'YELP US Equity', it should return 03/01/2012.
Given '700 HK Equity', it should return 06/16/2004.
Is there a way?
Thank you
You can use the field EQY_INIT_PO_DT
=BDP("YELP US Equity", "EQY_INIT_PO_DT")
and more in general, you can use the FLDS command over a security to search for all available data.