sgfixedincome_pkg.analysis

Functions

filter_df(combined_df[, investment_amount, ...])

Filters the combined_df based on provided criteria, including investment amount, tenure, rate,

best_returns(combined_df, investment_amount[, ...])

Calculate the highest total dollar return achievable for each possible tenure,

best_rates(combined_df, investment_amount[, ...])

Display the highest rates offered for each possible tenure given an investment amount.

products(combined_df)

Returns a list of unique products in the dataset by joining the 'Product provider' and 'Product' columns.

plot_rates_vs_tenure(df, investment_amount[, ...])

Plots a graph of Rate (% p.a.) vs Tenure (in months) for a given investment amount

plot_best_rates(df, investment_amount[, min_tenure, ...])

Plot of best rates (% p.a.) for each tenure for a given investment amount, across

plot_bank_offerings_with_fuzz(df, product_provider[, ...])

Plots a graph of Rate (% p.a.) vs Tenure (in months) for a given bank, where each line represents a

better_allocation(df, investment_amount, tenure)

Returns a better strategy to improve effective rate by allocating investment across

plot_better_allocation_strategy(df, investment_amount)

Plot the Rate (% p.a.) against Tenure (Months) for the better allocation strategy

plot_pure_and_better_allocation_strategy_rates(df, ...)

Overlay plot for best rates (% p.a.) and effective better allocation strategy rates for each tenure.

Module Contents

sgfixedincome_pkg.analysis.filter_df(combined_df, investment_amount=None, min_tenure=0, max_tenure=999, min_rate=None, consider_tbills=True, consider_ssbs=True, consider_fd=True, include_providers=None, exclude_providers=None)[source]

Filters the combined_df based on provided criteria, including investment amount, tenure, rate, product provider, product, and whether to consider T-bills and SSBs.

Parameters:
  • combined_df (pd.DataFrame) – DataFrame containing columns ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Required multiples’, ‘Product provider’, ‘Product’.

  • investment_amount (float, optional) – The investment amount to filter available rates and products for that amount.

  • min_tenure (int, optional) – The minimum tenure (in months) to filter. Default is 0.

  • max_tenure (int, optional) – The maximum tenure (in months) to filter. Default is 999.

  • min_rate (float, optional) – The minimum rate (% p.a.) to filter. Default is None (no filtering).

  • consider_tbills (bool, optional) – Whether to consider T-bills. Default is True.

  • consider_ssbs (bool, optional) – Whether to consider SSBs. Default is True.

  • consider_fd (bool, optional) – Whether to consider fixed deposits. Default is True.

  • include_providers (list, optional) – Exclusive list of providers to include. Default is None.

  • exclude_providers (list, optional) – List of providers to exclude. Default is None.

Returns:

The filtered DataFrame based on the provided criteria.

Return type:

pd.DataFrame

sgfixedincome_pkg.analysis.best_returns(combined_df, investment_amount, min_tenure=0, max_tenure=999)[source]

Calculate the highest total dollar return achievable for each possible tenure, considering that the offered rates and available products differ across invested amounts.

This function assumes you only can select one product to invest in, and finds the highest dollar return attainable for each tenure. For products which only accept investment in specific multiples, we allocate the maximum amount of investment to them given the investment amount, and assume the remaining cash earns no return.

As such, for each tenure, the product delivering the best return (our concern here) may differ from the product with the highest rates. For example, product ‘A’ with a higher rate but which has required multiples of investment may produce lower total dollar return compared to product ‘B’ with a lower rate but no required multiples, as the full amount of cash cannot be invested in product ‘A’ but can be fully invested into product ‘B’.

Parameters:
  • combined_df (pd.DataFrame) – DataFrame containing columns ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Required multiples’, ‘Product provider’, ‘Product’.

  • investment_amount (float) – The investment amount to filter available rates and products for that amount.

  • min_tenure (int, optional) – The minimum tenure (in months) to consider. Default is 0.

  • max_tenure (int, optional) – The maximum tenure (in months) to consider. Default is 999.

Returns:

A DataFrame with products that deliver the highest dollar return for each tenure, product details, and total dollar return from the investment.

Return type:

pd.DataFrame

sgfixedincome_pkg.analysis.best_rates(combined_df, investment_amount, min_tenure=0, max_tenure=999)[source]

Display the highest rates offered for each possible tenure given an investment amount.

Parameters:
  • combined_df (pd.DataFrame) – DataFrame containing columns ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Required multiples’, ‘Product provider’, ‘Product’.

  • investment_amount (float) – The investment amount to filter available rates and products for that amount.

  • min_tenure (int, optional) – The minimum tenure (in months) to consider. Default is 0.

  • max_tenure (int, optional) – The maximum tenure (in months) to consider. Default is 999.

Returns:

A DataFrame with the products offering the best rate (in % p.a.) for each tenure.

Return type:

pd.DataFrame

sgfixedincome_pkg.analysis.products(combined_df)[source]

Returns a list of unique products in the dataset by joining the ‘Product provider’ and ‘Product’ columns. It considers unique combinations of these joined strings.

Parameters:

combined_df (pd.DataFrame) – DataFrame containing the columns ‘Product provider’ and ‘Product’.

Returns:

A list of unique product combinations in the format ‘Product provider - Product’.

Return type:

list

sgfixedincome_pkg.analysis.plot_rates_vs_tenure(df, investment_amount, min_tenure=0, max_tenure=999)[source]

Plots a graph of Rate (% p.a.) vs Tenure (in months) for a given investment amount with optional filtering by tenure range. Each unique ‘Product provider - Product’ pair is plotted as a separate line.

Parameters:
  • df (pd.DataFrame) – DataFrame containing the data to plot. Must include columns: ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Product provider’, ‘Product’.

  • investment_amount (float) – The investment amount to filter rows for the plot.

  • min_tenure (int, optional) – Minimum tenure (in months) to include. Default is 0.

  • max_tenure (int or float, optional) – Maximum tenure (in months) to include. Default is 999.

Raises:

ValueError – If no valid rows remain after filtering based on the investment amount and tenure.

sgfixedincome_pkg.analysis.plot_best_rates(df, investment_amount, min_tenure=0, max_tenure=999)[source]

Plot of best rates (% p.a.) for each tenure for a given investment amount, across available products. The plot color-codes the points by provider-product pair.

Parameters:
  • df (pd.DataFrame) – DataFrame containing columns ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Required multiples’, ‘Product provider’, ‘Product’.

  • investment_amount (float) – The investment amount to filter available rates and products for that amount and to calculate the total return.

  • min_tenure (int, optional) – The minimum tenure (in months) to consider. Default is 0.

  • max_tenure (int, optional) – The maximum tenure (in months) to consider. Default is 999.

sgfixedincome_pkg.analysis.plot_bank_offerings_with_fuzz(df, product_provider, fuzz_factor=0.02)[source]

Plots a graph of Rate (% p.a.) vs Tenure (in months) for a given bank, where each line represents a different deposit range (created by joining ‘Deposit lower bound’ and ‘Deposit upper bound’). Adds small fuzz to the points to avoid overlap.

Parameters:
  • df (pd.DataFrame) – DataFrame containing columns ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Product provider’.

  • product_provider (str) – The bank name (Product provider) to filter the data for.

  • fuzz_factor (float, optional) – The amount of fuzz (random noise) to add to the points. Default is 0.02.

Raises:

ValueError – If no data is available for the given product_provider.

sgfixedincome_pkg.analysis.better_allocation(df, investment_amount, tenure)[source]

Returns a better strategy to improve effective rate by allocating investment across different products.

Strategy:

  1. First sorts all available products by interest rate in descending order

  2. For each provider-product pair, only allows investment in one deposit range (the one with highest rate that we can afford given remaining funds)

  3. Allocates maximum possible amount to each product while respecting: deposit range bounds (lower and upper limits), required multiples (if any), and available remaining investment amount

  4. Continues allocation until either the entire investment amount is allocated, or no more valid products are available

Note that while this strategy often produces returns at least as good as investing in any single product, it may sometimes produce lower returns, and may also be different from the globally optimal allocation. For example, consider the case where we ‘use up’ a provider-product pair by allocating the full amount to a low deposit range with high rates, and because of that forfeit the ability to invest in the same provider-product at a higher deposit range but a slightly lower rate. The overall return may be higher by allocating more to a slightly lower rate deposit range.

Parameters:
  • df (pd.DataFrame) – DataFrame containing ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Product provider’, ‘Product’.

  • investment_amount (float) – The total investment amount to allocate across different products.

  • tenure (int) – The tenure in months for the investment.

Returns:

A DataFrame containing:

  • Product provider: Provider offering the product

  • Product: Type of investment product

  • Allocated amount: Amount invested in this product

  • Rate (% p.a.): Annual interest rate as percentage

  • Expected return ($): Expected dollar return from this allocation

Plus a summary row with totals and effective overall rate

Return type:

pd.DataFrame

sgfixedincome_pkg.analysis.plot_better_allocation_strategy(df, investment_amount, min_tenure=0, max_tenure=999)[source]

Plot the Rate (% p.a.) against Tenure (Months) for the better allocation strategy across all tenures available in the dataframe.

Parameters:
  • df (pd.DataFrame) – DataFrame containing ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Product provider’, ‘Product’.

  • investment_amount (float) – The total investment amount to allocate across different products.

  • min_tenure (int, optional) – The minimum tenure (in months) to include. Default is 0.

  • max_tenure (int, optional) – The maximum tenure (in months) to include. Default is 999.

sgfixedincome_pkg.analysis.plot_pure_and_better_allocation_strategy_rates(df, investment_amount, min_tenure=0, max_tenure=999)[source]

Overlay plot for best rates (% p.a.) and effective better allocation strategy rates for each tenure.

Parameters:
  • df (pd.DataFrame) – DataFrame containing ‘Tenure’, ‘Rate’, ‘Deposit lower bound’, ‘Deposit upper bound’, ‘Product provider’, ‘Product’.

  • investment_amount (float) – The investment amount to filter available rates and products.

  • min_tenure (int, optional) – The minimum tenure (in months) to include. Default is 0.

  • max_tenure (int, optional) – The maximum tenure (in months) to include. Default is 999.