Зміст курсу
Introduction to Portfolio Management with Python
Introduction to Portfolio Management with Python
Measuring Risk of Portfolio
What is Risk?
Let's discover the second key concept in portfolio analysis - risk.
First of all, let's define what risk is.
Practically, investing always involves risk because asset prices fluctuate frequently. They can fall just as easily as they can rise.
Common Measure of Risk
The question arises: how to measure risk?
Since investing is considered riskier when an asset's price fluctuates more significantly, a common measure of risk is the standard deviation of an asset's return.
This is common measure, also known as volatility.
Below is a code example of computing risks, using stock shares of Apple, Meta, and Amazon as assets:
# Importing pandas library import pandas as pd # Creating DataFrame `stocks` with values of stock prices of Apple, Meta and Amazon # for the period from `2024-09-06` to `2024-09-11` stocks = pd.DataFrame(index = ['2024-09-06', '2024-09-09', '2024-09-10', '2024-09-11'], columns = ['Apple', 'Meta', 'Amazon'], data = [[220.14, 499.60, 170.56], [220.88, 505.90, 176.25], [219.74, 504.56, 179.40], [222.14, 512.20, 184.05]]) print('Stock data:') print(stocks) print('Returns:') print(stocks.pct_change()) print('Risks:') print(stocks.pct_change().std())
Here, as well as in the previous chapter, we use the stocks.pct_change()
construction to compute the returns of each asset. Additionally, we apply the std()
method on the resulting DataFrame to compute the standard deviation of each asset's return.
Risk of Portfolio
After we have covered the key aspects of the risk associated with individual investments, it's time to turn our attention to the risk of an entire portfolio.
We will explore this topic in the following video:
Here is a corresponding Google Colab.
Additionally, there are several other measures of financial risk, some of which we will explore in later chapters of this course.
Дякуємо за ваш відгук!