Skip to content

Commit

Permalink
add bash file
Browse files Browse the repository at this point in the history
  • Loading branch information
woldy committed Dec 26, 2023
1 parent bd76cad commit 90bf5f9
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 39 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# FinHack® 炼金术
FinHack® is a scalable quantitative finance framework.

FinHack® 是一个易于拓展的量化金融框架

1 change: 0 additions & 1 deletion README.txt

This file was deleted.

181 changes: 181 additions & 0 deletions database/finhack_structure.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
-- MySQL dump 10.13 Distrib 8.0.30, for Linux (x86_64)
--
-- Host: localhost Database: finhack
-- ------------------------------------------------------
-- Server version 8.0.30

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `auto_train`
--

DROP TABLE IF EXISTS `auto_train`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `auto_train` (
`id` int NOT NULL AUTO_INCREMENT,
`start_date` varchar(10) DEFAULT NULL,
`valid_date` varchar(10) DEFAULT NULL,
`end_date` varchar(10) DEFAULT NULL,
`features` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`label` varchar(255) DEFAULT NULL,
`shift` int DEFAULT NULL,
`param` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`hash` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`loss` varchar(255) DEFAULT NULL,
`algorithm` varchar(255) DEFAULT NULL,
`filter` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '',
`score` double(10,10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12548 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `backtest`
--

DROP TABLE IF EXISTS `backtest`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `backtest` (
`id` int NOT NULL AUTO_INCREMENT,
`instance_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`features_list` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`train` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`model` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`strategy` varchar(255) DEFAULT NULL,
`start_date` varchar(10) DEFAULT NULL,
`end_date` varchar(10) DEFAULT NULL,
`init_cash` double(100,5) DEFAULT NULL,
`args` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`history` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`returns` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`logs` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`total_value` double(100,5) DEFAULT NULL,
`alpha` double(100,5) DEFAULT NULL,
`beta` double(100,5) DEFAULT NULL,
`annual_return` double(100,5) DEFAULT NULL,
`cagr` double(100,5) DEFAULT NULL,
`annual_volatility` double(100,5) DEFAULT NULL,
`info_ratio` double(100,5) DEFAULT NULL,
`downside_risk` double(100,5) DEFAULT NULL,
`R2` double(100,5) DEFAULT NULL,
`sharpe` double(100,5) DEFAULT NULL,
`sortino` double(100,5) DEFAULT NULL,
`calmar` double(100,5) DEFAULT NULL,
`omega` double(100,5) DEFAULT NULL,
`max_down` double(100,5) DEFAULT NULL,
`SQN` double(100,5) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`filter` varchar(255) DEFAULT '',
`win` double(100,5) DEFAULT NULL,
`server` varchar(255) DEFAULT NULL,
`trade_num` int DEFAULT NULL,
`runtime` varchar(255) DEFAULT NULL,
`starttime` varchar(100) DEFAULT NULL,
`endtime` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`benchReturns` mediumtext,
`roto` double(100,5) DEFAULT NULL,
`simulate` int DEFAULT '0',
`benchmark` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `instence_id` (`instance_id`)
) ENGINE=InnoDB AUTO_INCREMENT=387973 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `factors_analysis`
--

DROP TABLE IF EXISTS `factors_analysis`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `factors_analysis` (
`id` int NOT NULL AUTO_INCREMENT,
`factor_name` varchar(255) DEFAULT NULL,
`days` varchar(255) DEFAULT NULL,
`pool` varchar(255) DEFAULT NULL,
`start_date` varchar(10) DEFAULT NULL,
`end_date` varchar(10) DEFAULT NULL,
`formula` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`IC` float(10,5) DEFAULT NULL,
`IR` float(10,5) DEFAULT NULL,
`IRR` float(10,5) DEFAULT NULL,
`score` float(10,5) DEFAULT NULL,
`max_up_corr` float(10,7) DEFAULT NULL,
`hash` varchar(255) DEFAULT NULL,
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2388 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `factors_list`
--

DROP TABLE IF EXISTS `factors_list`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `factors_list` (
`id` int NOT NULL AUTO_INCREMENT,
`factor_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`indicators` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`func_name` varchar(255) DEFAULT NULL,
`code` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`return_fileds` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`md5` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`check_type` int DEFAULT '0',
`status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT 'activate',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2406 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `factors_mining`
--

DROP TABLE IF EXISTS `factors_mining`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `factors_mining` (
`id` int NOT NULL AUTO_INCREMENT,
`factor_name` varchar(255) DEFAULT NULL,
`days` varchar(255) DEFAULT NULL,
`pool` varchar(255) DEFAULT NULL,
`start_date` varchar(10) DEFAULT NULL,
`end_date` varchar(10) DEFAULT NULL,
`formula` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`IC` float(20,5) DEFAULT NULL,
`IR` float(20,5) DEFAULT NULL,
`IRR` float(20,5) DEFAULT NULL,
`score` float(10,5) DEFAULT NULL,
`hash` varchar(255) DEFAULT NULL,
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `hash` (`hash`(32)) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=31156 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2023-12-26 18:40:11
4 changes: 2 additions & 2 deletions examples/demo-project/strategy/AITopNStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def initialize(context):
# 为股票设定滑点为百分比滑点
set_slippage(PriceRelatedSlippage(0.00246),type='stock')
# 持仓数量
g.stocknum = 3
g.stocknum = 50
# 交易日计时器
g.days = 0
# 调仓频率
g.refresh_rate = 5
g.refresh_rate = 1
# 运行函数
#inout_cash(100000)

Expand Down
4 changes: 3 additions & 1 deletion finhack/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def check_project(self):
if module=="project":
project_path=args.project_path
if project_path==None:
project_path=os.getcwd()+"project_"+str(int(time.time()))
project_path=os.getcwd()+"/project_"+str(int(time.time()))
self.project_path=project_path

template_path=Utils.get_template_path()
if action=="create":
Expand All @@ -107,6 +108,7 @@ def check_project(self):
print("创建完毕!项目路径为 %s 请切换到该目录或使用-p参数指定目录并执行相应操作!" % (project_path).replace('//','/'))
else:
print("创建失败!")
exit()
elif action=="renew":
#todo
pass
Expand Down
2 changes: 1 addition & 1 deletion finhack/library/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_framework_path():

#获取框架的模板路径
def get_template_path():
framework_path=utils.get_framework_path()
framework_path=Utils.get_framework_path()
template_path=framework_path+"/widgets/templates/empty_project"
return template_path

Expand Down
8 changes: 0 additions & 8 deletions finhack/note

This file was deleted.

11 changes: 6 additions & 5 deletions finhack/trainer/lightgbm/lightgbm_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from finhack.market.astock.astock import AStock
from finhack.factor.default.taskRunner import taskRunner
from finhack.factor.default.factorManager import factorManager

from lightgbm import log_evaluation, early_stopping
from finhack.trainer.trainer import Trainer

class LightgbmTrainer(Trainer):
Expand Down Expand Up @@ -124,22 +124,23 @@ def train(self,data_train,data_valid,data_path='/tmp',md5='test',loss="ds",param

print('Starting training...')
# 模型训练

callbacks = [log_evaluation(period=100), early_stopping(stopping_rounds=30)]
if loss=="ds":
params['objective']=self.custom_obj
gbm = lgb.train(params,
data_train,
num_boost_round=100,
valid_sets=data_valid,
early_stopping_rounds=5,
fobj=self.custom_obj,
callbacks=callbacks,

feval=self.custom_eval
)
else:
gbm = lgb.train(params,
data_train,
num_boost_round=100,
valid_sets=data_valid,
early_stopping_rounds=5
callbacks=callbacks
)

print('Saving model...')
Expand Down
2 changes: 2 additions & 0 deletions finhack/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import importlib
import lightgbm as lgb
from runtime.constant import *


class Trainer:
def getTrainData(self,start_date='20000101',valid_date="20080101",end_date='20100101',features=[],label='abs',shift=10,filter_name='',dropna=False,norm=False):
data_path=DATA_DIR
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FRAMEWORK_DIR="/root/anaconda3/envs/finhack/lib/python3.9/site-packages/finhack"
BASE_DIR="/data/code/finhack-new/examples/demo-project"
BASE_DIR="/data/code/finhack/examples/demo-project"
DATA_DIR=BASE_DIR+"/data/"
CACHE_DIR=DATA_DIR+"cache/"
CONFIG_DIR=DATA_DIR+"config/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def initialize(context):
# 为股票设定滑点为百分比滑点
set_slippage(PriceRelatedSlippage(0.00246),type='stock')
# 持仓数量
g.stocknum = 3
g.stocknum = 50
# 交易日计时器
g.days = 0
# 调仓频率
g.refresh_rate = 5
g.refresh_rate = 15
# 运行函数
#inout_cash(100000)

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ TA_Lib==0.4.24
tabulate==0.8.10
mysql-connector-python==8.0.30
tushare==1.2.87
lightgbm==4.2.0
cryptography==39.0.1
1 change: 0 additions & 1 deletion script/init.sh → script/conda.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
conda remove --name finhack --all
conda create --name finhack python=3.9
conda activate finhack
Loading

0 comments on commit 90bf5f9

Please sign in to comment.