-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCloseModel.py
74 lines (54 loc) · 2.17 KB
/
CloseModel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
# -*- coding: utf-8 -*-
from framework.mysql import mysql
from strategy.ma import ma
from strategy.singlek import singlek as singleK
import pandas as pd
from full_line_class.common import insert_fx
import os
class LineModel():
"""docstring for LineModel"""
def __init__(self, code, table):
self.code = code
self.table = table
self.get_TD()
def get_TD(self):
self.df = mysql.select_with_index(self.table, self.code)
class LineModel2():
"""docstring for LineModel"""
def __init__(self, code, table):
self.code = code
self.table = table
self.get_TD()
def get_TD(self):
self.df = mysql.select_with_index(self.table, self.code)
def run(code,times,gap=0):
table = code+"_f365_"+times
macd = LineModel(code, table).df[0:]
table = code+"_all_stock_dayline_details_"+times
k_data = LineModel(code, table).df[0:]
df = []
point = 0
for i in range(1,len(macd)):
if macd.ix[i-1]['bar']:
# 红柱小于绿柱
if float(macd.ix[i-2]['bar']) < float(macd.ix[i-1]['bar']) and float(macd.ix[i-1]['bar']) > float(macd.ix[i]['bar']):
if point > 0 and float(macd.ix[i-1]['bar']) < 0 and (abs(float(macd.ix[i-1]['bar'])) - abs(point) > gap):
# 平仓
df.append([macd.ix[i].data, k_data.ix[i].bar, 'duo', code])
point = float(macd.ix[i-1]['bar'])
# 绿柱小于红柱
if float(macd.ix[i-2]['bar']) > float(macd.ix[i-1]['bar']) and float(macd.ix[i-1]['bar']) < float(macd.ix[i]['bar']):
if point < 0 and float(macd.ix[i-1]['bar']) > 0 and (abs(float(macd.ix[i-1]['bar'])) - abs(point) > gap):
# 平仓
df.append([macd.ix[i].data, k_data.ix[i].bar, 'kong', code])
point = float(macd.ix[i-1]['bar'])
line_df = pd.DataFrame(df, columns=["date","bar", "type", "code"])
line_df = line_df.set_index(line_df.date)
line_df = line_df.drop(['date'], axis=1)
insert_table=code+"_f365_close_"+times
insert_fx(line_df,insert_table,code)
code_list = ['RB0']
times = 'm15'
for code in code_list:
run(code,times)