Adds a cash like security to an existing MkT data object.

azapy.Util.add_cash_security.add_cash_security(data, name='_CASH_', value=1)

Add cash like security to an existent market data.

datapandas.DataFrame or dict

Initial market data to which a cash like security will be added.

namestr, optional

The symbol of the cash like security. Must be different than any symbol in data. Note that CASH is a valid stock symbol. The default is ‘_CASH_’.

valuefloat, optional

Nominal value of the cash like security. It is constant overtime (no dividends and no splits). The default is 1.

`pandas.DataFrame` or `dict`The new MkT data updated with the cash like security,in the same format of data input format, i.e., pandas.DataFrame or ‘dict’.


Example add_cash_security

import azapy as az

mktdir = "../../MkTdata"
sdate = "2012-01-01"
edate = "2021-07-27"
symb = ['GLD', 'TLT', 'XLV', 'IHI', 'VGT']

# mkt data as a DataFrame
mktdata = az.readMkT(symb, sdate=sdate, edate=edate, file_dir=mktdir)
print(f"mktdata   symbols: {mktdata.symbol.unique()}")

# new MkT DataFrame with a cash like security
mktdata_c = az.add_cash_security(mktdata)
print(f"mktdata_c symbols: {mktdata_c.symbol.unique()}")

# mkt data as a dict
mktdata_d = az.readMkT(symb, sdate=sdate, edate=edate, file_dir=mktdir, 
print(f"mktdata_d   symbols: {mktdata_d.keys()}")

# append a cash like security to mktdata_d dict
mktdata_d_c = az.add_cash_security(mktdata_d)
print(f"mktdata_d_c symbols: {mktdata_d_c.keys()}")
# for dict it is an append
print(f"mktdata_d   symbols: {mktdata_d.keys()}")