# Account value to number of policiesΒΆ

This graph uses the CashValue_ME_EX2 model from 2. Extended Stochastic Example, and shows path dependency of policy decrement.

The scatter plot shows how the number of policies at maturity varies by the level of account value at maturity, and the graphs on the sides show the distributions of the two factors.

# The code below is based on the sample script available on
# https://matplotlib.org/stable/gallery/lines_bars_and_markers/scatter_hist.html
# See accompanying LICENSE_MATPLOT.txt for its terms of conditions.

import numpy as np
import matplotlib.pyplot as plt
import modelx as mx

def scatter_hist(x, y, ax, ax_histx, ax_histy):
# no labels
ax_histx.tick_params(axis="x", labelbottom=False)
ax_histy.tick_params(axis="y", labelleft=False)

# the scatter plot:
ax.scatter(x, y)

def get_bins(data, binsize):
ub, lb = np.max(data), np.min(data)
binwidth = ((ub - lb) / binsize)
return np.arange(lb, ub + binwidth, binwidth)

xbins = get_bins(x, 100)
ybins = get_bins(y, 100)
ax_histx.hist(x, bins=xbins)
ax_histy.hist(y, bins=ybins, orientation='horizontal')

# definitions for the axes
left, width = 0.1, 0.65
bottom, height = 0.1, 0.65
spacing = 0.005

rect_scatter = [left, bottom, width, height]
rect_histx = [left, bottom + height + spacing, width, 0.2]
rect_histy = [left + width + spacing, bottom, 0.2, height]

fig = plt.figure(figsize=(8, 8))

ax.grid(True), ax_histx.grid(True), ax_histy.grid(True)