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.1.tar.gz (3.7 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.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nkutils-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 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.1.tar.gz
Algorithm Hash digest
SHA256 e47e4f192c05bba64b73abd191d79325a59e5d283fbf9c2bade58b0638406b61
MD5 44d7a035ea04ac7b35633f1929fac325
BLAKE2b-256 5062a909b3a6962a6c7cf40a5eed4c73c4465c8745b1f34b24cba409230f77b4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nkutils-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f365eac4f7386e8ab3670fc13d7e5fb11cc1faf05c800ceb119616ed233e0c17
MD5 9c4b96c0947d7beb817746a24cfcc279
BLAKE2b-256 0bd61a2952136c5c79c449ed71432690a1ccc5ce7d03ac7f9081d4313923ae70

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