In [1]:
Copied!
from polars_bloomberg import BQuery
from polars_bloomberg import BQuery
S&P Annual Price Returns¶
In [2]:
Copied!
# get S&P annual price returns
bin_names: list = [
"< -50",
"-50 to -40",
"-40 to -30",
"-30 to -20",
"-20 to -10",
"-10 to 0",
"0 to 10",
"10 to 20",
"20 to 30",
"30 to 40",
"40 to 50",
"> 50",
]
bins = list(range(-50, 60, 10))
query = f"""
let(
#rets = dropna(pct_diff(px_last(dates=range(-100Y, 0Y), per=Y)));
#bins = bins(#rets, {bins}, bin_names={bin_names});
)
get(#rets, #bins)
for(['SPX Index'])
"""
with BQuery() as bq:
df = bq.bql(query).combine()
# get S&P annual price returns
bin_names: list = [
"< -50",
"-50 to -40",
"-40 to -30",
"-30 to -20",
"-20 to -10",
"-10 to 0",
"0 to 10",
"10 to 20",
"20 to 30",
"30 to 40",
"40 to 50",
"> 50",
]
bins = list(range(-50, 60, 10))
query = f"""
let(
#rets = dropna(pct_diff(px_last(dates=range(-100Y, 0Y), per=Y)));
#bins = bins(#rets, {bins}, bin_names={bin_names});
)
get(#rets, #bins)
for(['SPX Index'])
"""
with BQuery() as bq:
df = bq.bql(query).combine()
Out[3]: