def get_student(): student_id = get_int("Enter ID Number:") matching_ids = [ student for student in student_list if student.id == student_id ] if not matching_ids: print("You're not in the list!") get_student() return matching_ids[0] # Take first student
def edit_id_number(): new_id = get_int("Enter your new ID number") student.id = new_id
def edit_unit(): new_unit = get_int("Enter new unit") course.unit = new_unit
def add_course(): code = get_string("Enter Code") unit = get_int("Enter unit") course_list.append(Course(unit=unit, code=code)) print(course_list[0].code) # TEST
def register(): name = get_string("Enter name") id = get_int("Enter ID Number") student_list.append(Student(name=name, id=id)) print(f"Welcome {name}!")
fig.suptitle('Proportion of variance explained by principal components') ax1.bar(["{:.1e}".format(eigenvalue) for eigenvalue in eigenvalue_df['eigenvalue']], eigenvalue_df['proportion_of_variance']) ax1.set_xlabel("eigenvalue") ax1.set_ylabel("proportion of variance explained") ax2.plot(cumulative_plot, marker="^") ax2.set_xlabel("# of principal components (sorted)") ax2.set_ylabel("Cumulative prop. of variance explained") ax2.set_ylim([0, 1]) plt.show() reduced_eigenvalue_matrix = None reduced_covariance_matrix = None if user_input.get_boolean("Reduce dimensionality using PCA? (Y/N) "): max_components = len(eigenvalue_df) num_components = user_input.get_int("Enter desired number of components (1 to " + str(max_components) + ") ", int_min=0, int_max=max_components) reduced_eigenvalue_matrix, reduced_covariance_matrix = \ numerical_functions.run_principal_components_analysis(num_components, eigenvalue_df, eigenvector_df) adjusted_final = float((weights.dot(reduced_covariance_matrix)).dot(weights.transpose())) adjusted_portfolio_stddev = np.sqrt(adjusted_final) adjusted_shift = np.expm1(adjusted_portfolio_stddev * z_score) * np.sqrt(holding_period) adjusted_var = abs(np.sum(notional_values) * adjusted_shift) helper_functions.output(f"PCA-adjusted portfolio standard deviation: {adjusted_portfolio_stddev:.2%}") helper_functions.output(f"PCA-adjusted log return: {adjusted_shift:.2%}") helper_functions.output(f"PCA-adjusted percentage return: " f"{adjusted_portfolio_stddev * z_score * np.sqrt(holding_period):.2%}") helper_functions.output(str(holding_period) + "-day" + f"{confidence_level: .2%}" + " PCA-adjusted VaR: $" + f'{adjusted_var:,.2f}')