Hi all,
I am trying to create a relative price ratio between two assets (e.g. between TLT and SPY) but kept getting an error. Wondering if anybody can give any suggestion on how to resolve this?
Hi all,
I am trying to create a relative price ratio between two assets (e.g. between TLT and SPY) but kept getting an error. Wondering if anybody can give any suggestion on how to resolve this?
Use either method 1 or method 2.
In method 1, you have created two Series that can be divided directly.
In method 2 you have created two DataFrames with equity object column labels e.g. Equity(8554 [SPY])
To divide these two DataFrames you have to reference the column labels for each.
The symbols() function converts the symbol strings to equity objects.
import numpy as np
startDate = '2019-10-4'
endDate = '2019-12-31'
# Method 1
pxTLT = np.log(get_pricing('TLT', start_date= startDate, end_date= endDate, fields= 'price', frequency='daily'))
pxSPY = np.log(get_pricing('SPY', start_date= startDate, end_date= endDate, fields= 'price', frequency='daily'))
px = pxTLT / pxSPY
print(px.tail())
# Method 2
pxTLT = np.log(get_pricing(['TLT'], start_date= startDate, end_date= endDate, fields= 'price', frequency='daily'))
pxSPY = np.log(get_pricing(['SPY'], start_date= startDate, end_date= endDate, fields= 'price', frequency='daily'))
px = pxTLT[symbols('TLT')] / pxSPY[symbols('SPY')]
print(px.tail())