Bloomberg Query Language (BQL) is used to query financial data from Bloomberg's data services. To calculate the total return of an equity over the last 3 weeks, you would typically need to consider both the price return and the dividend return. The total return is the sum of the capital gains (or losses) and the dividends received.
Here is a general approach to constructing a BQL formula for the total return of an equity over the last 3 weeks:
Price Return: Calculate the percentage change in the price of the equity over the last 3 weeks.
Dividend Return: Sum the dividends received over the last 3 weeks.
Total Return: Add the price return and the dividend return.
Assuming you have the necessary data fields available in Bloomberg, the BQL formula might look something like this:
bql
// Define the equity ticker
equity_ticker = "AAPL US Equity";
// Get the price data for the last 3 weeks
price_data = GET(PX_LAST, equity_ticker, START_DATE=DATETIME_NOW()-21, END_DATE=DATETIME_NOW());
// Calculate the price return
price_return = (LAST(price_data) - FIRST(price_data)) / FIRST(price_data);
// Get the dividend data for the last 3 weeks
dividend_data = GET(DIVIDENDS, equity_ticker, START_DATE=DATETIME_NOW()-21, END_DATE=DATETIME_NOW());
// Sum the dividends received over the last 3 weeks
dividend_return = SUM(dividend_data);
// Calculate the total return
total_return = price_return + dividend_return;
Explanation:
GET(PX_LAST, equity_ticker, START_DATE=DATETIME_NOW()-21, END_DATE=DATETIME_NOW()): Fetches the last price of the equity over the last 3 weeks.
LAST(price_data) - FIRST(price_data)) / FIRST(price_data): Calculates the price return.
GET(DIVIDENDS, equity_ticker, START_DATE=DATETIME_NOW()-21, END_DATE=DATETIME_NOW()): Fetches the dividends paid over the last 3 weeks.
SUM(dividend_data): Sums the dividends received over the last 3 weeks.
price_return + dividend_return: Calculates the total return.
Notes:
Ensure that the data fields PX_LAST and DIVIDENDS are available and correctly named in your Bloomberg setup.
The DATETIME_NOW() function is used to get the current date and time.
The START_DATE and END_DATE parameters are used to specify the date range for the data retrieval.
This is a conceptual example and might need adjustments based on the actual data fields and functions available in your Bloomberg setup. Always refer to the Bloomberg documentation for the most accurate and up-to-date information.
User
isnt there an actual total return formula? instead of needing to construct this ourselves
Assistant
Yes, Bloomberg provides a built-in function to calculate the total return of an equity, which simplifies the process significantly. The total return index (TRI) is a common measure that includes both capital gains and dividends.
In Bloomberg, you can use the TR function to get the total return index for an equity. Here’s how you can construct a BQL formula to get the total return for the last 3 weeks:
bql
// Define the equity ticker
equity_ticker = "AAPL US Equity";
// Get the total return index (TRI) for the last 3 weeks
total_return_index = GET(TR, equity_ticker, START_DATE=DATETIME_NOW()-21, END_DATE=DATETIME_NOW());
// Calculate the total return percentage change
total_return = (LAST(total_return_index) - FIRST(total_return_index)) / FIRST(total_return_index);
Explanation:
GET(TR, equity_ticker, START_DATE=DATETIME_NOW()-21, END_DATE=DATETIME_NOW()): Fetches the total return index (TRI) for the equity over the last 3 weeks.
(LAST(total_return_index) - FIRST(total_return_index)) / FIRST(total_return_index): Calculates the percentage change in the total return index over the specified period.
Notes:
The TR function in Bloomberg provides the total return index, which includes both capital gains and dividends.
The DATETIME_NOW() function is used to get the current date and time.
The START_DATE and END_DATE parameters are used to specify the date range for the data retrieval.
This approach leverages Bloomberg's built-in functionality to simplify the calculation of the total return, making it more straightforward and less prone to errors compared to manually constructing the formula.
User
isnt there one with custom_trr
Assistant
Yes, Bloomberg provides a more specific function called CUSTOM_TRR (Custom Total Return) which allows you to calculate the total return for a specific period, including both capital gains and dividends. This function is particularly useful for custom date ranges and specific calculations.
Here is how you can use CUSTOM_TRR to calculate the total return for an equity over the last 3 weeks:
bql
// Define the equity ticker
equity_ticker = "AAPL US Equity";
// Define the start and end dates for the last 3 weeks
start_date = DATETIME_NOW() - 21;
end_date = DATETIME_NOW();
// Calculate the custom total return
total_return = CUSTOM_TRR(equity_ticker, start_date, end_date);
Explanation:
equity_ticker: The ticker symbol of the equity you are interested in.
start_date: The start date for the period, which is 21 days ago from the current date.
end_date: The end date for the period, which is the current date.
CUSTOM_TRR(equity_ticker, start_date, end_date): This function calculates the custom total return for the specified equity over the given date range.
Notes:
The DATETIME_NOW() function is used to get the current date and time.
The CUSTOM_TRR function automatically includes both capital gains and dividends in its calculation.
This approach uses Bloomberg's built-in CUSTOM_TRR function to directly calculate the total return for a custom date range, making it efficient and accurate.