Skip to content

Instructions how to create Portfolio DataFrame

Vladislav Pyatnitskiy edited this page Feb 5, 2024 · 4 revisions

The most crucial part of working with Portfolio Information is DataFrame. This page is aimed to explain how to create specific type of DataFrame to work with all other script in this repository.

Creating Nested List with Securities' information

Before building Portfolio DataFrame, it is necessary to type info about current securities. Information should include ticker (name of the company on stock market), start date (buy date), end date (sell date) and number of securities. To do the following you need to create nested list with information.

The example of nested list can be checked here:

https://github.com/vladislavpyatnitskiy/Portfolio_Analysis/blob/main/Scripts/Securities%20info%20entry.R

Portfolio DataFrame

Having created Nested list with portfolio information, you will be finally able to create time series data of portfolio. Everything you need is to put nested list into this script:

https://github.com/vladislavpyatnitskiy/Portfolio_Analysis/blob/main/Scripts/Portfolio%20DataFrame%20Builder.R

Now you have right DataFrame Format which will allow to get all functionality of the repository.

DataFrame of returns

Portfolio DataFrame contains values of securities prices, number and total values but not appropriate to calculate returns. However, the number of securities is always changing and it would be incorrect to use total amount of investments as material for returns calculations. My method is calculating returns by dividing sum of assets that have been in the portfolio for 2 time period (e.g. if security was bought today, it will affect returns; only securities that have been for 2 day period are counted). Therefore, I have written script that calculates Portfolio Return:

https://github.com/vladislavpyatnitskiy/Portfolio_Analysis/blob/main/Scripts/Portfolio%20Returns%20Calculation.R