### Formula Syntax Examples for Factor Creation Source: https://github.com/pandaai-tech/panda_factor/blob/main/README.md Illustrates how to define quantitative factors using the formula syntax. Examples include calculating 20-day return rank, price-volume correlation, and a complex factor combining multiple operators. Formulas can span multiple lines using intermediate variables (as mentioned in the surrounding text). ```Formula # 计算20日收益率排名 RANK((CLOSE / DELAY(CLOSE, 20)) - 1) # 计算价格和成交量的相关性 CORRELATION(CLOSE, VOLUME, 20) # 复杂因子示例 RANK((CLOSE / DELAY(CLOSE, 20)) - 1) * STDDEV((CLOSE / DELAY(CLOSE, 1)) - 1, 20) * IF(CLOSE > DELAY(CLOSE, 1), 1, -1) ``` -------------------------------- ### Installing Project Modules in Editable Mode Source: https://github.com/pandaai-tech/panda_factor/blob/main/README.md Provides the command to install project sub-modules (like panda_common, panda_data, etc.) in editable mode using pip. This is recommended for development environments like VS Code or Cursor and should be executed from within each sub-module directory. ```Bash pip install -e . ``` -------------------------------- ### Example Complex Factor Calculation in Python Source: https://github.com/pandaai-tech/panda_factor/blob/main/README.md Provides a detailed example of implementing a complex quantitative factor in Python mode. It demonstrates accessing base data (close, volume, high, low) and using various built-in operators (DELAY, STDDEV, SUM, RANK, IF, SCALE) to calculate intermediate signals and synthesize a final factor value. ```Python class ComplexFactor(Factor): def calculate(self, factors): close = factors['close'] volume = factors['volume'] high = factors['high'] low = factors['low'] # 计算20日收益率 returns = (close / DELAY(close, 20)) - 1 # 计算20日波动率 volatility = STDDEV((close / DELAY(close, 1)) - 1, 20) # 计算价格区间 price_range = (high - low) / close # 计算成交量比率 volume_ratio = volume / DELAY(volume, 1) # 计算20日成交量均值 volume_ma = SUM(volume, 20) / 20 # 计算动量信号 momentum = RANK(returns) # 计算波动率信号 vol_signal = IF(volatility > DELAY(volatility, 1), 1, -1) # 合成最终因子 result = momentum * vol_signal * SCALE(volume_ratio / volume_ma) return result ``` -------------------------------- ### Python Project Dependencies List Source: https://github.com/pandaai-tech/panda_factor/blob/main/panda_llm/requirements.txt This snippet lists the core Python packages and their exact versions required to run the project. This format is typically used in a requirements.txt file for easy installation using pip. ```Python fastapi==0.104.1 uvicorn==0.24.0 pydantic==2.4.2 aiohttp==3.9.1 pyyaml==6.0.1 python-dotenv==1.0.0 ``` -------------------------------- ### Utility Dependencies (Python) Source: https://github.com/pandaai-tech/panda_factor/blob/main/requirements.txt Lists general utility Python packages for logging (Loguru), YAML parsing (PyYAML), progress bars (tqdm), and package management (setuptools). ```Python # Utilities loguru>=0.6.0 PyYAML>=6.0 tqdm>=4.65.0 setuptools>=67.6.1 ``` -------------------------------- ### Trading and Market Data Dependencies (Python) Source: https://github.com/pandaai-tech/panda_factor/blob/main/requirements.txt Lists Python packages specifically for trading and accessing market data, including rqdatac and tqsdk. ```Python # Trading & Market Data rqdatac>=2.9.0 tqsdk>=3.2.10 ``` -------------------------------- ### Development and Testing Dependencies (Python) Source: https://github.com/pandaai-tech/panda_factor/blob/main/requirements.txt Lists Python packages used for development, testing, and interactive sessions, including pytest, pytest-asyncio, httpx, IPython, and openai. ```Python # Development & Testing pytest>=7.3.1 pytest-asyncio>=0.21.0 httpx>=0.24.0 IPython>=8.12.0 openai>=1.73.0 ``` -------------------------------- ### Web Framework Dependencies (Python) Source: https://github.com/pandaai-tech/panda_factor/blob/main/requirements.txt Lists Python packages required for building web applications, including FastAPI, Uvicorn, Flask, and Pydantic. ```Python # Web Framework fastapi>=0.95.0 uvicorn>=0.21.0 flask>=2.3.2 pydantic>=1.10.7 ``` -------------------------------- ### Database Dependencies (Python) Source: https://github.com/pandaai-tech/panda_factor/blob/main/requirements.txt Lists Python packages for database interactions, including MongoDB (PyMongo), Redis, and MySQL. ```Python # Database pymongo>=4.3.3 redis>=4.5.4 mysql-connector-python>=8.0.32 ``` -------------------------------- ### Accessing Generated Factors in Python Source: https://github.com/pandaai-tech/panda_factor/blob/main/README.md Demonstrates how to import the `panda_data` module, initialize it, and retrieve a specific factor by its name and date range. This code snippet is used to integrate factors produced by PandaFactor into external trading systems or strategies. ```Python import panda_data panda_data.init() factor = panda_data.get_factor_by_name(factor_name="VH03cc651", start_date='20240320',end_date='20250325') ``` -------------------------------- ### Task Scheduling Dependency (Python) Source: https://github.com/pandaai-tech/panda_factor/blob/main/requirements.txt Lists the Python package required for task scheduling, specifically APScheduler. ```Python # Task Scheduling apscheduler>=3.10.1 ``` -------------------------------- ### Defining a Custom Factor Class in Python Source: https://github.com/pandaai-tech/panda_factor/blob/main/README.md Defines the basic structure for creating a custom quantitative factor in Python mode. Factors must inherit from the `Factor` class and implement the `calculate` method, which takes `factors` (containing base data like close, volume) as input and must return a pandas Series with a multi-index ['symbol', 'date']. ```Python class CustomFactor(Factor): def calculate(self, factors): return result ``` -------------------------------- ### Data Processing Dependencies (Python) Source: https://github.com/pandaai-tech/panda_factor/blob/main/requirements.txt Lists Python packages for data manipulation, analysis, and visualization, such as NumPy, Pandas, SciPy, Statsmodels, Matplotlib, and Seaborn. ```Python # Data Processing numpy>=1.24.2 pandas>=2.0.0 scipy>=1.10.1 statsmodels>=0.13.5 matplotlib>=3.7.1 seaborn>=0.13.0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.