AlgoQuant, an integrated trading strategy research and backtesting system
com.numericalmethod.algoquant.model.util.movingwindow

## Class MovingWindowOfReturns

• java.lang.Object
• com.numericalmethod.algoquant.model.util.movingwindow.MovingWindowOfReturns

• public class MovingWindowOfReturns
extends Object
Maintains multiple fixed-length series of returns (of a specified type).
• ### Constructor Summary

Constructors
Constructor and Description
MovingWindowOfReturns(ReturnsCalculator returnCalculator, int dimension)
Constructs an instance with the default capacity of Integer.MAX_VALUE.
MovingWindowOfReturns(ReturnsCalculator returnCalculator, int dimension, int capacity)
Constructs an instance.
• ### Method Summary

All Methods
Modifier and Type Method and Description
boolean addPrices(double[] prices)
Updates the series with new prices.
void clear()
Clears all the cached returns.
int size()
The length of the series, i.e., the number of periods.
com.numericalmethod.suanshu.algebra.linear.matrix.doubles.Matrix toMatrix()
Gets the multiple return series as a matrix, each row for one period (that is, each column vector is a return series for an asset).
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### MovingWindowOfReturns

public MovingWindowOfReturns(ReturnsCalculator returnCalculator,
int dimension,
int capacity)
Constructs an instance.
Parameters:
returnCalculator - the type of returns calculation
dimension - the number of series
capacity - the maximum length of the series
• #### MovingWindowOfReturns

public MovingWindowOfReturns(ReturnsCalculator returnCalculator,
int dimension)
Constructs an instance with the default capacity of Integer.MAX_VALUE.
Parameters:
returnCalculator - the type of returns calculation
dimension - the number of series
• ### Method Detail

public boolean addPrices(double[] prices)
Updates the series with new prices.
Parameters:
prices - new prices
Returns:
true if the length of the series reaches the capacity
• #### toMatrix

public com.numericalmethod.suanshu.algebra.linear.matrix.doubles.Matrix toMatrix()
Gets the multiple return series as a matrix, each row for one period (that is, each column vector is a return series for an asset).
Returns:
a matrix of returns; null if the series is empty
• #### size

public int size()
The length of the series, i.e., the number of periods.
Returns:
size of the series
• #### clear

public void clear()
Clears all the cached returns. Note: the last updated prices will not be cleared, so that the next price update will be used to compute the new returns. For example, after 10 updates, the return matrix contains 9 rows. Clearing the cache followed by 10 more updates produces a return matrix of 10 rows.