Options trading questions

Posted By: Zheka

Options trading questions - 09/04/18 18:04

JCL,

there are several classes of FX options having the same expiry date, some are illiquid or not desirable for trading for some other reason.
However,contractUpdate() gets everything and selecting a contract via standard contract functions sometimes gets such an "undesirable" contract.

I am exploring 2 approaches: 1)"pruning" the received contract chain, getting rid of unnecessary lines or
- preferably- 2)creating own 'mini-chain' from the very beginning.

So, questions:
for 1) - how to access the first field - which in [Trade] mode contains "class" (a string, rather than time).
- will it be possible to set Expiry of selected structs to zero, or Contracts is a "read-only" list?
- can you implement a way to trim such live contract chain based on class and strikes?

for 2)
- can you enable loading/using a user-supplied chain dataset in [Trade] mode, like it is done in [Test] mode?
- how to properly fill in the Contract struct to pass to the contractPrice() to request a price update for an arbitrary, user-defined contract?

Thank you.
Posted By: jcl

Re: Options trading questions - 09/05/18 06:52

You can get a pointer to the whole chain with the Contracts pointer, and this way evaluate the class and reset the PUT/CALL flags on wrong classes. The class string of a contract pointer C is simply (string)C. For loading a chain from a file while live trading, use dataLoad(). The .t8 file has the same structure as a dataset with 9 fields.
Posted By: Zheka

Re: Options trading questions - 09/05/18 07:34

OK. But please give some more details on the first field:
it is of DATE type in a Contract structure, but somehow is a string in a downloaded chain (which is supposedly a dataset/list of Contract structs...

How do I access the class? c->xxx?
Posted By: Zheka

Re: Options trading questions - 09/05/18 08:11

Thank you! (string)C works with the downloaded chain.
How do you recommend to reset PUT/CALL flags?
Why is preferable to setting Expiry to 0?
I then thought of sorting the Contracts list and cutting the unnecessary lines altogether by setting NumContracts to a smaller value..Is this at all possible?

Is the class just typecasted to/from double? I.e. a dataset will need to have the first column saved as e.g.(double)Class (where Class is a string)?
And when such Contract* C is passed to contractPrice(C) it is automatically assumed to contain class in its first field?
Posted By: Zheka

Re: Options trading questions - 09/05/18 12:48

Trading a portfolio of options/expirations, it is needed to have a futures chain alongside the options chain.

What's the recommended way to maintain both, usable by the standard contract() functions?
Posted By: jcl

Re: Options trading questions - 09/05/18 13:44

The probably simplest method is splitting the asset in two, one for the options and one for the futures.

Sorting and reducing the contracts list should work, although I haven't tested it - just try. For resetting PUT and CALL, simply set C->Type=0. Expiry=0 will probably also work. Class and timestamp are a union of the same struct element. In live trading it's the class, in the backtest it's the timestamp.
Posted By: Zheka

Re: Options trading questions - 09/05/18 16:43

I am trying to get the option chain to a dataset before trimming as needed.
Quote:
string Format="s,sss8,i7,f6,f5,f1,f2,f3,f4";
char* exClass="EU";
CONTRACTS* C;

for (ii=0;ii<NumContracts;ii++)
{
C=Contracts+ii;

if (strstr((string)C,exClass))
contractPrint(C,TO_CSV);
}

dataParse(2,Format,"C:ZorroLogTradeOptions.csv");

file_delete("C:ZorroLogTradeOptions.csv");

ii=0;

while(C = dataStr(2,ii++,0))
contractPrint(C,TO_CSV);

All good except for one character lost in the class string.
Quote:
Downloading chain..
!Get Future Option Chain EUR-FOP--0----USD
Chain of 3044 EUR contracts
3044 contracts
Parse C:ZorroLogTradeOptions.csv..
EUU,FutureCall,20180907,1.1650,0.0000,0.0000,0.0000,125000,0
EU FutureCall 20180907 1.16500 0.00000 0.00000 0.00000 125000.00000 0.00000


And then the last contractPrint() prints nothing for the class at all.
Why would this happen? The manual states "s" parses a 3-character text field, and as you can see this is the case.

Is there a more elegant way of getting from Contracts to a dataset?
Given that formation of a more relevant contracts set is a typical step, it might make sense to store the retrieved option chain as a dataset (rather then an internal list of structs), seamlessly with [Test] mode.
contractUpdate() would then just return a handle to such dataset.
And both contract() and dataset functions will be available at once.
Posted By: Zheka

Re: Options trading questions - 09/05/18 17:26

contractPrice() does not seem to work.

Quote:
C=contract(CALL,2,priceClose());

print(TO_WINDOW,"n Future price=%f",contractPrice(C));
contractPrint(C,TO_WINDOW);

produces this output:
Quote:
NY Time: 13:19
Downloading chain..
!Get Future Option Chain EUR-FOP--0----USD
Chain of 3044 EUR contracts
3044 contracts
!EUR-FOP-20180907-1.16-C-GLOBEX: 0.00000 0.00000 0
Future price=0.000000
EUU,FutureCall,20180907,1.1650,1.1641,0.0000,0.0000,125000,0
V 1.883 on Wed 18-09-05 13:18:38
EUR 1.16406 0.00005 0.000 0.000 0.00010 0.00010 0.0200 125000.0 285312.0

Trade: TradeOptions EUR 2018-09-05
Assets AssetsIB

[1: Wed 18-09-05 17:19] 1.1641/1.16411.1640/1.1641 -0.000050000
Future price=0.000000
EUU,FutureCall,20180907,1.1650,1.1641,0.0000,0.0000,125000,0

The price of an underlying is updated (but not returned), neither are bid-ask for the option.
Posted By: Zheka

Re: Options trading questions - 09/17/18 18:53

JCL,

will appreciate your attention to get this resolved.

Thank you.
Posted By: jcl

Re: Options trading questions - 09/18/18 15:52

What resolved? We got a bug report about that, I suppose from you, but could not confirm that problem. You can only trade options when you got the needed IB account permissions and subscribed the needed market data - then all is fine. If you have another problem, just give details.
Posted By: Zheka

Re: Options trading questions - 09/18/18 16:23

Yes, I got a message on that from support after posting the reminder above. And with v 1.88.5 somehow contractPrice() got live pricing data correctly.
With 1.88.3 - as should be clear from my message - I could obtain EUR option chain and some prices.
Posted By: jcl

Re: Options trading questions - 09/18/18 16:43

The only change of the IB plugin between 1.88 and 1.83 was with the SET_PRICETYPE broker command, so maybe your options had a different price type, although I have not yet heard about such an issue. Anyway, glad that the problem disappeared.
Posted By: Zheka

Re: Options trading questions - 09/24/18 14:40

Quote:
For loading a chain from a file while live trading, use dataLoad()

JCL,
HAving loaded a custom chain with dataLoad(), I would like to use standard contract() search functions for looking up a desired contract.
However, doing
Quote:
Contracts = (CONTRACT*) dataStr(2,0,0); //with or without typecast
C=contract(CALL,3,priceClose());
print(TO_WINDOW,"n Option price=%f",contractPrice(C));
generates:
Quote:
Error 016: Invalid date 0

Is there a workaround?
Or would it be possible to add handle as input to all contract() functions?
Posted By: jcl

Re: Options trading questions - 09/24/18 14:49

Was this while live trading, or in backtest mode? If in backtest, check the dates of the contracts - maybe a date is really wrong.
Posted By: Zheka

Re: Options trading questions - 09/24/18 15:11

This is in Trade mode following contract chain 'trimming':
Quote:
for (ii=0;ii<NumContracts;ii++)
{
C=Contracts+ii;

if (strstr((string)C,incClass))
contractPrint(C,TO_CSV);
}

int sNumContracts=dataParse(2,Format,"C:ZorroLogEA_TradeOptions.csv");
Posted By: Zheka

Re: Options trading questions - 09/25/18 15:36

I got this to (somewhat) work. The problem has been that contractPrint() exported a text field and i parsed it as such, while proper CONTRACT struct needs an int in this place.

So, the trick with assigning a ptr to the dataset to Contracts works.

However,
Quote:
C=contract(CALL,3,priceClose())

still generates
Quote:
Error 016: Invalid date 0

And then selects some arbitrary contract strike.

Does contract() make any assumption on the order of expiries (or something else) in the option chain?
Posted By: jcl

Re: Options trading questions - 09/26/18 07:17

No, but the error is probably not about expiration, but about the first field, which is a union of a date in historical data and a text string in live data. Check that field.
Posted By: Zheka

Re: Options trading questions - 10/05/18 13:34

JCL,

I have a problem with obtaining a contractPrice() in Trade Mode for a correctly selected Contract - when I load a chain from a dataset, rather then when using a contractUpdate().
(actually, occasionally also when i DO use contractUpdate()).

The difference between cases when it works and when it doesn't comes down to this.

Quote:
BrokerAsset ??? - FOP-20181109-1.16-C-GLOBEX: : 0.0000 0.004145 ms
BrokerAsset EUR-FOP-20181109-1.16-C-GLOBEX: : 0.0118 6983.145685 ms
i.e. the underlying "string" is not recognized ("EUR" is dropped from the symbol string).

I of course do call asset ("EUR") before contractUpdate() and contractPrice().

I got this reply from support:
Quote:
the part "EUR" of the contract symbol is stored by contractUpdate(). asset() is for selecting an asset, not for storing a contract symbol. Since the "EUR" is sometimes missing in your symbol, we suspect that the first argument to the previous contractUpdate call was wrong. For testing that, please print the first argument of contractUpdate() to the log. If it turns out that "EUR" was correctly set but is still missing in the symbol, then we have to look elsewhere.

To which I have 2 questions:

1) Which variable in an Asset struct - or anywhere else - that holds this value - and so could be set?

- I thought this should be taken by Zorro from the very first part of the SYMBOL string.

2) Is it possible at all to NOT call contractUpdate() in a script?

Answer from support suggests it is not possible, but you earlier wrote that it is indeed possible to load a chain from a file.

I think it should be made possible.
Posted By: jcl

Re: Options trading questions - 10/05/18 14:47

I don't know the symbol variable, but know that you can load the chain by script from a file, because some users did that too. But in live trading you must always call contractUpdate even when you load the chain otherwise. In the backtest it is probably not necessary.
© 2024 lite-C Forums