Skip to content

Commit f000b4b

Browse files
committed
Adds Pre-Trade Risk Control
1 parent 5310964 commit f000b4b

File tree

261 files changed

+204
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+204
-167
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>LEAN performs pre-order checks to ensure that the order meets some requirements to ensure that the order is valid and can be executed. These checks are include risk controls such as validation of order size and price limits, and whether the order can be executed by a given brokerage at a given time.</p>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<p>Orders undergo basic validation checks to ensure they meet certain criteria before being submitted. The following list outlines some of the key checks performed:</p>
2+
<ol>
3+
<li><strong>Security:</strong> Ensures that your algorithm has a valid data subscription for the security and receives its market data.</li>
4+
<p>Your algorithm cannot place an order for SPY if it hasn't added it via <code class="csharp">AddEquity("SPY")</code><code class="csharp">self.add_equity("SPY")</code> or universe selection.</p>
5+
<li><strong>Tradable:</strong> Ensures that the security is tradable or in the market.</li>
6+
<p>Your algorithm cannot place orders for <a href="/docs/v2/writing-algorithms/securities/asset-classes/index">indices</a>, delisted securities, expired contracts, or any assets removed from your universe. For example, the option filter or universe selection removed a contract because it doesn't meet the criteria set by the filter.</p>
7+
<li><strong>Market Hours:</strong> Checks that the order can be placed at the current time.</li>
8+
<p>For example, market orders cannot be placed outside of regular trading hours. LEAN converts market orders to market-on-open orders if possible.</p>
9+
<li><strong>Price:</strong> Checks that the last known price is not zero.</li>
10+
<p>LEAN requires the last known price for <a href="/docs/v2/writing-algorithms/trading-and-orders/pre-trade-risk-control#04-Buying-Power">buying power calculations</a>.</p>
11+
<li><strong>Order Size:</strong> Ensures that the order quantity is not zero or less than the lot size.</li>
12+
</ol>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>QuantConnect supports <a href="/docs/v2/writing-algorithms/trading-and-orders/order-types">several order types</a>. To see the requirements of each order, see the <span class='page-section-name'>Requirements</span> section of <a href='/docs/v2/writing-algorithms/trading-and-orders/key-concepts#03-Order-Types'>the documentation for the order types</a>. LEAN doesn't allow placing orders that don't meet these requirements. For example, your algorithm cannot place a <a href="/docs/v2/writing-algorithms/trading-and-orders/order-types/market-on-close-orders#08-Requirements">market-on-close</a> order from cryto-currencies because they operate 24/7.</p>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>When you place an order, LEAN uses the <a href="/docs/v2/writing-algorithms/reality-modeling/buying-power">buying power model</a> to determine whether the order should be submitted so you avoid placing orders that would be rejected by the brokerage. Buying power calculations can be very complex and depend on many factors, including the brokerage or even the time of day. The main factors include your current portfolio holdings, available cash, and margin requirements.</p>
2+
3+
<p>The buying power calculations are restricted to portfolio your algorithm is connected to. QuantConnect doesn't support multi-account risk controls.</p>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<p>QuantConnect supports <a href="/docs/v2/cloud-platform/live-trading/brokerages">several brokerages</a>. Each brokerage trades different asset classes and support different order types. LEAN doesn't allow placing orders that don't meet these requirements. For example, your algorithm cannot place a <a href="/docs/v2/writing-algorithms/trading-and-orders/order-types/trailing-stop-orders#07-Brokerage-Support">trailing stop</a> order for most brokerages.
2+
3+
<p>By default, LEAN uses the <a href="/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/quantconnect-paper-trading">default brokerage model</a> that suports all order types and all asset classes. To avoid issues with unsupported order types and asset classes when live trading, <a href='/docs/v2/writing-algorithms/initialization#05-Set-Brokerage-and-Cash-Model'>set the brokerage model</a> to a brokerage that supports them.</p>
4+
5+
<div class='section-example-container'>
6+
<pre class='csharp'>SetBrokerageModel(BrokerageName.TradeStation);</pre>
7+
<pre class='python'>self.set_brokerage_model(BrokerageName.TRADE_STATION)</pre>
8+
</div>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "metadata",
3+
"values": {
4+
"description": "LEAN performs pre-order checks to ensure that the order meets some requirements to ensure that the order is valid and can be executed.",
5+
"keywords": "trading orders, order types, order validation, risk control, brokerage connections",
6+
"og:description": "LEAN performs pre-order checks to ensure that the order meets some requirements to ensure that the order is valid and can be executed.",
7+
"og:title": "Pre-trade Risk Control - Documentation QuantConnect.com",
8+
"og:type": "website",
9+
"og:site_name": "Pre-trade Risk Control - QuantConnect.com",
10+
"og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/trading-and-orders/pre-trade-risk-control.png"
11+
}
12+
}

03 Writing Algorithms/22 Trading and Orders/04 Position Sizing/01 Introduction.html renamed to 03 Writing Algorithms/22 Trading and Orders/05 Position Sizing/01 Introduction.html

File renamed without changes.

03 Writing Algorithms/22 Trading and Orders/04 Position Sizing/02 Single Asset Targets.html renamed to 03 Writing Algorithms/22 Trading and Orders/05 Position Sizing/02 Single Asset Targets.html

File renamed without changes.

03 Writing Algorithms/22 Trading and Orders/04 Position Sizing/03 Multiple Asset Targets.html renamed to 03 Writing Algorithms/22 Trading and Orders/05 Position Sizing/03 Multiple Asset Targets.html

File renamed without changes.

03 Writing Algorithms/22 Trading and Orders/04 Position Sizing/04 Asynchronous Orders.php renamed to 03 Writing Algorithms/22 Trading and Orders/05 Position Sizing/04 Asynchronous Orders.php

File renamed without changes.

0 commit comments

Comments
 (0)