parent
1ac643018a
commit
3526d5d564
24
max_pain.py
24
max_pain.py
|
@ -57,17 +57,15 @@ 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)
|
||||||
|
|
||||||
intrinsic_values: dict[str, dict[str, Decimal]] = {}
|
|
||||||
closes: list[str] = sorted(oi_by_strikes.keys())
|
|
||||||
for strike in oi_by_strikes:
|
|
||||||
s: Decimal = Decimal(f'{strike}')
|
|
||||||
call_cash: Decimal = Decimal(0)
|
call_cash: Decimal = Decimal(0)
|
||||||
put_cash: Decimal = Decimal(0)
|
put_cash: Decimal = Decimal(0)
|
||||||
for close in closes:
|
intrinsic_values: dict[str, dict[str, Decimal]] = {}
|
||||||
c: Decimal = Decimal(f'{close}')
|
closes: list = sorted(Decimal(close) for close in oi_by_strikes)
|
||||||
call_cash += max(0, (s - c) * oi_by_strikes[f'{close}']['C'])
|
|
||||||
put_cash += max(0, (c - s) * oi_by_strikes[f'{close}']['P'])
|
for strike, oi in oi_by_strikes.items():
|
||||||
|
s = Decimal(strike)
|
||||||
|
call_cash = sum(max(0, (s - c) * oi_by_strikes[str(c)]['C']) for c in closes)
|
||||||
|
put_cash = sum(max(0, (c - s) * oi_by_strikes[str(c)]['P']) for c in closes)
|
||||||
|
|
||||||
intrinsic_values[strike] = {
|
intrinsic_values[strike] = {
|
||||||
'C': call_cash,
|
'C': call_cash,
|
||||||
|
@ -75,10 +73,9 @@ async def max_pain_daemon(
|
||||||
'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