question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't Maximize Position Size of OptionStrategies

See original GitHub issue

Expected Behavior

We can place an order with OptionStrategies to maximize the position size (minimize the amount of margin remaining).

Actual Behavior

When we try to maximize the position size of OptionStrategies, we receive the error

Order Error: id: 1, Insufficient buying power to complete order

Related issue: #2709 Related thread: Examples of how to use OptionStrategyPositionGroupBuyingPowerModel?

Potential Solution

Fix the bug in the OptionStrategyPositionGroupBuyingPowerModel. None of the examples in the repo using OptionStrategies maximize the position size. They all use a small order size of <= 10. We need more unit tests to cover the case of attaining the maximum position size.

Reproducing the Problem

Run this backtest.

When placing a single order for the BullPutSpread, with self.Order(strategy, 54) # Works in interval [1, 54] the orders go through without error but we have $7,111 of $10K margin remaining. Increasing the order size to 55 throws the error.

Additionally, when placing the orders incrementally with

for i in range(64): # Works in interval [1, 64]
    self.Order(strategy, 1)

we can achieve a larger position size but we have $6,480 of $10K margin remaining. Increasing the range to range(65) throws the error.

System Information

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DerekMelchincommented, Jan 12, 2023

It would be nice to have something like

self.SetHoldings(option_strategy, 1)

so we can maximize the position size.

0reactions
Martin-Molinerocommented, May 22, 2023

The underlying bug here was solved, opening new feature request to add missing sugar syntax for option strategies https://github.com/QuantConnect/Lean/issues/7261.

Read more comments on GitHub >

github_iconTop Results From Across the Web

10 Options Strategies Every Investor Should Know
There are many options strategies that both limit risk and maximize return. With a little effort, traders can learn how to take advantage...
Read more >
Wanna Trade Big? How and When to Increase Your Positi...
Maximize your trading effectiveness by knowing when and how to vary position sizes--without skipping sound risk management.
Read more >
How to Increase Position Size The Right Way
Increasing position size too quickly leads to anxiety-related trading problems. Learn to push through barriers to increase profits and position size.
Read more >
7 common options trading mistakes to avoid
Mistake #3: Choosing the wrong position size​​ Most position sizing errors stem from 2 common emotions: fear or greed. If you are greedy...
Read more >
What to Know About Proper Position Sizing when Trading
To determine position sizing you must first set a firm stop level. As a rule of thumb, a trader should not risk more...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found