@beartypeclassAnalysis(AnalysisInterface):"""Class for collecting and processing annual report data."""under_development=Truedefanalyze(self)->Optional[pd.DataFrame]:# Build a training set involving good companiessec_filter=SecFilter(tags=["EarningsPerShareDiluted","CommonStockSharesIssued","AssetsCurrent","LiabilitiesCurrent","Assets","OperatingIncomeLoss","NetCashProvidedByUsedInOperatingActivities",],years=5,# Over the past 5 yearslast_report=self.options.final_report,only_annual=True,# We only want the 10-K)good_tickers=set()good_tickers.add("aapl")good_tickers.add("msft")good_tickers.add("goog")good_tickers.add("hd")good_tickers.add("acn")good_tickers.add("nvda")bad_tickers=set()bad_tickers.add("wdc")bad_tickers.add("nclh")bad_tickers.add("grpn")bad_tickers.add("capr")combined_tickers=list(good_tickers.union(self.options.tickers).union(bad_tickers))# Create an SEC Data Sourcetable=create_normalized_sec_table(sec_filter,combined_tickers,False)table.calculate_return_on_assets("ROA")table.calculate_net_income("net_income")table.calculate_delta(column_name="delta_ROA",delta_of="ROA")table.calculate_debt_to_assets("debt_to_assets")table.calculate_current_ratio("current_ratio")table.data["good_stock"]=Falsefortingood_tickers:table.data.loc[t.upper(),["good_stock"]]=Truetable.data.fillna(0,inplace=True)# Select Training Stockstrain_df=table.slice(ticker=list(good_tickers.union(bad_tickers)))logging.debug(f"there are {train_df['good_stock'].sum()} good stocks in the training set")logging.debug(f"training_data:\n{train_df.to_string()}")# Select Assessment Stockstest_df=table.slice(ticker=list(good_tickers.difference(self.options.tickers)))train_ds=tfdf.keras.pd_dataframe_to_tf_dataset(train_df,label="good_stock")test_ds=tfdf.keras.pd_dataframe_to_tf_dataset(test_df,label="good_stock")# Train a Random Forest model.model=tfdf.keras.RandomForestModel()model.fit(train_ds)# Summary of the model structure.model.summary()# Evaluate the model.model.evaluate(test_ds)# Export the model to a SavedModel.model.save(str(cache.CACHE_DIR/"tf-model"))returnpd.DataFrame()# Reuse documentation from parentanalyze.__doc__=AnalysisInterface.analyze.__doc__