Polars-Bloomberg
  • Home
  • Usage & Tutorials
    • BDP
    • BDH
    • BQL
  • Examples
    • Equity Examples
    • Credits
  • API Reference
  • Search
  • Previous
  • Next
  • Edit on GitHub
  • Equity Examples
    • S&P Annual Price Returns

Equity Examples¶

(c) Marek Ozana

Example usage of polars-bloomberg in Equity space

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]:

Documentation built with MkDocs.

Search

From here you can search these documents. Enter your search terms below.

Keyboard Shortcuts

Keys Action
? Open this help
n Next page
p Previous page
s Search