addisonlynch / addisonlynch/pyTD

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

Offen
#6 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
12
Forks
12
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## 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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.