### Set Up Virtual Environment and Install Dependencies Source: https://github.com/llmquant/quant-wiki/blob/master/README.md Create a virtual environment using venv, activate it, and install project dependencies from requirements.txt. ```bash python -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/llmquant/quant-wiki/blob/master/README.md Clone the quant-wiki repository and navigate into the project directory to begin local setup. ```bash git clone https://github.com/LLMQuant/quant-wiki.git cd quant-wiki ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/SITE_CONFIGURATION.md Install all project dependencies listed in the requirements.txt file using pip. This ensures the project has all necessary libraries to run. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/DeepSeek-R1-tesla.md Installs necessary Python libraries for fetching news, parsing HTML, and interacting with LLMs. ```bash pip install yfinance pandas markitdown requests langchain langchain-ollama ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/SITE_CONFIGURATION.md Create and activate a Python virtual environment to isolate project dependencies. This is a standard practice for Python development. ```bash python -m venv .venv source .venv/bin/activate # Linux/Mac # or .venv\Scripts\activate # Windows ``` -------------------------------- ### Example Call to Get Tesla News Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/DeepSeek-R1-tesla.md Demonstrates how to call the `get_news` function for 'TSLA' and print the number of articles found and the details of the first article. ```python news_list = get_news("TSLA") print(len(news_list)) # 查看获取到的新闻数量 print(news_list[0]) # 输出其中一篇新闻的信息 ``` -------------------------------- ### Knowledge Checklist Example Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/LEARNING_PATHS.md A checklist to track mastery of key financial concepts, probability, and trading principles. Useful for self-assessment and progress tracking. ```plaintext Financial Concepts: ☐ Primary/secondary markets ☐ Stocks, bonds, derivatives ☐ Options Greeks ☐ Margin and leverage ☐ Short selling Probability: ☐ Normal distribution ☐ Conditional probability ☐ Bayes' theorem ☐ Hypothesis testing ☐ Monte Carlo simulation Trading: ☐ CAPM ☐ Fama-French ☐ Alpha/beta ☐ Momentum/mean reversion ☐ Backtesting methodology ``` -------------------------------- ### Check for Outdated Packages Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/SITE_CONFIGURATION.md List all installed Python packages that have newer versions available. ```bash pip list --outdated ``` -------------------------------- ### Agents with PythonREPLTool for Code Execution Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/aiquant/ChatGPT-langchain.md Illustrates using an Agent with the PythonREPLTool to execute Python code directly within a LangChain flow for data processing, analysis, or computation. Note: This example uses langchain-core < 0.2. ```python from langchain.agents import AgentType, initialize_agent from langchain_experimental.tools import PythonREPLTool from langchain_openai import ChatOpenAI llm = ChatOpenAI(temperature=0) tools = [ PythonREPLTool() ] agent = initialize_agent( tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True ) agent.run("What is 3 + 3?") ``` -------------------------------- ### Install Pydantic Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/aiquant/ChatGPT-langchain.md Installs a specific version of the Pydantic library, which is often a dependency for LangChain components. ```shell !pip install pydantic==<相应版本> ``` -------------------------------- ### Serve MkDocs Locally Source: https://github.com/llmquant/quant-wiki/blob/master/README.md Run this command to serve the MkDocs documentation locally for previewing. ```bash mkdocs serve ``` -------------------------------- ### Build Static Site for Production Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/SITE_CONFIGURATION.md Generate the static HTML, CSS, and JS files for the website in the 'site/' directory. This command optimizes assets for deployment. ```bash mkdocs build ``` -------------------------------- ### Initialize DeepSeek-R1 with OllamaLLM Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/DeepSeek-R1-tesla.md Sets up the DeepSeek-R1 language model using LangChain's OllamaLLM integration, preparing it for sentiment analysis tasks. ```python from langchain_ollama.llms import OllamaLLM from langchain_core.prompts import ChatPromptTemplate from pprint import pprint # 初始化DeepSeek-R1 llm = OllamaLLM(model="deepseek-r1:1.5b") ``` -------------------------------- ### Clone Repository Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/SITE_CONFIGURATION.md Clone the quant-wiki repository to your local machine to begin contributing. Navigate into the cloned directory. ```bash git clone https://github.com/YOUR_USERNAME/quant-wiki.git cd quant-wiki ``` -------------------------------- ### Ratio Signal Formula Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/chat-paper.md Example of a ratio-based signal formula used in financial research, derived from accounting variables. ```latex \text{Signal}_{i,t} = \frac{\text{AccountingVar1}_{i,t}}{\text{AccountingVar2}_{i,t}} ``` -------------------------------- ### Project Directory Structure Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/README.md This snippet shows the directory structure of the quant-wiki project, outlining the purpose of each main file. ```bash output/ ├── README.md # This file (overview and index) ├── PROJECT_OVERVIEW.md # Project structure and architecture ├── CONTENT_CATALOG.md # Complete content index (422 docs) ├── CONCEPTS_REFERENCE.md # 192 core concepts encyclopedia ├── AI_TRADING_FRAMEWORKS.md # AI/ML frameworks reference ├── SITE_CONFIGURATION.md # Build system and deployment └── LEARNING_PATHS.md # 5 structured learning journeys ``` -------------------------------- ### Difference Signal Formula Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/chat-paper.md Example of a difference-based signal formula, calculating the change in an accounting variable over time relative to another variable. ```latex \text{Signal}_{i,t} = \frac{\text{AccountingVar1}_{i,t} - \text{AccountingVar1}_{i,t-1}}{\text{AccountingVar2}_{i,t-1}} ``` -------------------------------- ### Concept Map Example Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/LEARNING_PATHS.md Illustrates a hierarchical structure for organizing knowledge about a concept like 'Volatility'. Useful for studying and interview preparation. ```plaintext Volatility ├── Measurement (standard deviation) ├── Drivers (price movement) ├── Prediction (volatility forecasting) ├── Application (option pricing) └── Trading (volatility arbitrage) ``` -------------------------------- ### Deploy to GitHub Pages Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/SITE_CONFIGURATION.md Build the site and deploy it to GitHub Pages. This command automates the process of building and pushing to the gh-pages branch. ```bash mkdocs gh-deploy ``` -------------------------------- ### Using LLMs with Prompting in LangChain Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/aiquant/ChatGPT-langchain.md Demonstrates integrating LLMs with Prompting for generating targeted responses. The 'temperature' parameter controls output randomness; setting it to 0 ensures deterministic output. ```python from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate llm = ChatOpenAI(model="gpt-4") prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful assistant."), ("user", "{input}") ]) chain = prompt | llm response = chain.invoke({"input": "Translate the following English text to French: 'hello world'"}) print(response.content) ``` -------------------------------- ### Get Tesla News with yfinance Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/DeepSeek-R1-tesla.md Fetches news articles related to a given stock symbol using the yfinance library. It filters for 'STORY' content types and extracts title, summary, URL, and publication date. ```python import yfinance as yf import pandas as pd def get_news(stock: str) -> list: """ 获取与指定股票相关的新闻列表,返回包含标题、摘要、链接、发布日期的字典列表。 """ try: # 获取股票对象及其新闻 ticker = yf.Ticker(stock) news = ticker.news # 如果没有新闻,则返回空列表 if not news: print(f"No news found for {stock}.") return [] # 只保留contentType='STORY'的新闻 relevant_news = [ item for item in news if item.get('content', {}).get('contentType') == 'STORY' ] all_news = [] for i, item in enumerate(relevant_news): try: content = item.get('content', {}) current_news = { 'title': content.get('title'), 'summary': content.get('summary'), 'url': content.get('canonicalUrl', {}).get('url'), 'pubdate': content.get('pubDate', '').split('T')[0], } all_news.append(current_news) except Exception as e: print(f"Error processing news {i}: {e}") continue return all_news except Exception as e: print(f"An error occurred while fetching news for {stock}: {e}") return [] ``` -------------------------------- ### Prompt Templates for Structured Prompts Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/aiquant/ChatGPT-langchain.md Illustrates the use of Prompt Templates to create predefined structures for prompts, enabling consistent and context-aware queries to language models. Placeholders can be used for dynamic data insertion. ```python from langchain_core.prompts import PromptTemplate prompt = PromptTemplate( input_variables=["product", "model"], template="Tell me more about the {product} in the {model} model.", ) formatted_prompt = prompt.format(product="iPhone", model="15 Pro") print(formatted_prompt) ``` -------------------------------- ### Chains for Sequential Operations Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/aiquant/ChatGPT-langchain.md Shows how to create a chain by connecting a prompt and an LLM ('prompt | llm') to perform sequential operations and generate responses. This structure is fundamental for building complex NLP tasks. ```python from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate llm = ChatOpenAI(model="gpt-4") prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful assistant."), ("user", "{input}") ]) chain = prompt | llm response = chain.invoke({"input": "What is the capital of France?"}) print(response.content) ``` -------------------------------- ### Batch Processing with Chains Source: https://github.com/llmquant/quant-wiki/blob/master/docs/ai/aiquant/ChatGPT-langchain.md Demonstrates batch processing by inputting multiple data points into a chain simultaneously for parallel processing, which enhances efficiency. ```python from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate llm = ChatOpenAI(model="gpt-4") prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful assistant."), ("user", "{input}") ]) chain = prompt | llm responses = chain.batch([{"input": "Translate 'hello' to French"}, {"input": "Translate 'goodbye' to French"}]) for response in responses: print(response.content) ``` -------------------------------- ### LangChain + ChatGPT Integration Pattern Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/AI_TRADING_FRAMEWORKS.md Illustrates the flow for building AI-powered financial analysis agents using LangChain and OpenAI's GPT-4. This pattern is suitable for automated report generation and market analysis agents. ```text LLM (GPT-4) → LangChain Agent → Financial Tools/APIs → Analysis Output ``` -------------------------------- ### Include Custom CSS Source: https://github.com/llmquant/quant-wiki/blob/master/_autodocs/SITE_CONFIGURATION.md To use custom CSS, place your file in the 'docs/stylesheets/' directory and reference it in mkdocs.yml under 'extra_css'. ```yaml extra_css: - stylesheets/custom.css ```