forked from Classiq/classiq-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration of reviewer modification
- Loading branch information
1 parent
f73e035
commit 5a44717
Showing
8 changed files
with
608 additions
and
122 deletions.
There are no files selected for viewing
253 changes: 198 additions & 55 deletions
253
...options/RainbowOptions-DirectMethod.ipynb → ...ethod/rainbow_options_direct_method.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
research/rainbow_options_direct_method/rainbow_options_direct_method.metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"friendly_name": "Rainbow Options Direct Method", | ||
"description": "Rainbow Options payoff using Direct Method in QAE", | ||
"problem_domain_tags": ["risk analysis"], | ||
"vertical_tags": ["finance"], | ||
"qmod_type": ["application"], | ||
"level": ["advanced"] | ||
} |
90 changes: 90 additions & 0 deletions
90
research/rainbow_options_direct_method/rainbow_options_direct_method.qmod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
qfunc qmci_oracle(ind: qbit) { | ||
Z(ind); | ||
} | ||
|
||
qfunc affine_max(x1: qnum, x2: qnum, output res: qnum) { | ||
res = max(x1 * 1.0, ((x1 * 0.75) + (x2 * 0.75)) + (-1.25)); | ||
} | ||
|
||
qfunc asset_geq_strike_price(x: qnum, output res: qbit) { | ||
res = x > 1.5; | ||
} | ||
|
||
qfunc exponential_amplitude_loading<exp_rate: real>(x: qbit[], aux: qbit[], res: qbit) { | ||
apply_to_all<X>(x); | ||
repeat (index: x.len) { | ||
control (x[index]) { | ||
RY<2 * acos(1 / sqrt(exp(exp_rate * (2 ** index))))>(aux[index]); | ||
} | ||
} | ||
apply_to_all<X>(x); | ||
aux_num: qnum<aux.len, False, 0>; | ||
aux -> aux_num; | ||
control (aux_num == 0) { | ||
X(res); | ||
} | ||
aux_num -> aux; | ||
} | ||
|
||
qfunc direct_load_amplitudes(geq_reg: qnum, max_reg: qnum, aux_reg: qnum, ind_reg: qbit) { | ||
control (geq_reg == 1) { | ||
exponential_amplitude_loading<(1 / (2 ** max_reg.fraction_digits)) * 0.4341>(max_reg, aux_reg, ind_reg); | ||
} | ||
control (geq_reg == 0) { | ||
RY<2 * asin(13.784 / sqrt(max(193.97 * exp(((0.4341 * (2 ** (max_reg.size - max_reg.fraction_digits))) * (1 - (1 / (2 ** max_reg.size)))) + (-0.7408)), 190)))>(ind_reg); | ||
} | ||
} | ||
|
||
qfunc direct_payoff(max_reg: qnum, aux_reg: qnum, ind_reg: qbit) { | ||
geq_reg: qbit; | ||
within { | ||
asset_geq_strike_price(max_reg, geq_reg); | ||
} apply { | ||
direct_load_amplitudes(geq_reg, max_reg, aux_reg, ind_reg); | ||
} | ||
} | ||
|
||
qfunc rainbow_direct(x1: qnum, x2: qnum, aux_reg: qnum, ind_reg: qbit) { | ||
inplace_prepare_state<[ | ||
0.0656, | ||
0.4344, | ||
0.4344, | ||
0.0656 | ||
], 0>(x1); | ||
inplace_prepare_state<[ | ||
0.0656, | ||
0.4344, | ||
0.4344, | ||
0.0656 | ||
], 0>(x2); | ||
max_out: qnum; | ||
within { | ||
affine_max(x1, x2, max_out); | ||
} apply { | ||
direct_payoff(max_out, aux_reg, ind_reg); | ||
} | ||
} | ||
|
||
qfunc grover_algorithm<k: int, oracle_operand: qfunc (arg0: qbit[]), sp_operand: qfunc (arg0: qbit[])>(x: qbit[]) { | ||
sp_operand(x); | ||
power (k) { | ||
grover_operator<oracle_operand, sp_operand>(x); | ||
} | ||
} | ||
|
||
qfunc main<k: int>(output ind_reg: qbit) { | ||
full_reg: qbit[]; | ||
allocate<10>(full_reg); | ||
grover_algorithm<k, lambda(arg0) { | ||
qmci_oracle(arg0[arg0.len - 1]); | ||
}, lambda(arg0) { | ||
rainbow_direct(arg0[0:2], arg0[2:4], arg0[4:9], arg0[arg0.len - 1]); | ||
}>(full_reg); | ||
state_reg: qbit[]; | ||
full_reg -> {state_reg, ind_reg}; | ||
} | ||
|
||
cscope ``` | ||
iqae_res = iqae(epsilon=0.05, alpha=0.1) | ||
save({'iqae_res': iqae_res}) | ||
``` |
5 changes: 5 additions & 0 deletions
5
research/rainbow_options_direct_method/rainbow_options_direct_method.synthesis_options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"constraints": { | ||
"max_width": 25 | ||
} | ||
} |
Oops, something went wrong.