Learning QuantConnect - Part II: Portfolio, Security Holding & Cashbook (Python) π§¨ππ¨βπ
QuantConnect is a powerful open-source, cloud-based platform for algorithmic trading platform. It allows users to design, test, and deploy trading strategies across various financial markets including equities, FX, futures, options, and cryptocurrencies.
QuantConnect can be a bit of a beast when it comes to complexity. The thing is packed with features and, let's be real, wading through the docs can feel like trying to read hieroglyphics. So in this series I tried to break it down into bite-sized pieces that won't make your head hurt.
In this part we will take a look at the main concepts around the Securities class. In this post we will learn how to work with Portfolio, Holdings and Cashbook.
Suggested Reads:
This story is solely for general information purposes, and should not be relied upon for trading recommendations or financial advice. Source code and information is provided for educational purposes only, and should not be relied upon to make an investment decision. Please review my full cautionary guidance before continuing.
Portfolio
The Portfolio is a LEAN class that provides access to the complete state of your portfolio. It has quite a few member properties such as Positions, Cashbook, Holdings, Cash, Transactions, TotalFees, TotalProfit, etc.
Letβs see how we can work with this class:
Check available cash
Settled cash means cash available for trading where all trades and payments have completed versus βunsettled cashβ, which means that where transactions have not completed.
class TestAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetCash(100000)
...
def OnData(self, data: Slice):
cash = self.Portfolio.Cash
unsettled_cash = self.Portfolio.UnsettledCash
self.Log(f"All settled currencies in account in US dollars: {cash}")
self.Log(f"All unsettled currencies in account in US dollars: {unsettled_cash}")
output:
2024-01-03 00:00:00 : All settled currencies in account in US dollars: 100000.0
2024-01-03 00:00:00 : All unsettled currencies in account in US dollars: 0.0