Skip to main content

Simple Utilities for reading from excel named ranges, forward rates and other minor tasks

Project description

Experimental package with some functions I found useful for automating frequently used tasks

The package is for illustration only - it is unlikely it will be updated. Or it may be replaced by a more comprehensive list of other packages.

It has the following functions:

  • read_named_range_to_dataframe(file_path, sheet_name, range_name, header=True)

    • reads data to a python dataframe from a named range in excel.
    • arguments are:
      • filepath: the name of the file, together with the path, if not in the working directory
      • sheet_name: self-explanatory
      • range_name: self-explanatory
      • header: defaults to True, which assumes the table/range has a label.
    • even if you put "A1:B5", the code should work. ,m,
    • it reads single cells as well as rectangular ranges.
    • It probably fails with ranges that are neither of the two above.
    • it works with .xlsx and .xlsm files. Does not work with .xlsb files for now.
  • forward_rate(rfr, t1,t2, comp="ann")

    • calculates the forward rate between two times
    • takes as inputs a list of spot rates and the two times between which the forward rate is to be calculated
    • the list is assumed to have rates at each year (so it assumes annual rates)
    • by default it assumes annual compounding. You can set comp = "cont" for continuous formula.
  • send2clipboard(A,colnames = ["datafrompython"])

    • used mainly while debugging jupyter notebook files;
    • A is usually a numpy array.
    • you can add a colnames argument that matches the number of columns of the array
    • no index is printed.
  • print_stats(myseries,percentiles = [0.01, 0.05, 0.25, 0.5, 0.75, 0.95, 0.99], colnames = None)

    • prints various statistics from the myseries data; the built-in describe function didnt do it for me!
    • myseries needs to be a numpy array with numerical data only; nan values will result in error
    • as well as the percentiles, it prints mean, st.dev, skewness, kurtosis, min and max
    • colnames need to have the right size, or it will result in an error. or you can leave empty
    • this is a crude stats function. a more sophisticated one will be published in due course.
  • align_to_schema(subdf: pd.DataFrame, maindf: pd.DataFrame)

    • produces a single dataframe with all columns of the main dataframe, maintaining their order.
    • it also adds any columns in the subdf that are not in the maindf
    • it makes sure there is no NaN data, by putting zeros or empty strings in the relevant columns
    • useful for combining a "base position" list of assets with a "buy list" which may have some fields that are not relevant in the base scenario (e.g. asset base MA or asset base FS)

If you have used the previous version, please note the forward rate calc was wrong - it is fixed now.

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

nkutils-0.1.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nkutils-0.1.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nkutils-0.1.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for nkutils-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7034585f2e5bd0b63733f6e006e1b670048ceea13e2533f55f2cb9046a0f89ad
MD5 d67f20e1c24046acfe6472ed51da4042
BLAKE2b-256 47d0e1590798644ea4173184efa11508f43bb2f7ea1bfd400fe059abce4dbdf0

See more details on using hashes here.

File details

Details for the file nkutils-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nkutils-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for nkutils-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e78d0c5fabb356518b68502a5f4226f5f7cc8ac140b5890901b878a5dde0757
MD5 c8f6a5092b41447bb5901f425e1b5f66
BLAKE2b-256 b0295f1ec49d40ddd44cb7b361fb842083541f26e189513e02d6e9d101b5bd05

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