5. Class Structure

Disclaimer

Before reading this tutorial you, the reader, agree to the following. This tutorial and the code it contains are designed to be informational and educational tools only. They do not constitute investment advice. The author, Dave Topper, strongly recommends that you seek the advice of a financial services professional before making any type of investment. This model is provided as a rough approximation of future financial performance. The results presented are hypothetical and will likely not reflect the actual growth of your own investments. The author, Dave Topper, is not responsible for any human or mechanical errors or omissions. The author, Dave Topper, is not responsible for the consequences of any decisions or actions taken in reliance upon or as a direct or indirect result of the information provided by these tools.

It is often a good idea to think about the overall class structure of an application before writing any code. There’s no need to have it 100% complete at the outset, but referring back to it and keeping it updated can be extremely helpful as things get more complicated. UML is also a very useful tool for creating diagrams that represent the structure of your code. I use xDiagram under MacOS for my own work. For this tutorial, however, a simple outline will suffice.

The algorithm we will be designing is a type of Crossover Strategy. This is a great technique to start with. It offers us a few variables to optimize and compels us to be efficient with a few of our mathematical calculations (eg., the moving averages).

The following are the primary classes we will be building.

An input argument parser class will parse command line arguments and turn them into parameters for our model.

A parameter class will take command line arguments and store them in a format that can be passed to other classes within our application. The name of our data file will also be a parameter.

A trading model class will implement our trading logic, executing BUY and SELL signals accordingly.

A price data class will hold our OHLCV data. It will also be responsible for parsing our data file and loading it into the appropriate matrix.

A quick moving average class will help us create the two moving averages used for our Crossover Strategy.

A portfolio class will keep track of our profit and/or loss as well as various other important trade statistics.

We will start by creating a parameter class.

< previous | next >