Technical analysis of financial instruments
With technical analysis of assets, metrics (such as cumulative returns and volatility) are calculated to compare various assets to each other. As with the previous two sections in this chapter, we will be writing a module with classes to help us. We will need the StockAnalyzer
class for technical analysis of a single asset and the AssetGroupAnalyzer
class for technical analysis of a group of assets. These classes are in the stock_analysis/stock_analyzer.py
file.
As with the other modules, we will start with our docstring and imports:
"""Classes for technical analysis of assets.""" import math from .utils import validate_df
The StockAnalyzer class
For analyzing individual assets, we will build the StockAnalyzer
class, which calculates metrics for a given asset. The following UML diagram shows all the metrics that it provides: