Building a Portfolio Workbook

Transcription

Building a Portfolio Workbook
July 2010
Building a Portfolio Workbook
Portfolio workbooks are used to manage a collection of trades. This article describes how to
construct a portfolio workbook from a paste example of a FINCAD function. Tips on workbook
building and automation with the use of Visual Basic for Applications (VBA) are introduced.
Portfolio workbooks for different asset classes have been added to FINCAD Analytics Suite for
Excel to address the need in different areas.
Let’s begin building a portfolio workbook. This example uses the function aaBSG.
1. Start a new spreadsheet and paste an example of aaBSG as a portfolio at cell A4.
a. Open Analytics Suite 2010 for Excel and click Analytics Finder.
b. Select the Search tab, type the string “aaBSG” in the text box and click Search.
c. Select the function aaBSG in the search result.
d. Open the Paste Example Options dialog box by clicking the triangle mark on
the Paste Example button and select Paste Example Options as shown in
Figure 1.
e. In the Paste Example Options dialog box, select As portfolio (when available)
and the All statistics (when available) checkbox as shown in Figure 2. Click
OK to confirm the settings.
Figure 1
Figure 2
f.
Select the function aaBSG again and click Paste Example.
g. The function example is pasted horizontally across the screen as shown in
Figure 3.
Figure 3
2. Remove all combo boxes in the pasted example as shown in Figure 4. Right-click each
combo box and select Cut.
Figure 4
Combo boxes are difficult to work with in a portfolio environment. Cell links of the
combo boxes are not updated automatically when making multiple copies. Therefore,
data validation is used in place of combo boxes. The use of data validation requires
two cells. The first cell enforces the data validation and lists out all available options
as shown in Figure 5. The second cell uses the Excel function MATCH to identify the
index of the selected item as shown in Figure 6. Named ranges are used to define
the switch values.
Figure 5
Figure 6
3. Change the statistics input of the function aaBSG to an absolute reference.
a. Select cell M7.
b. In the formula bar, highlight the statistics input M6:T6 as shown in Figure 7.
Figure 7
c. Press the F4 key once to change the cell reference from relative to absolute as
indicated by the $ sign.
d. Press Ctrl + Shift + Enter to recalculate the array.
4. Create a new position in the portfolio with the use of the Macro Recorder. The macro
recorder provides a good starting point for automation and the foundation for further
customization.
a. For Microsoft Excel 2003, open the Record Macro dialog box through the Excel
menu as shown in Figure 8. Go to Tools -> Macro -> Record New Macro.
Figure 8
For Microsoft Excel 2007, the Record Macro dialog box is located under the
Developer tab as shown in Figure 9. If the ribbon is not accessible, go to the
Office icon -> Excel Options -> Popular, select Show Developer Tab in the
Ribbon, and click OK.
Figure 9
b. In the Record Macro dialog box, specify the name, the shortcut and the
description of the new macro as shown in Figure 10.
Figure 10
Improve readability by giving a meaningful function name and providing a
description.
c. Copy the contents in row 7 as shown in Figure 11. Click the row number to
select the entire row 7, then right-click and select Copy.
Figure 11
d. Insert a new position at the top of the portfolio by inserting the copied contents
into the same row as shown in Figure 12. Immediately following the copy from
the previous step (notice the flashing border), right-click the row number again
and select Insert Copied Cells.
Figure 12
e. Press the Escape key once to remove the flashing border and select cell A4.
f.
Stop the recording as shown in Figure 13. Go to Tools -> Macro -> Stop
Recording.
Figure 13
For Microsoft Excel 2007, the Stop Recording button is located under the
Developer tab as shown in Figure 14.
Figure 14
The macro is recorded in a module residing in the current workbook object. It
can be accessed through the VB Editor.
5. Add a button and assign the recorded macro to this button.
a. For Microsoft Excel 2003, make the Form toolbar visible as shown in Figure 15.
Go to View -> Toolbars and ensure Forms has a check mark beside it.
For Microsoft Excel 2007, the Form toolbar can be found in the Control section
of the Developer tab.
Figure 15
b. For Microsoft Excel 2003, click the Button button in the Forms toolbar as shown
in Figure 16. The mouse cursor turns into a + mark, indicating Excel is ready to
draw a button.
Figure 16
For Microsoft Excel 2007, click Insert from the Form Controls section and click
the Button button. (This is usually the first button on the Form Controls menu.)
Figure 17
c. Click on where the button will be located (this is the top left corner of the button)
and drag to size the button. The Assign Macro dialog box pops up when the
mouse button is released.
d. Assign the recorded macro to the button as shown in Figure 18. Select
Add_Trade from the list of macros and click OK.
Figure 18
e. Double-click and highlight the Button Name. Rename the button to Add Trade.
6. Automation is added to this portfolio and we can rerun the add trade operation by
clicking this macro button.
7. Add a formula =SUM(OFFSET($M$6,1,0,COUNT($M$6:$M$8)-1,1)) in cell M3 and
press Enter to calculate the fair value of the portfolio as shown in Figure 19. Excel
functions SUM, OFFSET and COUNT are used. This formula sums a range of cells
specified by the OFFSET function. The OFFSET function specifies a range that starts
one cell below the statistic output value (cell M6). This range is one column wide. Its
length is dynamically adjusted since new trades are added in between the statistic
output value (cell M6) and the last row of the portfolio (cell M8). The minus one after the
COUNT function adjusts the counting of rows begins one row above the first trade.
Figure 19
Never delete the last trade (bottom row) in the portfolio because the COUNT function
has a cell reference associated with this cell in order to count the number of rows in
between.
8. The option portfolio is ready to use.
Automation Enhancement with Visual Basic for Application (VBA)
The recorded macro can be used as long as the portfolio does not move away from cell A4
because there is a direct cell reference in the code.
Let’s examine the recorded code in the VB Editor:
Sub Add_Trade()
'
' Add_Trade Macro
' This macro adds a new trade into the top of the portfolio by duplicating the top row.
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Rows("7:7").Select
Selection.Copy
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Range("A7").Select
End Sub
There are direct calls to row 7 and cell A7. The macro stops working correctly if the portfolio is
moved away from these pivotal cells. For example, if we insert a row at the top of the
worksheet, the portfolio now starts at row 8 instead.
We can improve the code in the following ways:
1. Use named ranges instead of cell references. For example, define the top left corner of
the portfolio as a named range. Let’s name cell A6 as anchor_table.
2. Since the top of the portfolio is always one cell below the named range anchor_table,
we can further generalize the subroutine by using the OFFSET function to refer to the
row. The top row of the portfolio can be referenced as
Range(“anchor_table”).Offset(1,0).
With the above changes, the resulting code becomes:
Sub Add_Trade()
'
' Add_Trade Macro
' This macro adds a new trade into the top of the portfolio by duplicating the top row.
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Range("anchor_table").Offset(1, 0).EntireRow.Select
Selection.Copy
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Range("anchor_table").Offset(1, 0).Select
End Sub
This is one example of how we can improve the portfolio with the use of VBA. Further
customization can be implemented accordingly.
Some Variations in Building Portfolio Workbooks
When building a portfolio using a function that has table inputs shared across all trades, such as
discount factor curves and holiday lists, the paste as portfolio option is not available for such
functions. The function has to be transposed manually. It is a good idea to start building the
portfolio with one of the FINCAD swap curve templates. The swap curve templates contain one
or more discount factor curves and holiday lists. They are located in the Curves (Interest Rate)
section of the workbook menu. Simply open a swap curve template of your choice, add a new
spreadsheet, and start your work. In a single swap curve template, the discount factor curve is
referred as df_curve and the holiday list is referred as holidays.
When building a portfolio using a function that has different table inputs in each trade, such as
amortizing schedules or reset tables, this brings additional challenges in designing and building
the workbook. How are these input tables stored and arranged? How are the data inputted and
fed into the function? All of these factors affect the design and ease of use of the workbook.
Very often, additional use of VBA is required. FINCAD has recently added new portfolio
workbook solutions into FINCAD Analytics Suite 2010 For Excel that involve different table
inputs. They are:



Overnight Index Swap Portfolio,
CD CDS (Single Asset) Portfolio – ISDA Model, and
Convertible Bond (Amortizing) Portfolio.
FINCAD Professional Services
FINCAD offers custom workbook solutions. We will work with you to custom-build one or more
FINCAD Analytics Suite workbooks to address your specific valuation needs.
Disclaimer
Your use of the information in this article is at your own risk. The information in this article is provided on an “as
is” basis and without any representation, obligation, or warranty from FINCAD of any kind, whether express or
implied. We hope that such information will assist you, but it should not be used or relied upon as a substitute
for your own independent research. This document is for informational purposes only. FinancialCAD
Corporation MAKES NO WARRANTIES, EXPRESSED OR IMPLIED, IN THIS SUMMARY.
Copyright
© 2010 FinancialCAD Corporation (“FINCAD”). All rights reserved. FinancialCAD® and FINCAD® are
registered trademarks of FinancialCAD Corporation. Other trademarks are the property of their respective
holders.