Finalizing the Report
Finalizing the Report¶
To finalize the report we start adding in the writing of different sheets. First, the treasury sheet.
In [10]:
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 workbook
wb = openpyxl.Workbook()
# Grab the active sheet and write the treasury sheet
ws = wb.active
write_treasury_sheet(ws, yield_table)
# Save workbook
wb.save("Workbooks/Economic Report.xlsx")
create_report(2019, 1)
We add in a few other things, renaming the title of the worksheet to "Yield Curve", creating a new sheet called "Real Estate", then writing the actual real estate report.
In [11]:
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 workbook
wb = openpyxl.Workbook()
# Grab the active sheet and write the treasury sheet
ws = wb.active
write_treasury_sheet(ws, yield_table)
# Change title
ws.title = "Yield Curve"
# Add worksheet and write real estate
ws = wb.create_sheet("Real Estate")
create_real_estate_report(ws, quarterly_returns_RE, "Images/Real Estate vs. Inflation.png")
# Save workbook
wb.save("Workbooks/Economic Report.xlsx")
create_report(2019, 1)
We are going to actually take that real estate sheet and replicate it so that we can have on sheet which is our nominal real estate returns, and the other is inflation adjusted!
In [12]:
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 workbook
wb = openpyxl.Workbook()
# Grab the active sheet and write the treasury sheet
ws = wb.active
write_treasury_sheet(ws, yield_table)
# Change title
ws.title = "Yield Curve"
# Add worksheet and write nominal real estate
ws = wb.create_sheet("Real Estate Nominal")
create_real_estate_report(ws, quarterly_returns_RE, "Images/Real Estate vs. Inflation.png")
# Add worksheet to write inflation adjusted real estate
ws = wb.create_sheet("Real Estate Adjusted")
create_real_estate_report(ws, quarterly_returns_adj_RE, "Images/Real Estate Inflation Adjusted.png")
# Save workbook
wb.save("Workbooks/Economic Report.xlsx")
create_report(2019, 1)
One final change, we can actually change the saving to have it name the report with the quarter and year.
In [13]:
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 workbook
wb = openpyxl.Workbook()
# Grab the active sheet and write the treasury sheet
ws = wb.active
write_treasury_sheet(ws, yield_table)
# Change title
ws.title = "Yield Curve"
# Add worksheet and write nominal real estate
ws = wb.create_sheet("Real Estate Nominal")
create_real_estate_report(ws, quarterly_returns_RE, "Images/Real Estate vs. Inflation.png")
# Add worksheet to write inflation adjusted real estate
ws = wb.create_sheet("Real Estate Adjusted")
create_real_estate_report(ws, quarterly_returns_adj_RE, "Images/Real Estate Inflation Adjusted.png")
# Save workbook
wb.save("Workbooks/Economic Report {}Q{}.xlsx".format(year, quarter))
create_report(2019, 1)
We are finished! You can run this with different year/quarter combinations and have the final report spit out!
In [14]:
#Now run a few times and see how it automatically creates them!
create_report(2019, 4)
create_report(2018, 2)
create_report(2017, 4)