Portfolio

Key Concepts

Introduction

The Portfolio object provides information about the whole portfolio state.

Properties

The Portfolio object has the following properties:

var invested = Portfolio.Invested;
var value = Portfolio.TotalPortfolioValue;
invested = self.Portfolio.Invested
value = self.Portfolio.TotalPortfolioValue

Cost Averaging Accounting

LEAN uses the cost averaging accounting method, which determines the cost of your holdings by taking a weighted average of all your purchase prices. For example, say you place the following buy orders:

  1. Buy 10 ABC @ $10
  2. Buy 5 ABC @ $11
  3. Buy 20 ABC @ $14
  4. Buy 3 ABC @ $9

In the preceding example, the average cost of your ABC position is (10*10 + 5*11 + 20*14 + 3*9) / (10 + 5 + 20 + 3) = $12.1579/share. In contrast, if you use the first-in, first-out (FIFO) accounting method, the cost of the first 10 shares is $10/share, not $12.1579/share.

Long and Short Holdings

You can identify a position as long- or short-biased based on the sign of the holding quantity. Long positions have a positive quantity and short positions have a negative quantity.

Buying Power

To get the maximum order size you can place for a given Symbol and order direction, call the GetBuyingPower method.

var quantity = Portfolio.GetBuyingPower(_symbol, OrderDirection.Buy);
quantity = self.Portfolio.GetBuyingPower(self.symbol, OrderDirection.Buy)

For more information about buying power, see Buying Power.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: