Package com.polytechnik.utils
Class MaximizeStandardDeviation
java.lang.Object
com.polytechnik.utils.MaximizeStandardDeviation
Find \( \left|\psi\right> \) state such that
\[
P\&L=\frac{\left<\psi|(p-\mathtt{pa})^2 I| \psi\right>}{\left<\psi|\psi\right> }
\xrightarrow[\psi]{\quad }\max
\]
subject to:
\[
\left<\psi|(p-\mathtt{pa}) I|\psi\right>=0
\]
The constant
\( \mathtt{pa}=\left<\psi|p I|\psi\right>/\left<\psi|I|\psi\right> \)
is average price in \( \left|\psi\right> \) state.
and the functional itself has the meaning of \( P\&L \).
Contrary to pure iteration type approach of
DIminP2maxI
this implementation uses Lagrange multipliers technique
to improve the convergence.
The functional \[
\left<\psi|(p-\mathtt{pa})^2 I| \psi\right>
+\mu\left<\psi|(p-\mathtt{pa}) I|\psi\right>
- \lambda\left[\left<\psi|\psi\right> -1\right]
\]
is constructed. Variate it by \( \left|\psi\right> \) , obtain the equation:
\[
\left|(p-\mathtt{pa})^2 I| \psi\right>
+\mu\left|(p-\mathtt{pa}) I|\psi\right>=
\lambda\left|\psi\right>
\]
An iteration process is:
- For an initial \( \left|\psi\right> \) calculate average price \( \mathtt{pa} \) and Lagrange multiplier \( \mu \): \begin{align} \mathtt{pa}&=\frac{\left<\psi|p I|\psi\right>}{\left<\psi|I|\psi\right>} \\ \left|b\right>&=\left|(p-\mathtt{pa}) I|\psi\right> \\ \mu &= - \, \frac{\left<b|(p-\mathtt{pa})^2 I|\psi\right>}{\left<b|b\right>} \end{align}
- Construct the matrix \[ \left|{\cal PL}\right|= \left|(p-\mathtt{pa})^2 I\right| +\mu\left|(p-\mathtt{pa}) I\right| \]
- Solve eigenvalue problem \[
\left|{\cal PL}|\psi^{[i]}\right>=
\lambda^{[i]} \left|\psi^{[i]}\right>
\]
and take the state \( \left|\psi^{[i]}\right> \)
corresponding an eigenvalue \( \lambda^{[i]} \)
as next iteration \( \left|\psi\right> \) .
Often (but not always!) this is the state corresponding to
maximal eigenvalue. In general case see
MaximizeStandardDeviation.EVSelection
that selects the state of maximal \( P\&L \). - Take the matrix
\( \left|{\cal PL}\right| \)
with updated \( \mathtt{pa} \) and \( \mu \) and repeat the process of above
for this new \( \left|\psi\right> \) .
If a solution exists -- iteration process
converges quickly (typically 5-7 iterations), unless price \( |p| \) and execution flow \( |I| \)
operators have several eigenvectors in common;
for example when \( \left|(p-\mathtt{pa})^2 I\right| \) and \( \left|(p-\mathtt{pa})I\right| \)
operators have the same eigenvectors the \( \left|{\cal PL}\right| \)
eigenvectors are always the same and iteration process fails.
On the first iteration
as \( \left|\psi\right> \)
select an eigenvectors of the problem
\( \left|I|\psi\right>=\lambda\left|\psi\right> \) ,
a few eigenvectors corresponding to large execution flow is a good try.
Typically the
MaximizeStandardDeviation.StandardDeviationForPsi
is used to calculate the \( P\&L \) for all these eigenvectors and sorting them by it. - The result of this iteration process is the state of maximal \( P\&L \) , it is equal to the value of maximal eigenvalue of
\( \left|{\cal PL}|\psi^{[i]}\right>=
\lambda^{[i]} \left|\psi^{[i]}\right>
\) problem. Position change \( dS \)
corresponding to it is:
\begin{align}
dS&=-(p-\mathtt{pa})\psi^2(x(t))\omega(t) dV \\
P\&L&= -\int p dS = \left<\psi|(p-\mathtt{pa})^2I|\psi\right> = \lambda^{[\max]}\\
0&=\int dS = - \left<\psi|(p-\mathtt{pa})I|\psi\right>
\end{align}
Position change is a subject to \(0=\int dS\) constraint,
\( P\&L \) is a covariance (with minus sign)
between price and postion change.
The \( P\&L \) can be written in dual form by applying integration by parts
to express it not via postion change \( dS \) but via postion \( S\) itself:
\begin{align}
S(t_{now})&=\int_{t=-\infty}^{t=t_{now}} dS \\
P\&L&= \int S dp \\
0&=S(-\infty)=S(t_{now})
\end{align}
Directional information can be obtained from considering \( S(t) \)
behavior, localized form of \( \psi^2(x(t)) \)
makes it often sufficient to consider
\( \left<S\right> \) :
whether "on average" we have to be long or short.
In some \( x, \omega(x) \) bases \( \left<S\right> \)
can be plain reduced to \(
\left<\psi|(p-\mathtt{pa})Ix|\psi\right>
\) form or similar; in such a case normalized solution to market direction
can be e.g. a correlation
between \( (p-\mathtt{pa})I \) and \( x \) in the found state
\( \left|\psi\right> \) ,
see an example in unit test
PnLInPsiHstate.PnLInPsiHstateTest.test_Extra()
. In general, however, such a correlation-style approach is typically unsatisfactory.
psi_PnLMax
corresponding to maximal \( P\&L \).- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
As the state corresponding to maximal \( P\&L \) is not necessary the maximal eigenvalue state due to average price offset -- check all the eigenstates.private static class
A helper class: calculate standard deviation for a set of \( \left|\psi\right> \) states. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal EVXData
The \( \left|I|\psi\right>=\lambda \left|\psi\right> \) solution.final double
final double
In case of good convergence matchesPnLMax
exactly.final double
Lagrange multiplier (has a dimension of price change).private static final int
final double
final double
final double
final double[]
The state maximaizing P&L functional. -
Constructor Summary
ConstructorsConstructorDescriptionMaximizeStandardDeviation
(int n, double[] QQt, double[] QQi, double[] QQpi, double[] QQp2i, OrthogonalPolynomialsBasisFunctionsCalculatable<? extends BasisFunctionsCalculatable> M, double eps) -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Unit test.(package private) static void
-
Field Details
-
N_iterations
private static final int N_iterations- See Also:
-
p_IH
public final double p_IH -
pA_PnLMax
public final double pA_PnLMax -
PnLMax
public final double PnLMax -
I_PnLMax
public final double I_PnLMax -
lambda_PnLMax
public final double lambda_PnLMaxIn case of good convergence matchesPnLMax
exactly. -
mu_PnLMax
public final double mu_PnLMaxLagrange multiplier (has a dimension of price change). -
psi_PnLMax
public final double[] psi_PnLMaxThe state maximaizing P&L functional. -
I
The \( \left|I|\psi\right>=\lambda \left|\psi\right> \) solution.
-
-
Constructor Details
-
MaximizeStandardDeviation
public MaximizeStandardDeviation(int n, double[] QQt, double[] QQi, double[] QQpi, double[] QQp2i, OrthogonalPolynomialsBasisFunctionsCalculatable<? extends BasisFunctionsCalculatable> M, double eps)
-
-
Method Details
-
printDiag
-
main
Unit test.
-