-
Yield Curve Data 4
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
-
Treasury Curve Report 4
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
-
Real Estate Data 4
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
-
Real Estate Report 2
-
Lecture4.1
-
Lecture4.2
-
-
Final Report 5
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
Generating the Report & Images
Generating the Report & Images¶
We take a step back and begin creation of the report function. Firstly we bring in all data functionality.
In [7]:
def create_report(year: int, quarter: int):
"""
Function to create the excel economic report
Parameters
----------
year : int
The year to use for the last quarter
quarter : int
The last quarter to use
"""
# Work through data
yield_curve = prepare_data_yield_curve()
real_estate_data = prepare_data_real_estate()
yield_table = process_data_yield_curve(yield_curve, year, quarter)
returns_RE, quarterly_returns_RE, quarterly_returns_adj_RE = process_data_real_estate(real_estate_data, year, quarter)
create_report(2019, 1)
And now to build a function which creates all the different images.
In [8]:
def create_images(yield_table: DataFrame, returns_RE: DataFrame):
"""
Function to create all the images for use in the report
Parameters
----------
yield_table : DataFrame
The yield table
returns_RE : DataFrame
The returns data
"""
# Create Treasury Yield Curves image
graph_data = yield_table[['Current', '1 Year Ago Curve', '5 Years Ago Curve']].copy()
ax = graph_data.plot(kind="line")
current_lim = plt.ylim()
new_lim = [min(current_lim[0],0),current_lim[1]]
plt.ylim(new_lim)
plt.xlabel("Maturity")
plt.ylabel("Yield")
plt.title("Yield Curves")
ax.yaxis.set_major_formatter(PercentFormatter())
plt.savefig("Images/Treasury Yield Curves.png")
plt.close()
# Create Real Estate vs. Inflation image
ax = returns_RE[['Real Estate', 'CPI']].plot(kind='line')
quarter_index = returns_RE.index.map(lambda x: str(x[0]) +"Q"+str(x[1]))
index_positions = list(range(len(quarter_index)))
ax.xaxis.set_ticks(index_positions[::4])
ax.xaxis.set_ticklabels(quarter_index[::4])
plt.xticks(rotation=70)
plt.ylabel("Normalized Index Value")
plt.xlabel("Date")
plt.title("Normalized Indices")
plt.savefig("Images/Real Estate vs. Inflation.png", bbox_inches="tight")
plt.close()
# Create Real Estate Inflation Adjusted image
ax = returns_RE[["Real Estate", "Real Estate Inflation Adjusted"]].plot(kind='line')
ax.xaxis.set_ticks(index_positions[::4])
ax.xaxis.set_ticklabels(quarter_index[::4])
plt.xticks(rotation=70)
plt.xlabel("Quarter")
plt.ylabel("Index Level")
plt.title("Real Estate Nominal vs. Inflation Adjusted")
plt.savefig("Images/Real Estate Inflation Adjusted.png", bbox_inches="tight")
plt.close()
create_images(yield_table, returns_RE)
Then update the create_report function to build the images.
In [9]:
def create_report(year: int, quarter: int):
"""
Function to create the excel economic report
Parameters
----------
year : int
The year to use for the last quarter
quarter : int
The last quarter to use
"""
# Work through data
yield_curve = prepare_data_yield_curve()
real_estate_data = prepare_data_real_estate()
yield_table = process_data_yield_curve(yield_curve, year, quarter)
returns_RE, quarterly_returns_RE, quarterly_returns_adj_RE = process_data_real_estate(real_estate_data, year, quarter)
# Create images
create_images(yield_table, returns_RE)
create_report(2019, 1)
Prev
Data Processing