Skip to content

Instantly share code, notes, and snippets.

@tinybike
Created January 25, 2021 06:43
Show Gist options
  • Save tinybike/713b0ef66b252a6aa4564e7987870015 to your computer and use it in GitHub Desktop.
Save tinybike/713b0ef66b252a6aa4564e7987870015 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
noShowBondsThatActuallyDidntShowInPreviousWindow = 3
totalNoShowBondsInPreviousWindow = 4
repPrice = 21
targetDesignatedReportNoShowsDivisor = 20
initalReportMinValue = 0.7
noShowBond = 0.7
def calculateFloatingValue(_totalBad, _total, _targetDivisor, _previousValue, _floor):
if _total == 0:
return _previousValue
# Modify the amount based on the previous amount and the number of markets fitting the failure criteria.
# We want the amount to be somewhere in the range of 0.9 to 2 times its previous value where ALL markets
# with the condition results in 2x and 0 results in 0.9x.
if _totalBad <= _total / _targetDivisor:
# FXP formula: previous_amount * (actual_percent / (10 * target_percent) + 0.9)
_newValue = _totalBad * _previousValue * _targetDivisor
_newValue = _newValue / _total
_newValue = _newValue / 10
_newValue = _newValue + (_previousValue * 9 / 10)
else:
# FXP formula: previous_amount * ((1/(1 - target_percent)) * (actual_percent - target_percent) + 1)
_newValue = _targetDivisor * (_previousValue*_totalBad/_total - _previousValue/_targetDivisor)
_newValue = _newValue / (_targetDivisor - 1)
_newValue = _newValue + _previousValue
return max(_newValue, _floor)
for i in range(12):
noShowBond = calculateFloatingValue(noShowBondsThatActuallyDidntShowInPreviousWindow, totalNoShowBondsInPreviousWindow, targetDesignatedReportNoShowsDivisor, noShowBond, initalReportMinValue)
print("{}\t${}".format(noShowBond, noShowBond * repPrice))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment