real.append(num)
时间: 2024-05-25 11:19:24 浏览: 7
This line of code is used to add a new element (in this case, the variable "num") to a list called "real" in Python. The append() function is used to add an element to the end of a list. After this code is executed, the list "real" will have the new element added to it.
相关问题
使用C++ eigen库翻译以下python代码import pandas as pd import numpy as np import time import random def main(): eigen_list = [] data = [[1,2,4,7,6,3],[3,20,1,2,5,4],[2,0,1,5,8,6],[5,3,3,6,3,2],[6,0,5,2,19,3],[5,2,4,9,6,3]] g_csi_corr = np.cov(data, rowvar=True) #print(g_csi_corr) eigenvalue, featurevector = np.linalg.eigh(g_csi_corr) print("eigenvalue:",eigenvalue) eigen_list.append(max(eigenvalue)) #以下代码验证求解csi阈值 eigen_list.append(1.22) eigen_list.append(-54.21) eigen_list.append(8.44) eigen_list.append(-27.83) eigen_list.append(33.12) #eigen_list.append(40.29) print(eigen_list) eigen_a1 = np.array(eigen_list) num1 = len(eigen_list) eigen_a2 = eigen_a1.reshape((-1, num1)) eigen_a3 = np.std(eigen_a2, axis=0) eigen_a4 = eigen_a3.tolist() k = (0.016 - 0.014) / (max(eigen_a4) - min(eigen_a4)) eigen_a5 = [0.014 + k * (i - min(eigen_a4)) for i in eigen_a4] tri_threshold = np.mean(eigen_a5)
#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
int main()
{
std::vector<double> eigen_list;
MatrixXd data(6, 6);
data << 1, 2, 4, 7, 6, 3,
3, 20, 1, 2, 5, 4,
2, 0, 1, 5, 8, 6,
5, 3, 3, 6, 3, 2,
6, 0, 5, 2, 19, 3,
5, 2, 4, 9, 6, 3;
MatrixXd g_csi_corr = data.transpose() * data / 6.0;
EigenSolver<MatrixXd> es(g_csi_corr);
VectorXd eigenvalue = es.eigenvalues().real();
std::cout << "eigenvalue: " << eigenvalue.transpose() << std::endl;
eigen_list.push_back(eigenvalue.maxCoeff());
eigen_list.push_back(1.22);
eigen_list.push_back(-54.21);
eigen_list.push_back(8.44);
eigen_list.push_back(-27.83);
eigen_list.push_back(33.12);
//eigen_list.push_back(40.29);
std::cout << "eigen_list: ";
for (std::vector<double>::iterator it = eigen_list.begin(); it != eigen_list.end(); ++it)
std::cout << *it << " ";
std::cout << std::endl;
int num1 = eigen_list.size();
MatrixXd eigen_a2 = Map<MatrixXd>(eigen_list.data(), num1, 1);
VectorXd eigen_a3 = eigen_a2.array().rowwise().mean().transpose();
VectorXd eigen_a4 = (eigen_a2 - eigen_a3.replicate(num1, 1)).array().abs().rowwise().mean().transpose();
double k = 0.002 / (eigen_a4.maxCoeff() - eigen_a4.minCoeff());
VectorXd eigen_a5 = 0.014 + k * (eigen_a4.array() - eigen_a4.minCoeff());
double tri_threshold = eigen_a5.mean();
std::cout << "tri_threshold: " << tri_threshold << std::endl;
return 0;
}
# 导入聚宽函数库 import jqdata log.set_level("system","error") # 初始化程序, 整个回测只运行一次 def initialize(context): # 开启动态复权模式(真实价格) set_option('use_real_price', True) # 股票类交易手续费是:买入时佣金万分之三,卖出时佣金万分之三加千分之一印花税, 每笔交易佣金最低扣5块钱 set_order_cost(OrderCost(open_tax=0, close_tax=0.001, \ open_commission=0.0003, close_commission=0.0003,\ close_today_commission=0, min_commission=5), type='stock') # 股票池 g.stocks = list(get_all_securities(['stock']).index) #上涨家数 g.num = [] #上涨家数(去重) g.b=[] # 计数器 g.run_num = -1 # 运行函数 run_daily(market_open, time='every_bar') def before_trading_start(context): # 得到所有股票前1日收盘价 g.last_df = history(1,'1d','close',g.stocks) def market_open(context): #频率10分钟一次 g.run_num += -1 if g.run_num != 10: return else: g.run_num = 0 #每天每10分钟实时价格 for security in g.stocks: # 得到当前价格 current_data = get_current_data() price = current_data[security].last_price g.one = g.last_df[security][0] if price > g.one: g.num.append(security) g.b = list(set(g.num)) elif price < g.one: if security in g.num: g.num.remove(security) g.b = list(set(g.num)) print(len(g.b))把上述代码改成只在14:30分运行
你可以在`initialize`函数中添加一个定时器,使其在14:30分运行。具体的修改如下:
```python
def initialize(context):
# 其他代码...
# 添加定时器,每天的14:30分运行
run_daily(market_open, time='14:30')
```
这样修改后,`market_open`函数将在每天的14:30分被调用。你可以在该函数中继续执行你的逻辑。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)