addisonlynch / addisonlynch/pyTD

market.get_option_chains returns only one of the strikes when the output is set to df

Aperta
#6 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
12
Fork
12
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Summary (include Python version)
python 3.6
In options.py lines 134,139, the code iterates over the strikes, but, always overwrites the value of previous strike. The code is:
```
for strike in out['callExpDateMap'][date]:
ret[date] = (out['callExpDateMap'][date][strike])[0]

```
I.e., you overwrite the ret[dict] in the subsequent iteration. I tried to change the dict entry to an array, i.e.,
```

strikes = []
for strike in out['callExpDateMap'][date]:
strikes.append((out['callExpDateMap'][date][strike])[0])
ret[date] = strikes

```
But, since the length of array is different for different dates, pandas throws an exception:
```

raise ValueError('arrays must all be same length')
ValueError: arrays must all be same length

```
I.e., either you pad the arrays so that all have the same length, or, just get the JSON. For now, I have decided to use the json output.
### Date/time of issue
June 4, 2020

### Expected behavior
have all the strikes in results

### Actual behavior
only one strike per day

Regards,
Behdad

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.