1. Home
  2. Docs
  3. Knowledge Base
  4. MT University
  5. Securities and Portfolio

Securities and Portfolio


Algorithms have a Securities property that stores a Security object for each currency symbol in your algorithm. Security objects hold the models (backtesting behaviors) and properties of an asset. Each security can be completely customized to behave as you’d like. Securities is a Dictionary<Symbol, Security> so you can access your Security objects with their ticker Securities["BTCUSD"].Price.

					// Popular Securities Property Values:
Securities["BTCUSD"].HasData           // Security has data
                 .Invested          // Have holdings
                 .LocalTime         // Time on the asset exchange
                 .Holdings          // Portfolio object
                 .Exchange          // Exchange information
                 .FeeModel;         // Fee model setter

Your algorithm can access Securities properties as follows:

					//Access to Security Objects with Securities:

Security objects also carry all the models for creating realistic backtests. These models are set via the public security properties and then used in the Machina Engine to improve your backtest realism.

					//Security object properties:
class Security {
    Resolution Resolution;
    bool HasData;
    bool Invested;
    DateTime LocalTime;
    SecurityHolding Holdings;
    SecurityExchange Exchange;
    IFeeModel FeeModel;
    IFillModel FillModel;
    ISlippageModel SlippageModel;
    ISecurityPortfolioModel PortfolioModel;
    ISecurityMarginModel MarginModel;
    ISettlementModel SettlementModel;
    IVolatilityModel VolatilityModel;
    ISecurityDataFilter DataFilter;


The Portfolio property is a collection of SecurityHolding objects to provide easy access to the holding properties. This property also provides information about the whole portfolio state:

					// Popular Portfolio Property Values:
Portfolio.Invested                // Hold at least one stock
         .Cash                    // Sum of all currencies in account (only unsettled cash)
         .UnsettledCash           // Sum of all currencies in account (only settled cash)
         .TotalFees               // Fees incurred since backtest start
         .TotalHoldingsValue      // Absolute sum portfolio items
         .MarginRemaining         // Remaining margin on the account
         .TotalMarginUsed         // Sum of margin used across all securities
         .TotalPortfolioValue     // Portfolio equity
         .TotalProfit             // Sum of all gross profit
         .TotalUnrealizedProfit   // Holdings profit/loss

The Portfolio class is a Dictionary<Symbol, SecurityHolding>, so it can be accessed via ticker index: Portfolio["BTCUSD"].IsLong

					// Popular Portfolio Property Values:
                .IsLong            // IsLong, IsShort Holdings.
                .Quantity          // Shares held.
                .UnrealizedProfit; // Holdings profit/loss
                .TotalFees         // Fees incurred since backtest start
                .Price;            // Asset price
Was this article helpful to you? Yes No

How can we help?

Close Menu