Skip to main content

TD ONE: A Python Package for Banking and Pricing

Project description

pip install tdone

Top level coding, reading from the standard input, responding in the stdout with print()

from sys import stdin
from tdone.pricer import SimpleResponse

new_quote = SimpleResponse()

# Get quotation request details as json
request = stdin.read()
details = json.loads(request)

if details.legs is None or len(details.legs) == 0:
    new_quote.error("No legs found")
    print(new_quote)
    exit(1)

only_leg = details.legs[0]
if only_leg.notional is None:
    new_quote.error("No notional found")
    print(new_quote)
    exit(1)

notional = only_leg.notional

# Get market data
market_data = (1.0, 0.5, 0.25, 0.1, 0.05, 0.01)

# Calculate
if new_quote.value < 0:
    new_quote.error("Negative value")
else:
    new_quote.value = notional * avg(market_data)

print(new_quote)

One function for one model, reading the market data from real-time updates from RabbitMQ and returning values as a function

from tdone.pricer import InstrumentPricer, MissingDataException, CalculationError

class InterestLinkedProductPricer(InstrumentPricer):
    async def async_price(self, quotation_request, quote):
        only_leg = quotation_request.legs[0]

        # Get market data
        curve = self.marketdata.zero_rate_curve(only_leg.currency, quotation_request.value_date)
        if len(curve) == 0:
            quote.warning(f"{only_leg.currency} curve is missing. Defaulting to USD zero curve")
            curve = self.marketdata.zero_rate_curve("USD", quotation_request.value_date)
            # To stop the calculation, use `throw MissingDataException()``

        subsequent_zero_rate = None
        for zero_rate in curve:
            if zero_rate.maturity > only_leg.maturity:
                subsequent_zero_rate = zero_rate.rate
                break

        if subsequent_zero_rate is None:
            quote.error(f"No subsequent zero rate found for {only_leg.maturity}")
            throw MissingDataException()

        if subsequent_zero_rate == 0.0 or subsequent_zero_rate is 1.0:
            quote.error(f"Subsequent zero rate is {subsequent_zero_rate}")
            throw CalculationError()

        quote.value = 100.0 * only_leg.notional (1 + subsequent_zero_rate)
        return quote

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tdone-0.1.2.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file tdone-0.1.2.tar.gz.

File metadata

  • Download URL: tdone-0.1.2.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for tdone-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f3b320ef959fd10f1f746b2f9fb85f648a0b4c2dee115ac69bfefa70d1e59370
MD5 275a0aaca9bc14ccf174c7cbefe2b642
BLAKE2b-256 8456afba60396149c0b825a89ea0f5c52a73d3953947b925c3b2217ec6761f59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page