Qiskit Finance: A library of quantum computing finance experiments
Archived. The repository is read-only: no more fixes or releases will come.
pip install qiskit-financeREADME as published on PyPI with version 0.4.1.
Qiskit Finance
Qiskit Finance is an open-source framework that contains uncertainty components for stock/securities problems, applications, such as portfolio optimization, and data providers to source real or random data to finance experiments.
Installation
We encourage installing Qiskit Finance via the pip tool (a python package manager).
pip install qiskit-finance
pip will handle all dependencies automatically and you will always install the latest (and well-tested) version.
If you want to work on the very latest work-in-progress versions, either to try features ahead of their official release or if you want to contribute to Finance, then you can install from source. To do this follow the instructions in the documentation.
Creating Your First Finance Programming Experiment in Qiskit
Now that Qiskit Finance is installed, it's time to begin working with the finance module. Let's try an experiment using Amplitude Estimation algorithm to evaluate a fixed income asset with uncertain interest rates.
import numpy as np
from qiskit.primitives import Sampler
from qiskit_algorithms import AmplitudeEstimation
from qiskit_finance.circuit.library import NormalDistribution
from qiskit_finance.applications import FixedIncomePricing
# Create a suitable multivariate distribution
num_qubits = [2, 2]
bounds = [(0, 0.12), (0, 0.24)]
mvnd = NormalDistribution(
num_qubits, mu=[0.12, 0.24], sigma=0.01 * np.eye(2), bounds=bounds
)
# Create fixed income component
fixed_income = FixedIncomePricing(
num_qubits,
np.eye(2),
np.zeros(2),
cash_flow=[1.0, 2.0],
rescaling_factor=0.125,
bounds=bounds,
uncertainty_model=mvnd,
)
# the FixedIncomeExpectedValue provides us with the necessary rescalings
# create the A operator for amplitude estimation
problem = fixed_income.to_estimation_problem()
# Set number of evaluation qubits (samples)
num_eval_qubits = 5
# Construct and run amplitude estimation
sampler = Sampler()
algo = AmplitudeEstimation(num_eval_qubits=num_eval_qubits, sampler=sampler)
result = algo.estimate(problem)
print(f"Estimated value:\t{fixed_income.interpret(result):.4f}")
print(f"Probability: \t{result.max_probability:.4f}")