Classiq / classiq-library

The Classiq Library is the largest collection of quantum algorithms, applications. It is the best way to explore quantum computing software. We welcome community contributions to our Library 🙌
https://platform.classiq.io
MIT License
284 stars 101 forks source link

Refactor the Option Pricing notebook to use classiq constructs #37

Open orsa-classiq opened 2 months ago

orsa-classiq commented 2 months ago

Using quantum computers for pricing financial derivatives has the promise for quadratic speedup.

In this issue we will improve the current option-pricing notebook, implementing algorithm for european call options, based on the paper Option Pricing using Quantum Computers. The goal is to use native language constructs instead of the current construct_finance_model black box function in the existing implementation.

to complete this issue, follow the following steps:

  1. Open the option pricing notebook and go over the code and explanations.
  2. Remove the usage of the construct_finance_model, function_input in the model creation. You will later on use native language functions Instead.
  3. We use a log-normal distribution for the asset. You can use the current parameters, such as num_qubits, mu, sigma, threshold. A bonus is to derive them from financial parameters. Use the prepare_state function on calculated lognormal distribution with the parameters, and some truncation value (5 sigma). This can be computed classically and passed to the prepare_state as an array of probabilities.
  4. For the payoff, use the *= syntax, see amplitude loading example. Pay attention for needed remapping of the variables and normalization, as done in the paper. Here, in difference from the article, the implementation is exact and not approximated.
  5. For the amplitude estimation, you can use the iqae execution scheme, that uses the iterative amplitude estimation, and the built-in grover_operator. See quantum_counting for example.
  6. Verify the execution results of the algorithm with a classical computation. Add assert validation to the code.
  7. Wherever needed, add Markdown cells with explanations and mathematical formulations.
  8. After finishing with the notebook, make sure you keep the write_qmod(qmod, "option_pricing.qmod") line. Run the notebook, and you will automatically update the .qmod file for this example.
  9. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  10. Follow the contribution guidelines to open a pull request.

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Qubit1718 commented 1 month ago

Hi @orsa-classiq & @amir-naveh,

I would like to work on this issue. May I please know what exactly do you mean by "native language constructs"? I am assuming that the functions needs to be changed to classiq 0.42.0 version. Please correct me if I am wrong. I look forward to hearing from you soon :)

orsa-classiq commented 1 month ago

Hi @Qubit1718, we will be really glad if you take it :)

By 'native language constructs' we mean using a main function, as you did in the hw_aware_sytnthesis notebook You can see that currently the notebook contains a construct_finance_model that directly returns pre-built qmod, and we want it to be transparent.

Qubit1718 commented 1 month ago

You mean the construct_finance_model and function_input need to be rewritten as main functions? Could you please also let me know what would be a better starting point to understand the working of construct_finance_model and function_input :))

orsa-classiq commented 1 month ago

You can just ignore this function, and re-write the notebook from scratch. I refer you to the mentioned paper for understanding of the algorithm. You need to create a single model (i.e single main function), within you use the amplitude-estimation algorithm, for the European Call options.

Qubit1718 commented 1 month ago

Got it, @orsa-classiq. I'll start reading the paper and post it to you if I have any further questions. Thanks!

orsa-classiq commented 1 week ago

@Qubit1718 are you still working on this?