paddle_quantum.finance.finance
Functions and data simulator class of quantum finance.
- class paddle_quantum.finance.finance.DataSimulator(stocks, start=None, end=None)
- Bases: - object- Used to generate data and calculate relevant parameters for portfolio optimization and portfolio diversification problems. - Parameters:
- stocks (list) – A list of names of investable stocks 
- start (datetime | None) – The start date of the trading day when the stock data is randomly generated. Defaults to - None.
- end (datetime | None) – The end date of the trading day when the stock data is randomly generated. Defaults to - None.
 
 - set_data(data)
- Decide which data source to use: randomly generated or locally entered. - Parameters:
- data (list) – Stock data entered by the user. 
 
 - randomly_generate()
- Randomly generate stock data for experiments based on start date and end date. - Note - To generate random stock data, you need to specify the start date and end date in the format of the - datetimepackage, e.g.- start = datetime.datetime(2016, 1, 1).
 - get_asset_return_mean_vector()
- Calculate expected return of each stock. - Returns:
- Expected return of all investable stocks. 
- Return type:
- list 
 
 - get_asset_return_covariance_matrix()
- Calculate the covariance matrix between the returns of each stock. - Returns:
- The covariance matrix between the returns of each stock. 
- Return type:
- list 
 
 - get_similarity_matrix()
- Calculate the similarity matrix among stocks. - The Dynamic Time Warping algorithm (DTW) is used to calculate the similarity between two stocks. - Returns:
- The similarity matrix among stocks. 
- Return type:
- list 
 
 
- paddle_quantum.finance.finance.portfolio_optimization_hamiltonian(penalty, mu, sigma, q, budget)
- Construct the hamiltonian of the portfolio optimization problem. - Parameters:
- penalty (int) – Penalty parameter. 
- mu (list) – Expected return of each stock. 
- sigma (list) – The covariance matrix between the returns of each stock. 
- q (float) – Risk appetite of the decision maker. 
- budget (int) – Budget, i.e. the number of stocks to be invested. 
 
 - Hint - Mapping Boolean variables - Returns:
- The hamiltonian of the portfolio optimization problem. 
- Return type:
 
- paddle_quantum.finance.finance.portfolio_diversification_hamiltonian(penalty, rho, q)
- Construct the hamiltonian of the portfolio diversification problem. - Parameters:
- penalty (int) – Penalty parameter. 
- rho (list) – The similarity matrix among stocks. 
- q (int) – Number of categories for stock clustering. 
 
 - Hint - Mapping Boolean variables - Returns:
- The hamiltonian of the portfolio diversification problem. 
- Return type:
 
- paddle_quantum.finance.finance.arbitrage_opportunities_hamiltonian(g, penalty, n, k)
- Construct the hamiltonian of the arbitrage opportunity optimization problem. - Parameters:
- g (DiGraph) – Graphical representation of conversions between different markets. 
- penalty (int) – Penalty parameter. 
- n (int) – Number of currency types, i.e. number of vertices in the graph g. 
- k (int) – Number of vertices contained in the arbitrage loop. 
 
 - Hint - Mapping Boolean variables - Returns:
- The hamiltonian of the arbitrage opportunity optimization problem. 
- Return type: