Venice 0.7beta

org.mov.analyser
Class PaperTrade

java.lang.Object
  extended by org.mov.analyser.PaperTrade
Direct Known Subclasses:
ANNPaperTrade

public class PaperTrade
extends java.lang.Object

Paper trades stocks using historical quote data and buy and sell indicators. Paper or back trading is a good way of testing the effectiveness of indicators without risking money. This class allows the user to supply historical quote data and buy and sell indicators. The class will then trade using the given indicators and return the final portfolio.

The final portfolio will contain a single cash and a single share account.

Author:
Andrew Leppard

Nested Class Summary
protected  class PaperTrade.Environment
           
 
Field Summary
protected static boolean[] buyRule
           
protected static double[] buyValue
           
protected static java.lang.String CASH_ACCOUNT_NAME
           
protected static boolean[] sellRule
           
protected static double[] sellValue
           
protected static java.lang.String SHARE_ACCOUNT_NAME
           
static int STOCKS_PER_LINES
           
protected static java.lang.String[] symbolStock
           
 
Constructor Summary
protected PaperTrade()
           
 
Method Summary
protected static boolean buy(PaperTrade.Environment environment, Variables variables, Symbol symbol, Money amount, Money tradeCost, double buyPrice, int day)
          Attempt to buy the given symbol.
protected static double getCapital(Portfolio portfolio, EODQuoteBundle quoteBundle, int dateOffset)
          Return the actual capital of the portfolio.
protected static int getHoldingTime(PaperTrade.Environment environment, StockHolding stockHolding, int dateOffset)
          Return the number of days we have held the given stock.
protected static double getStockCapital(PaperTrade.Environment environment, StockHolding stockHolding, Symbol symbol, int dateOffset)
          Return the actual capital of the given stock.
static java.lang.String getTip()
          Return a string representing the tip for next day trading.
static Portfolio paperTrade(java.lang.String portfolioName, EODQuoteBundle quoteBundle, Variables variables, OrderCache orderCache, TradingDate startDate, TradingDate endDate, Expression buy, Expression sell, Money capital, int numberStocks, Money tradeCost, java.lang.String tradeValueBuy, java.lang.String tradeValueSell)
          Perform paper trading keeping the number of stocks in the portfolio roughly constant.
static Portfolio paperTrade(java.lang.String portfolioName, EODQuoteBundle quoteBundle, Variables variables, OrderCache orderCache, TradingDate startDate, TradingDate endDate, Expression buy, Expression sell, Money capital, Money stockValue, Money tradeCost, java.lang.String tradeValueBuy, java.lang.String tradeValueSell)
          Perform paper trading using a fixed stock value.
protected static void sell(PaperTrade.Environment environment, Variables variables, StockHolding stockHolding, Money tradeCost, double sellPrice, int day)
          Attempt to sell the given stock holding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CASH_ACCOUNT_NAME

protected static final java.lang.String CASH_ACCOUNT_NAME

SHARE_ACCOUNT_NAME

protected static final java.lang.String SHARE_ACCOUNT_NAME

STOCKS_PER_LINES

public static final int STOCKS_PER_LINES
See Also:
Constant Field Values

symbolStock

protected static java.lang.String[] symbolStock

buyRule

protected static boolean[] buyRule

sellRule

protected static boolean[] sellRule

buyValue

protected static double[] buyValue

sellValue

protected static double[] sellValue
Constructor Detail

PaperTrade

protected PaperTrade()
Method Detail

sell

protected static void sell(PaperTrade.Environment environment,
                           Variables variables,
                           StockHolding stockHolding,
                           Money tradeCost,
                           double sellPrice,
                           int day)
                    throws EvaluationException,
                           MissingQuoteException
Attempt to sell the given stock holding. If we could not meet the trade cost, the stock will not be sold.

Parameters:
environment - the paper trade environment
stockHolding - the stock holding to sell
tradeCost - the cost of a trade
day - date of trade
Throws:
EvaluationException
MissingQuoteException

buy

protected static boolean buy(PaperTrade.Environment environment,
                             Variables variables,
                             Symbol symbol,
                             Money amount,
                             Money tradeCost,
                             double buyPrice,
                             int day)
                      throws EvaluationException,
                             MissingQuoteException
Attempt to buy the given symbol.

Parameters:
environment - the paper trade environment
symbol - the stock to buy
amount - the amount to spend on the stock
tradeCost - the cost of a trade (not including the stock price)
day - date of trade
Returns:
true if we had enough money to acquire the stock.
Throws:
EvaluationException
MissingQuoteException

getHoldingTime

protected static int getHoldingTime(PaperTrade.Environment environment,
                                    StockHolding stockHolding,
                                    int dateOffset)
Return the number of days we have held the given stock.

Parameters:
environment - the paper trade environment
stockHolding - to query
dateOffset - current date
Returns:
the holding time

getStockCapital

protected static double getStockCapital(PaperTrade.Environment environment,
                                        StockHolding stockHolding,
                                        Symbol symbol,
                                        int dateOffset)
Return the actual capital of the given stock.

Parameters:
environment - the paper trade environment
stockHolding - to query
dateOffset - current date
symbol - the stock of whom you want to know the capital owned
Returns:
the actual capital of the given stock

getCapital

protected static double getCapital(Portfolio portfolio,
                                   EODQuoteBundle quoteBundle,
                                   int dateOffset)
Return the actual capital of the portfolio.

Parameters:
portfolio - the paper trade portfolio
quoteBundle - historical quote data
dateOffset - current date
Returns:
the actual capital of the portfolio

paperTrade

public static Portfolio paperTrade(java.lang.String portfolioName,
                                   EODQuoteBundle quoteBundle,
                                   Variables variables,
                                   OrderCache orderCache,
                                   TradingDate startDate,
                                   TradingDate endDate,
                                   Expression buy,
                                   Expression sell,
                                   Money capital,
                                   Money stockValue,
                                   Money tradeCost,
                                   java.lang.String tradeValueBuy,
                                   java.lang.String tradeValueSell)
                            throws EvaluationException
Perform paper trading using a fixed stock value. This method will try to keep the value of each stock holding equal to stockValue.

Parameters:
portfolioName - name to call portfolio
quoteBundle - historical quote data
variables - any Gondola variables set
orderCache - cache of ordered symbols
startDate - start date of trading
endDate - last date of trading
buy - the buy indicator
sell - the sell indicator
capital - initial capital in the portfolio
stockValue - the rough value of each stock holding
tradeCost - the cost of a trade
Returns:
the portfolio at the close of the last day's trade
Throws:
EvaluationException

paperTrade

public static Portfolio paperTrade(java.lang.String portfolioName,
                                   EODQuoteBundle quoteBundle,
                                   Variables variables,
                                   OrderCache orderCache,
                                   TradingDate startDate,
                                   TradingDate endDate,
                                   Expression buy,
                                   Expression sell,
                                   Money capital,
                                   int numberStocks,
                                   Money tradeCost,
                                   java.lang.String tradeValueBuy,
                                   java.lang.String tradeValueSell)
                            throws EvaluationException
Perform paper trading keeping the number of stocks in the portfolio roughly constant. This method will try to keep the number of stocks in the portfolio roughly equal to numberStocks, and will try to have all of them at roughly the same value.

Parameters:
portfolioName - name to call portfolio
quoteBundle - historical quote data
variables - any Gondola variables set
orderCache - cache of ordered symbols
startDate - start date of trading
endDate - last date of trading
buy - the buy indicator
sell - the sell indicator
capital - initial capital in the portfolio
numberStocks - try to keep this number of stocks in the portfolio
tradeCost - the cost of a trade
Returns:
the portfolio at the close of the last day's trade
Throws:
EvaluationException

getTip

public static java.lang.String getTip()
Return a string representing the tip for next day trading. The method can be called after a paperTrade one, so doing it obtains a tip for next day trading, where next is the date folowing the end date of the trading period of paperTrade.

Returns:
the string representing the tip.

Venice 0.7beta