MachinaTrader's algorithm Engine manages your portfolio and data feeds, letting you focus on your algorithm strategy and execution. Data is piped into your strategy via event handlers, upon which you can place trades. The Engine also provides basic portfolio management and fill modeling. This is provided by the MEAlgorithm
base class.
All algorithms extend MEAlgorithm
, which provides some key helper properties for you to use: Security Manager, Portfolio Manager, Transactions Manager, Notification Manager, and Scheduling Manager. Along with hundreds of helper methods to make the API easy to use. We'll go into more detail in the rest of this chapter.
The SecurityManager is a dictionary of Security objects. Each asset (crypto, forex pair, etc) in your algorithm has a security object. All the models for a security live on these objects: e.g. Securities["IBM"].FeeModel
or Securities["IBM"].Price
PortfolioManager is a dictionary of SecurityHolding classes. These classes track the individual portfolio items profit and losses, fees, and quantity held. e.g. Portfolio["IBM"].LastTradeProfit
Other helpers like TransactionManager, ScheduleManager, and NotificationManager have their own helper methods, which will also be explained in this chapter.
public class MEAlgorithm
{
SecurityManager Securities; //Array of Security objects.
SecurityPortfolioManager Portfolio; // Array of SecurityHolding objects
SecurityTransactionManager Transactions; // Transactions helper
ScheduleManager Schedule; // Scheduling helper
NotificationManager Notify; //Email, SMS helper
UniverseManager Universe; // Universe helper
//Set up Requested Data, Cash, Time Period.
public virtual void Initialize() { ... };
//Event Handlers:
public virtual OnData(Slice data) { ... };
public virtual OnDividend() { ... };
public virtual OnEndOfDay() { ... };
public virtual OnEndOfAlgorithm() { ... };
//Helpers...
public SimpleMovingAverage SMA();
}