First success without a Terminal
The authoritative first-success script lives at repository root in
examples/quickstart_no_terminal.py. Run it from a clone after installing
blpapi and bbg-fetch:
python examples/quickstart_no_terminal.py
Expected evidence
The script prints the Python, bbg-fetch, and blpapi versions, a
deterministic synthetic forward and rate, the number of strikes used, and this explicit
boundary:
Bloomberg connection: NOT TESTED
It exercises the public recover_option_forward function with a compact
synthetic option chain satisfying put-call parity. It does not open a session,
fetch licensed values, or write output to disk.
Authoritative script
The source below is included mechanically from the root example so the docs do
not maintain a second implementation.
1"""NO TERMINAL: verify installation with a deterministic public-API workflow."""
2
3import platform
4from enum import Enum
5from importlib.metadata import version
6
7import numpy as np
8import pandas as pd
9
10import bbg_fetch
11
12
13SPOT = 100.0
14FORWARD = 102.0
15RATE = 0.03
16YEAR_FRACTION = 0.25
17
18
19class Locals(Enum):
20 """Available terminal-free example workflows."""
21
22 QUICKSTART = 1
23
24
25def _synthetic_option_chain() -> pd.DataFrame:
26 """Create call/put prices satisfying put-call parity exactly."""
27 discount = np.exp(-RATE * YEAR_FRACTION)
28 rows = []
29 for strike in np.array([90.0, 95.0, 100.0, 105.0, 110.0]):
30 put = 12.0 + 0.02 * np.square(strike - SPOT)
31 call = put + discount * (FORWARD - strike)
32 rows.extend((
33 {"opt_put_call": "Call", "opt_strike_px": strike, "px_last": call},
34 {"opt_put_call": "Put", "opt_strike_px": strike, "px_last": put},
35 ))
36 return pd.DataFrame(rows)
37
38
39def run_local(local: Locals) -> None:
40 """Run the terminal-free installation and public-API check."""
41 if local != Locals.QUICKSTART:
42 raise NotImplementedError(f"unsupported local: {local}")
43 recovered = bbg_fetch.recover_option_forward(
44 option_chain=_synthetic_option_chain(),
45 spot=SPOT,
46 year_fraction=YEAR_FRACTION,
47 price_source=bbg_fetch.OptionPriceSource.LAST,
48 )
49
50 if not np.isclose(recovered["forward"], FORWARD, atol=1e-10):
51 raise RuntimeError(f"unexpected forward: {recovered['forward']}")
52 if not np.isclose(recovered["rate"], RATE, atol=1e-10):
53 raise RuntimeError(f"unexpected rate: {recovered['rate']}")
54
55 print("installation/API check: PASS")
56 print(
57 f"versions: python={platform.python_version()}; "
58 f"bbg-fetch={bbg_fetch.__version__}; blpapi={version('blpapi')}"
59 )
60 print(
61 f"synthetic forward={recovered['forward']:.2f}; "
62 f"rate={recovered['rate']:.2%}; "
63 f"strikes={int(recovered['num_strikes_used'])}"
64 )
65 print("Bloomberg connection: NOT TESTED")
66
67
68if __name__ == "__main__":
69 run_local(local=Locals.QUICKSTART)