tensorcircuit.applications.finance.portfolio#

Supplementary functions for portfolio optimization

tensorcircuit.applications.finance.portfolio.QUBO_from_portfolio(cov: Any, mean: Any, q: float, B: int, t: float) Any[源代码]#

convert portfolio parameters to a Q matrix :param cov: n-by-n covariance numpy array :param mean: numpy array of means :param q: the risk preference of investor :param B: budget :param t: penalty factor :return Q: n-by-n symmetric Q matrix

class tensorcircuit.applications.finance.portfolio.StockData(data: Any)[源代码]#

基类:object

A class for converting real-world stock data to an annualized covariance matrix and annualized return.

Attributes: - data: A list of continuous stock data in the same time span. - n_stocks: The number of stocks in the data. - n_days: The number of trading days in the data.

Methods: - __init__(self, data): Initializes the StockData object. - get_return(self, decimals=5): Calculates the annualized return. - get_covariance(self, decimals=5): Calculates the annualized covariance matrix.

__init__(data: Any)[源代码]#

Initializes the StockData object.

参数

data -- A list of continuous stock data in the same time span.

get_covariance(decimals: int = 5) Any[源代码]#

Calculates the annualized covariance matrix (sigma).

参数

decimals -- Number of decimal places to round the result to (default: 5).

返回

The annualized covariance matrix rounded to the specified number of decimals.

get_return(decimals: int = 5) Any[源代码]#

Calculates the annualized return (mu).

参数

decimals -- Number of decimal places to round the result to (default: 5).

返回

The annualized return as an array rounded to the specified number of decimals.