text
stringlengths
1
93.6k
def Price_target_to_Price_Signal(stock_obj):
ratings_df = stock_obj.ratings_data
ratings_df['DateTime'] = pd.to_datetime(ratings_df['RatingDate'])
PT_ts = ratings_df.set_index('DateTime').loc[:, 'NewPT'].resample('D').mean()
PT_ts.index = PT_ts.index.map(lambda x: x.date())
PT_ts = PT_ts.reindex(stock_obj['PriceClose'].index).ffill()
signal_ts = (PT_ts - stock_obj['PriceClose']) / stock_obj['PriceClose']
return signal_ts
########################### Fama French Factors ###############################
def Fama_French_Rolling_Beta(stock_obj, Fama_French_Series_Name, window = 42):
stock_daily_returns = stock_obj['PriceClose'].pct_change(1).dropna()
F_F_series = get_Fama_French_ts(Fama_French_Series_Name)
output_dict = Rolling_Regression( Y_ts=stock_daily_returns,
X_ts_arr=[F_F_series],
window=window)
signal_dict = {dt: v['Beta_hat'][Fama_French_Series_Name] for dt, v in output_dict.items()}
signal_ts = pd.Series(signal_dict)
signal_ts.name = Fama_French_Series_Name + '_Beta'
return signal_ts
############################## Momentum Factors ##################################
def Momentum_dual_window(stock_obj, window_long, window_short):
stock_daily_returns = stock_obj['PriceClose'].pct_change(1).dropna()
Momentum_window_long_series = stock_daily_returns.rolling(window = window_long).mean().shift(1)
Momentum_window_short_series = stock_daily_returns.rolling(window = window_short).mean().shift(1)
return Momentum_window_long_series - Momentum_window_short_series
def Momentum_12M_1M(stock_obj):
return Momentum_dual_window(stock_obj, window_long = 252, window_short = 21)
def Momentum_window(stock_obj, window):
stock_daily_returns = stock_obj['PriceClose'].pct_change(1).dropna()
Momentum_window_series = stock_daily_returns.rolling(window = window).mean().shift(1)
return Momentum_window_series
# <FILESEP>
import json
import logging
from pathlib import Path
from typing import Optional, Type
from langchain import LLMChain, PromptTemplate
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage, SystemMessage
from pydantic import BaseModel, Field
OPEN_AI_MODEL = "gpt-3.5-turbo"
OPEN_AI_MODEL = "gpt-4"
class DeepResearchWriter(BaseModel):
desired_output_format: str = Field(
...,
description="The desired output format. The only valid value at this time is 'single_file'",
)
class DeepResearchWriterTool:
"""
Tool for writing the output of the Deep research tool. If deep research was not done, this tool will fail to run
"""
name: str = "Deep Research Writer Tool"
args_schema: Type[BaseModel] = DeepResearchWriter
description: str = "Takes the results of the deep research and writes the output format"
def __init__(self):