Package com.polytechnik.freemoney
Class CommonlyUsedMoments
java.lang.Object
com.polytechnik.freemoney.CommonlyUsedMoments
- All Implemented Interfaces:
CommonBasisOperations
- Direct Known Subclasses:
CommonlyUsedMomentsLaguerre
,CommonlyUsedMomentsLegendreShifted
,CommonlyUsedMomentsMonomials
A class to calculate commonly used moments.
It has an internal state
WIntegrator
and methods for
updating the internal state with new t,P,dv
coming.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
private long
private double
For d lambda^{IH}/dt calculation using secondary sampling.private double
For d lambda^{IH}/dt calculation using secondary sampling.private double
For dp/dt calculation.private double
Price offset to increase numerical stability.private long
Time of last trade added, may be different from last basis time referenceWIntegrator.currenttime_previous
.private final WIntegrator
Recurrent integrator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIHObservationSecondarySampling
(double IH) An experiment to calculate \( \frac{d}{dt}I^H \), \( \frac{d}{dt} P I^H \), and \( P\frac{d}{dt}I^H \) moments by using secondary sampling; the \( I^H \) is calculated from directly sampled moments and then used as it were a regular observable.void
addObservationNoBasisShift
(long currenttime, long t, double P, double dv) double[]
<A*dP/dt *Qk>.double[]
A poor man volume, <abs(dp)/dt*Qk>.double[]
An experimental method to obtain \( \frac{d}{dt}I^H \) moments using secondary sampling.double[]
An experimental method to obtain \( \frac{d}{dt}PI^H \) moments using secondary sampling.double[]
Price change moments <dp/dt*Qk>.double[]
The moments of a constant <Qk>, analytically obtained exact value.double[]
Volume moments <I*Qk>.double[]
<p^2*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_I
and price power=2.double[]
<p^3*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_I
and price power=3.double[]
The moments <p*abs(dp)/dt*Qk>.double[]
An experimental method to obtain \( P\frac{d}{dt}I^H \) moments using secondary sampling.double[]
<p*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_I
and price power=1.double
Last price as peraddObservationNoBasisShift(long, long, double, double)
call.double
Price Offset.double[]
<T*abs(dp)/dt*Qk>.double[]
<T*dp/dt*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TDP
and price power=1.double[]
Obtained using integration by parts fromgetdtMoments()
.double[]
<T*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TI
and price power=0.double
double
double[]
<p^2*T*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TI
and price power=2.double[]
<p^3*T*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TI
and price power=3.double[]
<p*T*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TI
and price power=1.double[]
<V*dP/dt *Qk>.double[]
Obtained using integration by parts fromgetdVMoments()
.void
setInitIHForSecondarySampling
(double IH_lastsaved) For unit tests to imitate initial input to match an observable's derivative.void
updateBasisToNewTimeReference
(long currenttime, double new_p_offset) void
updateWithSingleObservation
(long currenttime, long t_last, double P_last, double dv_last) A trivial update with a single triple (t,P,dv) coming.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.polytechnik.freemoney.CommonBasisOperations
getABasis, getDFMomentsFromF, getdtMoments, getEDPsi, getEmptyWIntegrator, getFMomentsFromDF, getPolynomialWIntegratedDt, getPsi2WIntegratedDt
-
Field Details
-
wi
Recurrent integrator. -
p_offset
private double p_offsetPrice offset to increase numerical stability. -
P_lastsaved
private double P_lastsavedFor dp/dt calculation. -
IH_lastsaved
private double IH_lastsavedFor d lambda^{IH}/dt calculation using secondary sampling. -
P_for_IH_lastsaved
private double P_for_IH_lastsavedFor d lambda^{IH}/dt calculation using secondary sampling. -
t_lastsaved
private long t_lastsavedTime of last trade added, may be different from last basis time referenceWIntegrator.currenttime_previous
. -
counter_addObservationNoBasisShift
private long counter_addObservationNoBasisShift -
counter_addIHObservationSecondarySampling
private long counter_addIHObservationSecondarySampling
-
-
Constructor Details
-
CommonlyUsedMoments
public CommonlyUsedMoments(int ntm, double atau) Initial state.
-
-
Method Details
-
updateWithSingleObservation
public void updateWithSingleObservation(long currenttime, long t_last, double P_last, double dv_last) A trivial update with a single triple (t,P,dv) coming. The method shifts the basis to correspond tocurrenttime
; new value ofgetPOffset()
can be also set to increase numerical stability. Internally the method adjusts the basis usingupdateBasisToNewTimeReference(long, double)
, then callsaddObservationNoBasisShift(long, long, double, double)
to add an observation. -
updateBasisToNewTimeReference
public void updateBasisToNewTimeReference(long currenttime, double new_p_offset) -
addObservationNoBasisShift
public void addObservationNoBasisShift(long currenttime, long t, double P, double dv) -
addIHObservationSecondarySampling
public void addIHObservationSecondarySampling(double IH) An experiment to calculate \( \frac{d}{dt}I^H \), \( \frac{d}{dt} P I^H \), and \( P\frac{d}{dt}I^H \) moments by using secondary sampling; the \( I^H \) is calculated from directly sampled moments and then used as it were a regular observable. The call ofaddIHObservationSecondarySampling(double)
should immediately followupdateWithSingleObservation(long, long, double, double)
. We use incremental calculation of moments.- See Also:
-
getPOffset
public double getPOffset()Price Offset. Selected close to last price to simplify calculations. Average price would probably provide a slightly better numerical stability. All price moments are calculated relatively this offset, this greatly increases numerical stability. To obtain "actual" price from the values stored in moments data -- add the value returned by this method.- See Also:
-
getPLast_withoutPOffset
public double getPLast_withoutPOffset()Last price as peraddObservationNoBasisShift(long, long, double, double)
call. No price offset used. To use it with saved price moments -- use the valuegetPLast_withoutPOffset()
-getPOffset()
. -
getdVMoments
public double[] getdVMoments()Volume moments <I*Qk>. Corresponds toDataInterfaceDirectTradesHistorical.M_I
and price power=0.- See Also:
-
getTotalVolume
public double getTotalVolume() -
getTotalA
public double getTotalA() -
getPdVMoments
public double[] getPdVMoments()<p*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_I
and price power=1. -
getP2dVMoments
public double[] getP2dVMoments()<p^2*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_I
and price power=2. -
getP3dVMoments
public double[] getP3dVMoments()<p^3*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_I
and price power=3. -
getTdVMoments
public double[] getTdVMoments()<T*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TI
and price power=0. -
getTPdVMoments
public double[] getTPdVMoments()<p*T*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TI
and price power=1. -
getTP2dVMoments
public double[] getTP2dVMoments()<p^2*T*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TI
and price power=2. -
getTP3dVMoments
public double[] getTP3dVMoments()<p^3*T*I*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TI
and price power=3. -
getdpMoments
public double[] getdpMoments()Price change moments <dp/dt*Qk>. Corresponds toDataInterfaceDirectTradesHistorical.M_DP
and price power=1. -
getTdpMoments
public double[] getTdpMoments()<T*dp/dt*Qk>, corresponds toDataInterfaceDirectTradesHistorical.M_TDP
and price power=1. -
getdAMoments
public double[] getdAMoments()A poor man volume, <abs(dp)/dt*Qk>. Instead of a number of shares traded the absolute value of every tick price change is used as integration measure. Can be used instead of volume with mixed results, see Fig. 6. Corresponds toDataInterfaceDirectTradesHistorical.M_A
and price power=0.- See Also:
-
getPdAMoments
public double[] getPdAMoments()The moments <p*abs(dp)/dt*Qk>. Instead of a number of shares traded the absolute value of every tick price change is used as integration measure. Corresponds toDataInterfaceDirectTradesHistorical.M_A
and price power=1.- See Also:
-
getAdPMoments
public double[] getAdPMoments()<A*dP/dt *Qk>. -
getTdAMoments
public double[] getTdAMoments()<T*abs(dp)/dt*Qk>.- See Also:
-
getTdtMoments
public double[] getTdtMoments()Obtained using integration by parts fromgetdtMoments()
. -
getVdtMoments
public double[] getVdtMoments()Obtained using integration by parts fromgetdVMoments()
. -
getdtMoments
public double[] getdtMoments()The moments of a constant <Qk>, analytically obtained exact value. Corresponds toDataInterfaceDirect.setMT(double[], int)
. -
getVdPMoments
public double[] getVdPMoments()<V*dP/dt *Qk>. Corresponds toDataInterfaceDirectTradesHistorical.M_VdPdt
and price power=1.- See Also:
-
getdIHdtMoments
public double[] getdIHdtMoments()An experimental method to obtain \( \frac{d}{dt}I^H \) moments using secondary sampling. RequiresaddIHObservationSecondarySampling(double)
to be properly called on every tick.- See Also:
-
getPdIHdtMoments
public double[] getPdIHdtMoments()An experimental method to obtain \( P\frac{d}{dt}I^H \) moments using secondary sampling. RequiresaddIHObservationSecondarySampling(double)
to be properly called on every tick.- See Also:
-
getdPIHdtMoments
public double[] getdPIHdtMoments()An experimental method to obtain \( \frac{d}{dt}PI^H \) moments using secondary sampling. RequiresaddIHObservationSecondarySampling(double)
to be properly called on every tick. For secondary sampling where the \( I^H \) can be of various meaning it is better to use \( \frac{d}{dt}PI^H \) rather than \( I^H\frac{d}{dt}P \) as ingetVdPMoments()
for the reason of unit test simplification. The \( I^H\frac{d}{dt}P \) can be obtained asgetdPIHdtMoments()
-getPdIHdtMoments()
.- See Also:
-
setInitIHForSecondarySampling
public void setInitIHForSecondarySampling(double IH_lastsaved) For unit tests to imitate initial input to match an observable's derivative. In application the initial value is zero and this method is not required.
-