 #%% md

# REIT STOCK ANALYSIS

#%% md

In this project, you will analyze Real Estate Investment Trusts, commonly known as REITs. REITs are companies that own or operate real estate that produces income. REITs, like the stocks of regular public companies, are traded on different stock exchanges. Investing in a REIT allows you to invest in portfolios of real estate assets the same way you can invest in a company by buying its stock.

Using financial statistics and NumPy you will analyze two REITs: Sabra Health Care REIT Inc. (NASDAQ: SBRA), which invests in health care real estate, and Equity Residential (NASDAQ:EQR), which invests in rental apartment properties.

#%% md

The time period for analysis we will be using is `Jan 1 2018` to `Dec 31 2018`. The REIT data for SBRA (`SBRA.csv`) and EQR (`EQR.csv`) can be found in the same folder as this file.

#%% md

1. Import the numpy module as np

#%%

import numpy as np

#%% md

#%%

import pandas as pd

#%% md

#%%

#%% md

## Simple Rate of Return Function

#%% md

1. To calculate the daily rate of return for the SBRA stock, we need the daily adjusted closing price. The formula we are using for the daily rate of return is out[n] = a[n+1] - a[n]

#%% md

1. Create a function that returns the daily rate of return

step 1. define a function named `rate_of_return`

step 2. create parameter for `adj_closings`

step 3. Within the function use np.diff() and set it to the variable `daily_simple_ror`

step 4. return `daily_simple_ror`

#%%

return daily_simple_ror

#%% md

## Calculate Daily Rate of Return for SBRA

#%% md

1. Call the function `simple_rate_of_return` with the arguments `adj_closings_sbra`. Then print the results.

#%%

daily_simple_returns_sbra

#%% md

## Calculate Daily Rate of Return for EQR

#%% md

1. Call the function `simple_rate_of_return` with the arguments `adj_closings_eqr`. Then print the results.

#%%

daily_simple_returns_eqr

#%% md

## Calculate Average Daily Return for SBRA

#%% md

1. Use `np.mean()` with the argument `daily_simple_returns_sbra` to calculate the average daily return for SBRA. Then set it to the variable name `average_daily_simple_return_sbra`

#%%

average_daily_simple_return_sbra = np.mean(daily_simple_returns_sbra)

#%% md

## Calculate Average Daily Return for EQR

#%% md

1. Use `np.mean()` with the argument `daily_simple_returns_eqr` to calculate the average daily return for EQR. Then set it to the variable name `average_daily_simple_return_eqr`

#%%

average_daily_simple_return_eqr = np.mean(daily_simple_returns_eqr)

#%% md

## Compare the Average Daily Return between EQR and SBRA

#%% md

1. Based on the average daily simple returns of EQR and SBRA, which stock is more likely to be profitable in the future?

#%% md

The SBRA stock is more likely to be profitable in the future

#%% md

## Daily Log Returns Function

#%% md

1. Create a function that returns the daily rate of return

step 1. define a function named log_returns

step 2. create parameter for `adj_closings`

step 3. use np.log() to get the log of each adjusted closing price and set it to the variable `log_adj_closings`

step 4. use np.diff() to get the diff of each daily log adjusted closing price and set it to the variable `daily_log_returns`

step 5. return `daily_log_returns`

#%%

return daily_log_returns

#%% md

## Calculate Daily Log Returns for SBRA

#%% md

1. Call the function `log_returns` with the arguments `adj_closings_sbra`. Set it to the variable `daily_log_returns_sbra`. Then print the results.

#%%

daily_log_returns_sbra

#%% md

## Calculate Daily Log Returns for EQR

#%% md

1. Call the function `log_returns` with the arguments `adj_closings_eqr`. Set it to the variable `daily_log_returns_eqr`. Then print the results.

#%%

daily_log_returns_eqr

#%% md

## Annualize Daily Log Return Function

#%% md

1. Create a function that returns the daily rate of return

step 1. define a function named `annualize_log_return`

step 2. create parameter for `daily_log_returns`

step 3. use `np.mean()` with the argument `daily_log_returns` to calculate the average daily return. Then set it to the variable name `average_daily_log_returns`

step 4. then multiply `average_daily_log_returns` by 250 and set it to the variable `annualized_log_return`

step 5. return `annualized_log_return`

#%%

def annualize_log_return(daily_log_returns):
average_daily_log_returns = np.mean(daily_log_returns)
annualized_log_return = average_daily_log_returns*250
return annualized_log_return

#%% md

## Calculate Annualize Daily Log Return for SBRA

#%% md

1. Call the function `annualize_log_return` with the arguments `daily_log_returns_sbra`. Set it to the variable `annualized_log_return_sbra`. Then print the results.

#%%

annualized_log_returns_sbra = annualize_log_return(daily_log_returns_sbra)
annualized_log_returns_sbra

#%% md

## Calculate Annualize Daily Log Return for EQR

#%% md

1. Call the function `annualize_log_return` with the arguments `daily_log_returns_eqr`. Set it to the variable `annualized_log_return_eqr`. Then print the results.

#%%

annualized_log_returns_eqr = annualize_log_return(daily_log_returns_eqr)
annualized_log_returns_eqr

#%% md

## Compare the Annualize Daily Log Return between EQR and SBRA

#%% md

1. Based on the differences between the Annualize Daily Log Return for EQR and SBRA, Which could be more profitable in the future and why?

#%% md

The SBRA stock could me more profitable in the future because it has an annualized log return of 50%

#%% md

## Calculate Variance of Daily Log Return for SBRA

#%% md

1. Calculate the variance of the daily logarithmetic return for SBRA. Use the function `.var()` with the argument `log_daily_ror`. Set it to the variable `daily_varaince_sbra`. Then print the results.

#%%

daily_variance_sbra = daily_log_returns_sbra.var()
daily_variance_sbra

#%% md

## Calculate Variance of Daily Log Return for EQR

#%% md

1. Calculate the variance of the daily logarithmetic return for EQR. Use the function `.var()` with the argument `daily_log_returns_eqr`. Set it to the variable `daily_varaince_eqr`. Then print the results.

#%%

daily_variance_eqr = daily_log_returns_eqr.var()
daily_variance_eqr

#%% md

## Compare the Variance of Daily Log Return between EQR and SBRA

#%% md

1. Explain which investment is more riskier based on the Variance of daily log return between EQR and SBRA ?

#%% md

The SBRA stock investment is more riskier, the SBRA variance is bigger than the EQR variance

#%% md

## Calculate the Daily Standard Deviation for SBRA

#%% md

1. Calculate the Standard Deviation of the daily logarithmetic return for SBRA. Use the function `.std()` with the argument `daily_log_returns_sbra`. Set it to the variable `daily_sd_sbra`. Then print the results.

#%%

daily_sd_sbra = daily_log_returns_sbra.std()
daily_sd_sbra

#%% md

## Calculate the Daily Standard Deviation for EQR

#%% md

1. Calculate the Standard Deviation of the daily logarithmetic return for EQR. Use the function `.std()` with the argument `daily_log_returns_eqr`. Set it to the variable `daily_sd_eqr`. Then print the results.

#%%

daily_sd_eqr = daily_log_returns_eqr.std()
daily_sd_eqr

#%% md

## Compare the Daily Standard Deviation between EQR and SBRA

#%% md

1. Has your previous variance risk assessment changed based on the Daily Standard Deviation and why?

#%% md

No, the assessment keeps the same

#%% md

## Calculate the Correlation between SBRA and EQR

#%% md

1. Calculate the Correlation of the daily logarithmetic return between SBRA and ERQ assets. Use the function `.corrcoef()` with the arguments `daily_log_returns_sbra` and `daily_log_returns_eqr`. Set it to the variable `corr_sbra_eqr`. Then print the results.

#%%

corr_sbra_eqr = np.corrcoef(daily_log_returns_sbra, daily_log_returns_eqr)
corr_sbra_eqr

#%% md

## Interpret the Correlation between SBRA and EQR

#%% md

1. Interpret and explain the correlation between the stocks SBRA and EQR?

The stocks are positively correlated. The daily returns moves towards the same direction in general

#%% md

## Final Analysis

#%% md

1. Which stock would you invest in based on risk and profitability?

For a riskier investor it would be better the SBRA stock.

2 Likes