asdf
This commit is contained in:
1 parent
15aa6397e8
commit
28bfd7ea81
7 files changed
+4144
-25
No files matched your search
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Price check (free, downloads nothing): CME options-on-futures data needed to estimate dealer gamma.
|
||||
Two schemas per product: 'statistics' (daily open interest + settlement prices) and 'definition'
|
||||
(strike, expiry, call/put of every option). Same API key setup as get_futures_1m.py.
|
||||
|
||||
export DATABENTO_API_KEY=db-xxxxxxxxxxxxxxxx
|
||||
python3 options_cost.py # NQ, ES, gold, crude options, 2016 -> latest
|
||||
python3 options_cost.py --parents NQ.OPT --start 2020-01-01
|
||||
"""
|
||||
import argparse, os, sys
|
||||
import databento as db
|
||||
import pandas as pd
|
||||
|
||||
DATASET = "GLBX.MDP3"
|
||||
# CME option product codes: NQ / ES equity index options, OG = gold (COMEX), LO = crude (NYMEX)
|
||||
DEFAULT = ["NQ.OPT", "ES.OPT", "OG.OPT", "LO.OPT"]
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("--parents", nargs="+", default=DEFAULT)
|
||||
p.add_argument("--schemas", nargs="+", default=["statistics", "definition"])
|
||||
p.add_argument("--start", default="2016-01-01")
|
||||
p.add_argument("--end", default=None)
|
||||
a = p.parse_args()
|
||||
|
||||
key = os.environ.get("DATABENTO_API_KEY")
|
||||
if not key:
|
||||
sys.exit("Set DATABENTO_API_KEY first.")
|
||||
client = db.Historical(key)
|
||||
end = a.end
|
||||
if end is None:
|
||||
rng = client.metadata.get_dataset_range(dataset=DATASET)
|
||||
end = rng["end"]
|
||||
end = pd.Timestamp(end); end = end.tz_localize("UTC") if end.tzinfo is None else end.tz_convert("UTC")
|
||||
start = pd.Timestamp(a.start, tz="UTC")
|
||||
print(f"Range {start.date()} -> {end.date()} (cost estimates only, nothing is downloaded or billed)\n")
|
||||
grand = 0.0
|
||||
for par in a.parents:
|
||||
for sch in a.schemas:
|
||||
params = dict(dataset=DATASET, schema=sch, stype_in="parent", symbols=[par], start=start.isoformat(), end=end.isoformat())
|
||||
try:
|
||||
cost = client.metadata.get_cost(**params)
|
||||
size = client.metadata.get_billable_size(**params)
|
||||
n = client.metadata.get_record_count(**params)
|
||||
grand += cost
|
||||
print(f"{par:8s} {sch:11s} ${cost:9.2f} {size / 1e9:7.2f} GB {n:,} records")
|
||||
except Exception as e:
|
||||
print(f"{par:8s} {sch:11s} error: {e}")
|
||||
print(f"\nTotal estimate: ${grand:,.2f}")
|
||||
Reference in new issue
Block a user