Question: We have trained a simple machine learning model to predict whether we should go LONG or SHORT a stock depending on 2 factors: - its



We have trained a simple machine learning model to predict whether we should go LONG or SHORT a stock depending on 2 factors: - its earnings per share (EPS); and - its returns on equity (ROE). The model comprises 3 lists of values: - eps: a list of 100 EPS values (normalized to between 1 and 1) - roe: a list of 100ROE values (normalized to between 1 and 1 ) - signal: a list of 100 'LONG' or 'SHORT' signals corresponding by list index to the eps and roe values The values are generated using the following code snippet: import random random, seed(312) def f(r,c) : return [ [random. uniform(i-c,i)/c for i in range(c) ] for in range (r)] When plotted as a graph of EPS vs ROE, we can visualize the data like this: To use the model, we employ the T-Closest Points (T-CP) classifier algorithm: - Given a stock S with normalized EPS E and ROER, we locate the point (E,R) on the EPS vs ROE graph. - Identify its T closest points by distance. The distance is defined as the Euclidean distance between two points (i.e. the proximity-2 metric from Q2 ). We can view this as a circle centered at the point (E,R) containing its T closest points. - If the majority of these T closest points have signals 'LONG', then we classify S s signal as 'LONG'; otherwise, it is 'SHORT'. Task: Design and implement a function TCP(t,E,R) that classifies stock S given its normalized EPS E and ROER. The function should return the string 'LONG' or 'SHORT'. Your implementation should be based on the algorithm description. Examples: - Suppose k=7 and (E,R)=(0.2,0.5). Then the 7 closest points comprise 4 'LONG' and 3 'SHORT' signals, so TCP(7,0.2,0.5)= 'LONG'. - Suppose k=9 and (E,R)=(0.5,0.1). Then the 9 closest points comprise 3 'LONG' and 6 'SHORT' signals, so TCP(9,0.5,0.1)= 'SHORT'. Change k=7 and k=9, to t=7 and t=9 (30 marks) Given the following 5 test cases, print the results from your function using this code: for t,E,R in cases: print(f'Result: {TCP(t,E,R)})
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
