A strategy for stock trading based on multiple models and trading rules
CS 395T Project Report
Subramanian Ramamoorthy
December 5, 2003
1.Introduction
The stock market represents a very interesting dynamical system that has intrigued analysts from a number of disciplines. A recent trend among the machine learning community is to build automated agent programs that trade in this market in a relatively autonomous fashion. This is part of a much larger program of research into autonomous agent systems [1].
This report is an account of the design of one such agent. This agent is designed to function within the framework of the Penn-Lehman Automated Trading Project (PLAT) [2]. The details of PLAT are not discussed here. For details on the system architecture and design, the reader is referred to the paper [2], and the PLAT project web site [3].
The structure of the game is essentially as follows. The PXS (Penn Exchange Simulator) server provides an electronic exchange for Microsoft shares, ticker symbol MSFT. This electronic exchange is a hybrid of a real world electronic crossing network (ECN) within NASDAQ and an internal market of agents such as mine. The agents are software programs written to communicate in a client-server protocol with the PXS server. Each agent has the option of invoking various actions such as “Buy” and “Sell”, has control over price and volume of trades and has access to various indicators of both the internal (simulator) and the external (Island ECN) markets. The objective of the agent design is to design an automated strategy that can satisfy the following key requirements:
1.Maximize profits. Specifically, maximize expected return in a strict statistical
sense, measured by the Sharpe ratio, to be defined below
2.Unwind (i.e., bring to zero) the entire share position at the end of the trading day.
Failure to do so results in a penalty. Any excess shares held at the end of the trading day are valued at zero. Shares that are ‘short’, i.e., a negative holding, needs to be bought back by the agent at twice the closing price.
sqrt函数用法stata3.Take into account transaction costs, i.e., a fee on every share traded.
mouse的复数形式
The reader may note that there are clearly multiple competing objectives at play here. The need to maximize profits by taking extreme positions is countered by the need to unwind one’s position at the end of the trading day. Moreover, one needs to maximize profits in a “robust” way so as to maximize a statistical measure of performance, the Sharpe ratio, defined as the ratio of the average of the daily returns and the standard deviation of daily returns. Daily returns are defined as:
Return, R = Cash – Unwinding Penalty – Trading Fees + Trading Rebates
The average daily return is,
å==N
i i R N R 1
1
The standard deviation of returns is,
()2
11211÷ø
öçèæ--=å=N i i R R N s  The Sharpe ratio is,
s
position of the day
R SR =
The key point to note from this formulation is that it is desirable to make consistent small profits, as opposed to adopting strategies that provide very high returns but also result in very large variance, neutralizing the benefits of the large returns. In this sense, the need is for a controlled  trading strategy.
2. Brief survey of the literature
There exists an immense body of work on the mathematical analysis of the behavior of stock prices, stock markets and successful strategies for trading in these environments. In recent times, a variety of different approaches have been tried for achieving the goals outlined in section 1. Some representative examples from the machine learning perspective would include rule induction and genetic algorithms [4,5], neural networks
[6], reinforcement learning [7], etc. While these are powerful techniques, they also require extensive
data handling and processing and the use of computational power.
Apart from these sophisticated approaches, a popular approach among practitioners is the use of technical trading rules. These techniques assume that, notwithstanding the efficient market hypothesis, there exist patterns in stock returns and that they can be exploited by analysis of the history of stock prices, returns and other key indicators. The reader is referred to [8] for more details on technical analysis for stock trading. The paper, [9], is a very good description of why it is a suitable tool, notwithstanding some controversy regarding their utility, for the problem at hand.json教程菜鸟教程
3. An ‘intuitive’ approach to stock trading
My research for this project is centered on the notion of using ‘intuitive’ strategies, i.e., that appeal to “common sense” and embody assumptions similar to those held by human traders. The final working strategy that resulted from my research is a robust strategy designed by composing multiple ‘intuitive’ strategies into a workable global strategy. The hypothesis is that robustness and relatively complex global behaviors are achievable by synthesizing multiple, intuitively obvious and structurally well defined local behaviors.
A simple intuition behind stock trading is summarized by the dictum “Buy Low, Sell High”. Essentially,
if one bought a share at a ‘low’ price p and then sold it at a ‘high’ price d
p, one makes a profit of d. A consistent series of such trades would quickly +
accumulate wealth for the trader.
Clearly, the problem in real stock markets is that one never really knows the future and the decision of when to buy in anticipation of a future price increase is a difficult one. This decision is further complicated by the fact that there is a strict penalty for not unwinding one’s position. So, if one were to take an extreme position in anticipation of a future price increase and such an increase were to never materialize, one takes a big loss for that trading day.
A working assumption that helps alleviate this problem is that stock returns are mean reverting. This is an assumption that is made often in the financial theory literature, and is supported by some empirical evidence. From the perspective of the current problem, one may assume that stock prices are mean reverting and so it is possible to trade now in expectation of a future movement in the opposite direction (In later sections, we will examine how to deal with the violation of this assumption). A simple trading strategy based on this assumption is as shown below.
接口测试jmeter
Algorithm 1:
MA1 = Moving Average of Stock Price over a horizon N1
MA2 = Moving Average of Stock Price over a horizon N2 (N2 > N1)
Begin Loop:
Calculate MA1, MA2 using the Last Price from Island ECN
If(MA1 > MA2 + Threshold )
Then Sell m shares @ SellPrice
Else If (MA2 > MA1 + Threshold)
Then Buy m shares @ BuyPrice
Else
Do Nothing
End Loop.
The selection of individual variables in this algorithm will be addressed in a future section.
The need to unwind positions is clearly not included in this algorithm. A preliminary approach to this problem is to decide on a fixed window before closing time and to divest all of one’s holdings.
Including this strategy, we get a modified version of the above algorithm as:
Algorithm 1.1
If (time < window)
Then Algorithm 1
Else
If(Number of Shares > 0)
Then Sell m shares
Else
Buy m shares
m: A fraction of the current share holdings
This algorithm would attempt to end with zero holdings and during the active trading period, it can be expected to make gains.
This algorithm is an attempt at a simple trend based strategy. In actual experiments, this strategy was found to be capable of making large gains, but it was equally likely to take large losses. The figures below show typical plots of results obtained with this algorithm, when the return is favorable.
These plots illustrate the following key points:
-The stock price over the trading day showed both positive and negative fluctuations. In response, the agent took both positive and negative positions and unwound successfully, ending in a profitable position.
-The trend was very favorable in that positive holdings were followed by an increasing trend, resulting in profits.
A key point to note is that the return is largely dependent on the nature of the trends. A favorable trend would cause the agent to take a strong position and divest at a profitable rate. On the other ha
nd, a move to the other direction would leave the agent exposed and it would take large losses. As it stands, the result is entirely dependent upon the nature of the trend.
phpmyadmin错误缺少mysqlThe following figures illustrate this aspect of the algorithm.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。