i want build OptionStrategyDefinition by myself with python code implment
here is C# example code
/// <summary>
/// Strangle strategy consists of buying a call option and a put option with the same expiration date.
/// The strike price of the call is above the strike of the put.
/// </summary>
public static OptionStrategyDefinition Strangle { get; }
= OptionStrategyDefinition.Create("Strangle",
OptionStrategyDefinition.CallLeg(+1),
OptionStrategyDefinition.PutLeg(+1, (legs, p) => p.Strike <= legs[0].Strike,
(legs, p) => p.Expiration == legs[0].Expiration)
);
then python code will throw No method matches given arguments
from QuantConnect.Securities.Option.StrategyMatcher import *
OptionStrategyDefinition.CallLeg(1)
OptionStrategyDefinition.PutLeg(1, lambda legs, p: p.Expiration == legs[0].Expiration and p.Strike <= legs[0].Strike)
Varad Kabade
Hi Cool nemo,
The OptionStrategyDefinitions class contains helper methods that work both in C# and Python, so you don't need to recreate them in Python. If you want to, you will have to do it "old school" (select the contracts based on strike and expiration from a list of contract symbols). We cannot reuse that C# implementation since lambda expressions don't work out of the box when a method requires a C# Linq expression, a Func/Action, or method, we need to implement a method overload. E.g.:
where the second method will do the conversion from lambda Python to C# Func.
Best,
Varad Kabade
Cool nemo
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!