Esempio n. 1
0
# The Default (absorbing state)
Default = Ratings - 1

# Lets extend the matrix into multi periods
Periods = 10
T = tm.TransitionMatrixSet(values=M,
                           periods=Periods,
                           method='Power',
                           temporal_type='Cumulative')

# Initialize a threshold set
As = ThresholdSet(TMSet=T)

for ri in range(0, Ratings):
    print("RI: ", ri)
    As.fit(AR_Model, ri)

lines = []
ri = 3
for rf in range(0, Ratings):
    for k in range(0, Periods):
        if rf != ri:
            value = As.A[ri, rf, k]
            line = [(k, value), (k + 1.0, value)]
            lines.append(line)

lc = mc.LineCollection(lines, linewidths=2)
fig, ax = plt.subplots()
ax.add_collection(lc)
ax.autoscale()
ax.margins(0.1)
# Example 2: Minimal -> Three state transition matrix

M = tm.TransitionMatrix(values=Generic)
# Lets take a look at the values
M.print()
M.validate()

# The size of the rating scale
Ratings = M.dimension

# The Default (absorbing state)
Default = Ratings - 1

# Lets extend the matrix into multi periods
Periods = 5
T = tm.TransitionMatrixSet(values=M, periods=Periods, method='Power', temporal_type='Cumulative')

# Initialize a threshold set
As = ThresholdSet(TMSet=T)

print("> Fit Multiperiod Thresholds")
for ri in range(0, Ratings):
    print("RI: ", ri)
    As.fit(AR_Model, ri)

print("> Validate Multiperiod Thresholds against Input Transition Matrix Set")
Q = As.validate(AR_Model)

print("> Save Multiperiod Thresholds in JSON Format")
As.to_json('generic_thresholds.json')
    Ratings = M.dimension

    # The Default (absorbing state)
    Default = Ratings - 1

    # Lets extend the matrix into multi periods
    Periods = 10
    T = tm.TransitionMatrixSet(values=M,
                               periods=Periods,
                               method='Power',
                               temporal_type='Cumulative')
    print("> Extend the matrix into 10 periods")
elif example == 2:
    T = tm.TransitionMatrixSet(periods=120,
                               temporal_type='Cumulative',
                               json_file=dataset_path + "generic_monthly.json")
    Ratings = T.entries[0].dimension

# Initialize a threshold set
As = ThresholdSet(TMSet=T)

# Calculate thresholds per initial rating state
print("> Calculate thresholds per initial rating state")
for ri in range(0, Ratings):
    print("Initial Rating: ", ri)
    As.fit(AR_Model, ri, dt=1.0 / 12.0)
As.to_json(json_file="monthly_thresholds.json")

# Display the calculated thresholds
# print("> Display the calculated thresholds")
# As.print()