parent
1ac643018a
commit
3526d5d564
28
max_pain.py
28
max_pain.py
|
@ -57,28 +57,25 @@ async def max_pain_daemon(
|
||||||
# an amount greater than zero.
|
# an amount greater than zero.
|
||||||
total_intrinsic_value: Decimal = Decimal('Infinity')
|
total_intrinsic_value: Decimal = Decimal('Infinity')
|
||||||
max_pain: Decimal = Decimal(0)
|
max_pain: Decimal = Decimal(0)
|
||||||
|
call_cash: Decimal = Decimal(0)
|
||||||
|
put_cash: Decimal = Decimal(0)
|
||||||
intrinsic_values: dict[str, dict[str, Decimal]] = {}
|
intrinsic_values: dict[str, dict[str, Decimal]] = {}
|
||||||
closes: list[str] = sorted(oi_by_strikes.keys())
|
closes: list = sorted(Decimal(close) for close in oi_by_strikes)
|
||||||
for strike in oi_by_strikes:
|
|
||||||
s: Decimal = Decimal(f'{strike}')
|
for strike, oi in oi_by_strikes.items():
|
||||||
call_cash: Decimal = Decimal(0)
|
s = Decimal(strike)
|
||||||
put_cash: Decimal = Decimal(0)
|
call_cash = sum(max(0, (s - c) * oi_by_strikes[str(c)]['C']) for c in closes)
|
||||||
for close in closes:
|
put_cash = sum(max(0, (c - s) * oi_by_strikes[str(c)]['P']) for c in closes)
|
||||||
c: Decimal = Decimal(f'{close}')
|
|
||||||
call_cash += max(0, (s - c) * oi_by_strikes[f'{close}']['C'])
|
|
||||||
put_cash += max(0, (c - s) * oi_by_strikes[f'{close}']['P'])
|
|
||||||
|
|
||||||
intrinsic_values[strike] = {
|
intrinsic_values[strike] = {
|
||||||
'C': call_cash,
|
'C': call_cash,
|
||||||
'P': put_cash,
|
'P': put_cash,
|
||||||
'total': call_cash + put_cash,
|
'total': call_cash + put_cash,
|
||||||
}
|
}
|
||||||
|
|
||||||
for strike in intrinsic_values:
|
if intrinsic_values[strike]['total'] < total_intrinsic_value:
|
||||||
if intrinsic_values[f'{strike}']['total'] < total_intrinsic_value:
|
total_intrinsic_value = intrinsic_values[strike]['total']
|
||||||
total_intrinsic_value = intrinsic_values[f'{strike}']['total']
|
max_pain = s
|
||||||
max_pain = strike\
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
|
@ -87,7 +84,6 @@ async def max_pain_daemon(
|
||||||
'max_pain': max_pain,
|
'max_pain': max_pain,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async with get_client(
|
async with get_client(
|
||||||
) as client:
|
) as client:
|
||||||
instruments = await client.get_instruments(
|
instruments = await client.get_instruments(
|
||||||
|
|
Loading…
Reference in New Issue