-
Notifications
You must be signed in to change notification settings - Fork 0
/
agricuture.py
183 lines (147 loc) · 7.66 KB
/
agricuture.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import os
import numpy as np
import pandas as pd
import datetime
from utils import *
from cftc import *
from lme import *
from compare import *
start_time = '2010-1-1'
end_time = '2099-12-31'
def plot_c():
# 玉米
path = os.path.join(future_price_dir, 'dce', 'c'+'.csv')
fut_df = pd.read_csv(path, header=[0,1])
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time']['Unnamed: 0_level_1'], format='%Y-%m-%d'))
price = np.array(fut_df['index']['close'])
t0, price0 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t0, price0, 'DCE:玉米', code='002602', inst_name='CBOT:玉米')
path = os.path.join(cfd_dir, 'CORN_CFD'+'.csv')
fut_df = pd.read_csv(path)
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time'], format='%Y-%m-%d'))
price = np.array(fut_df['close'])
t1, price1 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t1, price1, 'CORN CFD', code='002602', inst_name='CBOT:玉米')
# U.S. cents per bushel
adjust = 0.01 / 0.0254012
compare_price_in_different_currency(t1, price1, 'USD', t0, price0, 'CNY', adjust, variety='玉米')
def plot_a():
# 豆一
path = os.path.join(future_price_dir, 'dce', 'a'+'.csv')
fut_df = pd.read_csv(path, header=[0,1])
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time']['Unnamed: 0_level_1'], format='%Y-%m-%d'))
price = np.array(fut_df['index']['close'])
t0, price0 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t0, price0, 'DCE:豆一', code='005602', inst_name='CBOT:大豆')
path = os.path.join(cfd_dir, 'SOYBEAN_CFD'+'.csv')
fut_df = pd.read_csv(path)
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time'], format='%Y-%m-%d'))
price = np.array(fut_df['close'])
t1, price1 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t1, price1, 'SOYBEAN CFD', code='005602', inst_name='CBOT:大豆')
# U.S. cents per bushel
adjust = 0.01 / 0.0272
compare_price_in_different_currency(t1, price1, 'USD', t0, price0, 'CNY', adjust, variety='豆一')
def plot_b():
# 豆二
path = os.path.join(future_price_dir, 'dce', 'b'+'.csv')
fut_df = pd.read_csv(path, header=[0,1])
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time']['Unnamed: 0_level_1'], format='%Y-%m-%d'))
price = np.array(fut_df['index']['close'])
t0, price0 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t0, price0, 'DCE:豆二', code='005602', inst_name='CBOT:大豆')
path = os.path.join(cfd_dir, 'SOYBEAN_CFD'+'.csv')
fut_df = pd.read_csv(path)
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time'], format='%Y-%m-%d'))
price = np.array(fut_df['close'])
t1, price1 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t1, price1, 'SOYBEAN CFD', code='005602', inst_name='CBOT:大豆')
# U.S. cents per bushel
adjust = 0.01 / 0.0272
compare_price_in_different_currency(t1, price1, 'USD', t0, price0, 'CNY', adjust, variety='豆二')
def plot_m():
# 豆粕
path = os.path.join(future_price_dir, 'dce', 'm'+'.csv')
fut_df = pd.read_csv(path, header=[0,1])
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time']['Unnamed: 0_level_1'], format='%Y-%m-%d'))
price = np.array(fut_df['index']['close'])
t0, price0 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t0, price0, 'DCE:豆粕', code='026603', inst_name='CBOT:豆粕')
path = os.path.join(cfd_dir, 'SOYBEAN_MEAL_CFD'+'.csv')
fut_df = pd.read_csv(path)
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time'], format='%Y-%m-%d'))
price = np.array(fut_df['close'])
t1, price1 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t1, price1, 'SOYBEAN MEAL CFD', code='026603', inst_name='CBOT:豆粕')
# U.S. dollars per short ton
adjust = 0.9071847
compare_price_in_different_currency(t1, price1, 'USD', t0, price0, 'CNY', adjust, variety='豆粕')
def plot_y():
# 豆油
path = os.path.join(future_price_dir, 'dce', 'y'+'.csv')
fut_df = pd.read_csv(path, header=[0,1])
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time']['Unnamed: 0_level_1'], format='%Y-%m-%d'))
price = np.array(fut_df['index']['close'])
t0, price0 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t0, price0, 'DCE:豆油', code='007601', inst_name='CBOT:豆油')
path = os.path.join(cfd_dir, 'SOYBEAN_OIL_CFD'+'.csv')
fut_df = pd.read_csv(path)
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time'], format='%Y-%m-%d'))
price = np.array(fut_df['close'])
t1, price1 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t1, price1, 'SOYBEAN OIL CFD', code='007601', inst_name='CBOT:豆油')
# U.S. cents per pound
adjust = 0.01 / 0.00045359237
compare_price_in_different_currency(t1, price1, 'USD', t0, price0, 'CNY', adjust, variety='豆油')
def plot_cf():
# 棉花
path = os.path.join(future_price_dir, 'czce', 'CF'+'.csv')
fut_df = pd.read_csv(path, header=[0,1])
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time']['Unnamed: 0_level_1'], format='%Y-%m-%d'))
price = np.array(fut_df['index']['close'])
t0, price0 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t0, price0, 'CZCE:棉花', code='033661', inst_name='ICE:棉花')
path = os.path.join(cfd_dir, 'COTTON_CFD'+'.csv')
fut_df = pd.read_csv(path)
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time'], format='%Y-%m-%d'))
price = np.array(fut_df['close'])
t1, price1 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t1, price1, 'COTTON CFD', code='033661', inst_name='ICE:棉花')
# U.S. cents per pound
adjust = 0.01 / 0.00045359237
compare_price_in_different_currency(t1, price1, 'USD', t0, price0, 'CNY', adjust, variety='棉花')
# def plot_p():
# # 棕榈油
# path = os.path.join(future_price_dir, 'dce', 'p'+'.csv')
# fut_df = pd.read_csv(path, header=[0,1])
# t = pd.DatetimeIndex(pd.to_datetime(fut_df['time']['Unnamed: 0_level_1'], format='%Y-%m-%d'))
# price = np.array(fut_df['index']['close'])
# t0, price0 = get_period_data(t, price, start_time, end_time, remove_nan=True)
# cftc_plot_disaggregated(t0, price0, 'DCE:棕榈油', code='037021', inst_name='CME:棕榈油')
def plot_sr():
# 白糖
path2 = os.path.join(future_price_dir, 'czce', 'SR'+'.csv')
fut_df = pd.read_csv(path2, header=[0,1])
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time']['Unnamed: 0_level_1'], format='%Y-%m-%d'))
price = np.array(fut_df['index']['close'], dtype=float)
t0, price0 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t0, price0, 'CZCE:白砂糖', code='080732', inst_name='ICE:糖')
path = os.path.join(cfd_dir, 'SUGAR_CFD'+'.csv')
fut_df = pd.read_csv(path)
t = pd.DatetimeIndex(pd.to_datetime(fut_df['time'], format='%Y-%m-%d'))
price = np.array(fut_df['close'])
t1, price1 = get_period_data(t, price, start_time, end_time, remove_nan=True)
cftc_plot_disaggregated(t1, price1, 'SUGAR CFD', code='080732', inst_name='ICE:糖')
# U.S. cents per pound
adjust = 0.01 / 0.00045359237
compare_price_in_different_currency(t1, price1, 'USD', t0, price0, 'CNY', adjust, variety='糖')
def plot_agricuture():
plot_a()
plot_b()
plot_m()
plot_y()
plot_c()
plot_cf()
plot_sr()
if __name__=="__main__":
plot_agricuture()