Calculating Rates of Return of Single Financial Securities with Python
Now that you have a fair idea of the Python programming language syntax and number crunching libraries, we shall take a look at one of the core concepts in the world of investment (and Finance in general). Investopedia defines returns of a financial security or instrument as:
“A return is the gain or loss of a security in a particular period. The return consists of the income and the capital gains relative on an investment, and it is usually quoted as a percentage.”
The rate of returns gives an investor an idea of how much he/she gained or lost within a specified timeframe. Let’s say an investor buys some shares of a single company (or a portfolio of different companies) for XYZ and holds onto this asset (or portfolio) for a year. During this year, the prices of the assets fluctuate daily so how does this investor assess the performance of this asset (or portfolio)? The rate of return simply gives an investor a percentage returns for holding this asset (or portfolio) within a timeframe.
The two types of returns we shall look into in this post are simple (discrete) returns and log returns. Practitioners tend to use simple returns when dealing with multiple assets and log returns when looking at returns on a single asset.
Unless there are dividends paid during the holding period, Simple returns is calculated as:
Simple Returns = (Ending Price - Beginning Price) / (Beginning Price)ORSimple Returns (including Dividends) = (Ending Price - Begining Price + Dividend Received) / (Beginning Price)Log Returns = Log(Ending Price - Begining Price)
Let’s look at how to make these calculations using real world data from Yahoo finance:
This blog post covered how the rates of returns of single securities are calculated in Python. What about a portfolio made up of various securities? We shall cover how the calculation of expected returns of portfolios in the next blog post. See you there!