minor refactor

cleaning the code
max_pain_deribit
Nelson Torres 2024-12-08 13:38:23 -03:00
parent 1ac643018a
commit 3526d5d564
1 changed files with 12 additions and 16 deletions

View File

@ -57,28 +57,25 @@ async def max_pain_daemon(
# an amount greater than zero.
total_intrinsic_value: Decimal = Decimal('Infinity')
max_pain: Decimal = Decimal(0)
call_cash: Decimal = Decimal(0)
put_cash: 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)
put_cash: Decimal = Decimal(0)
for close 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'])
closes: list = sorted(Decimal(close) for close in oi_by_strikes)
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] = {
'C': call_cash,
'P': put_cash,
'total': call_cash + put_cash,
}
for strike in intrinsic_values:
if intrinsic_values[f'{strike}']['total'] < total_intrinsic_value:
total_intrinsic_value = intrinsic_values[f'{strike}']['total']
max_pain = strike\
if intrinsic_values[strike]['total'] < total_intrinsic_value:
total_intrinsic_value = intrinsic_values[strike]['total']
max_pain = s
return {
'timestamp': timestamp,
@ -87,7 +84,6 @@ async def max_pain_daemon(
'max_pain': max_pain,
}
async with get_client(
) as client:
instruments = await client.get_instruments(