Individual Assets
FinQuant provides classes for individual assets, such as stocks or funds. These are explained below.
Asset
This module provides a public class Asset
that represents a generic financial asset.
It serves as the parent class for specialized asset classes like Stock
and Market
in the finquant library.
An asset is characterized by its historical price data, from which various quantities
such as expected return, volatility, skewness, and kurtosis can be computed. The Asset
class provides common functionality and attributes that are shared among different types
of assets.
The specialized asset classes, Stock
and Market
, inherit from the Asset
class
and add specific functionality tailored to their respective types.
- class finquant.asset.Asset(data, name, asset_type='Market index')
Parent class representing a generic financial asset.
- Parameters:
data (
Series
) – Historical price data of the asset.name (
str
) – Name of the asset.asset_type (
str
) – Type of the asset (e.g., “Stock” or “Market index”).
The
Asset
class provides common functionality and attributes for financial assets. It represents a generic asset and serves as the parent class for specialized asset classes.- Attributes:
data
(pandas.Series
): Historical price data of the asset.name
(str
): Name of the asset.asset_type
(str
): Type of the asset (e.g., “Stock” or “Market”).expected_return
(float
): Expected return of the asset.volatility
(float
): Volatility of the asset.skew
(float
): Skewness of the asset.kurtosis
(float
): Kurtosis of the asset.
The
Asset
class provides methods to compute various quantities such as expected return, volatility, skewness, and kurtosis based on the historical price data of the asset.- __init__(data, name, asset_type='Market index')
- Parameters:
data (
Series
) – Historical price data of the asset.name (
str
) – Name of the assetasset_type (
str
) – Type of the asset (e.g., “Stock” or “Market index”), default: “Market index”
- comp_daily_returns()
Computes the daily returns (percentage change) of the asset. See
finquant.returns.daily_returns
.- Return type:
Series
- comp_expected_return(freq=252)
Computes the Expected Return of the asset. See
finquant.returns.historical_mean_return
.- Parameters:
freq (
INT
) – Number of trading days in a year, default: 252- Return type:
Series
- comp_volatility(freq=252)
Computes the Volatility of the asset.
- properties()
Nicely prints out the properties of the asset, with customized messages based on the asset type.
- Return type:
None
Stock
Inherits from Asset
.
This module provides a public class Stock
that represents a single stock or fund.
Instances of this class are used within the Portfolio
class (provided in finquant.portfolio
).
The Stock
class is designed to hold and calculate quantities related to a single stock or fund.
To initialize an instance of Stock
, it requires the following information:
investmentinfo
: Information about the stock or fund provided as apandas.DataFrame
.The required column labels are
Name
andAllocation
for the stock/fund name and allocation, respectively. However, the DataFrame can contain more information beyond these columns, such as year, strategy, currency (CCY), etc.
data
: Historical price data for the stock or fund provided as apandas.Series
.The data must contain
<stock_name> - Adj. Close
, which represents the closing price used to compute the return on investment.
The Stock
class computes various quantities related to the stock or fund, such as expected return,
volatility, skewness, and kurtosis. It also provides functionality to calculate the beta parameter
using the CAPM (Capital Asset Pricing Model) and the R squared value of the stock .
The Stock
class inherits from the Asset
class in finquant.asset
, which provides common
functionality and attributes for financial assets.
- class finquant.stock.Stock(investmentinfo, data)
Class that contains information about a stock/fund.
- Parameters:
investmentinfo (
DataFrame
) – Investment information of a stock.data (
Series
) – Historical price data of a stock.
The
Stock
class extends theAsset
class and represents a specific type of asset, namely a stock within a portfolio. It requires investment information and historical price data for the stock to initialize an instance.In addition to the attributes inherited from the
Asset
class, theStock
class provides a method to compute the beta parameter and one to compute the R squared coefficient specific to stocks in a portfolio when compared to the market index.- __init__(investmentinfo, data)
- Parameters:
investmentinfo (
DataFrame
) – Investment information of a stock.data (
Series
) – Historical price data of a stock.
- comp_beta(market_daily_returns)
Computes and returns the Beta parameter of the stock.
- Parameters:
market_daily_returns (
Series
) – Daily returns of the market index.- Return type:
- Returns:
Beta parameter of the stock
- comp_rsquared(market_daily_returns)
Computes and returns the R squared coefficient of the stock.
- Parameters:
market_daily_returns (
Series
) – Daily returns of the market index.- Return type:
- Returns:
R squared coefficient of the stock
- properties()
Nicely prints out the properties of the stock: Expected Return, Volatility, Beta (optional), R squared (optional), Skewness, Kurtosis as well as the
Allocation
(and other information provided in investmentinfo.)- Return type:
None
Market
Inherits from Asset
.
This module provides a public class Market
that represents a market index.
It serves as a specialized asset class within the finquant library.
A market index represents the performance of a specific market or a segment of the market,
such as the S&P 500 or NASDAQ. The Market
class is designed to hold and calculate quantities
related to a market index, such as expected return, volatility, skewness, and kurtosis.
The Market
class extends the Asset
class from finquant.asset
and inherits its
common functionality and attributes for financial assets. It provides additional methods
and attributes specific to market indices.
- class finquant.market.Market(data)
Class representing a market index.
- Parameters:
data (
Series
) – Historical price data of the market index.
The
Market
class extends theAsset
class and represents a specific type of asset, specifically a market index. It requires historical price data for the market index to initialize an instance.- __init__(data)
- Parameters:
data (
Series
) – Historical price data of the market index.
- comp_daily_returns()
Computes the daily returns (percentage change) of the market index. See
finquant.returns.daily_returns
.- Return type:
Series